• (cs) in reply to anon

    Anonymous:
    JohnO:
    Well, at least the algorithm is O(1).


    Only because it employs "caching".

    <FONT face="Courier New" size=2>that's not "caching".</FONT>

  • Brian S. (unregistered) in reply to emptyset

    I don't think anyone's mentioned it, but the odd indenting suggests to me server side scripting. Why you would mix server and client scripts in this way is still a WTF (javascript for the month and day, but PHP or whatever for the year? WTF??), but I thought it deserved mentioning.

  • A! (unregistered) in reply to Andr&#233;s Villanueva

    They are not claiming that it's a last update date. They merely display current time of a client's system. Not an unusual occurance on the web, but it is kind of pointless.

  • (cs) in reply to RevMike
    RevMike:
    I, for one, vote for doing a mod 100 on the result of getYear before prepending the 20.  Let the Y3K people fix it


    Er, you mean the Y2.1K people?
  • Me (unregistered) in reply to A!

    Anonymous:
    They are not claiming that it's a last update date. They merely display current time of a client's system. Not an unusual occurance on the web, but it is kind of pointless.

    Read the code again and if you still don't agree keep reading it until you understand what it is doing.

  • Anonynous Coward (unregistered) in reply to jawohl
    Anonymous:
    Anonymous:
    '20' + Date.getYear will either display '2004' or '20104' depending on the browser.
    And thats why there's Date.getFullYear() which returns 2004.


    The real WTF is that a language created in the late 1990s has the Y2K bug built into its API.

  • A! (unregistered) in reply to Me
    Anonymous:

    Anonymous:
    They are not claiming that it's a last update date. They merely display current time of a client's system. Not an unusual occurance on the web, but it is kind of pointless.

    Read the code again and if you still don't agree keep reading it until you understand what it is doing.

    I was refering to http://www.netcoast.nl/. Their JS doesn't have document.write("Last Update:");

     

  • A! (unregistered) in reply to Anonynous Coward

    Anonymous:
    Anonymous:
    Anonymous:
    '20' + Date.getYear will either display '2004' or '20104' depending on the browser.
    And thats why there's Date.getFullYear() which returns 2004.


    The real WTF is that a language created in the late 1990s has the Y2K bug built into its API.

    That's why Alex should stop posting JS WTFs. JS stopped being funny in 1999.

     

  • (cs) in reply to Anonynous Coward
    Anonymous:

    The real WTF is that a language created in the late 1990s has the Y2K bug built into its API.


    Hmmm... allow me to quote from the ECMA spec...
    -- begin quote --
    B.2.4 Date.prototype.getYear ( )
    NOTE
    The getFullYear method is preferred for nearly all purposes, because it avoids the “year 2000
    problem.”
    When the getYear method is called with no arguments the following steps are taken:
    1. Let t be this time value.
    2. If t is NaN, return NaN.
    3. Return YearFromTime(LocalTime(t)) - 1900.
    -- end quote --

    There's no Y2K bug here.  You can get the full year via d.getYear() + 1900 under all circumstances.  Or you can get the two-digit year via d.getYear() % 100.

    Of course, getFullYear() is preferable.
  • (cs) in reply to Maurits
    Maurits:

    There's no Y2K bug here.  You can get the full year via d.getYear() + 1900 under all circumstances.


    Not quite -- JScript in MSIE will return a four-digit year when you use getYear() on dates after December 31, 1999. (Non-standard, yes, but done on purpose to automagically fix customer-created bugs. Of course, that does little to help the folks who used getYear() correctly in the first place.)
  • (cs) in reply to Stan Rogers
    Stan Rogers:
    JScript in MSIE will return a four-digit year when you use getYear() on dates after December 31, 1999


    OMG...

    And also on dates before 1/1/1900, too, it seems...

    IE:
    j a v a s c r i p t: alert(new Date("1/1/1899").getYear()) // 1899
    j a v a s c r i p t: alert(new Date("1/1/1900").getYear()) // 0
    j a v a s c r i p t: alert(new Date("1/1/1999").getYear()) // 99
    j a v a s c r i p t: alert(new Date("1/1/2000").getYear()) // 2000

    Firefox / Standard:
    j a v a s c r i p t: alert(new Date("1/1/1899").getYear()) // -1
    j a v a s c r i p t: alert(new Date("1/1/1900").getYear()) // 0
    j a v a s c r i p t: alert(new Date("1/1/1999").getYear()) // 99
    j a v a s c r i p t: alert(new Date("1/1/2000").getYear()) // 100

    I have to consider that a bug in IE.
  • Anonynous Coward (unregistered) in reply to Maurits
    Maurits:
    Anonymous:

    The real WTF is that a language created in the late 1990s has the Y2K bug built into its API.



    Hmmm... allow me to quote from the ECMA spec...
    -- begin quote --
    B.2.4 Date.prototype.getYear ( )
    NOTE
    The getFullYear method is preferred for nearly all purposes, because it avoids the “year 2000
    problem.”
    When the getYear method is called with no arguments the following steps are taken:
    1. Let t be this time value.
    2. If t is NaN, return NaN.
    3. Return YearFromTime(LocalTime(t)) - 1900.
    -- end quote --

    There's no Y2K bug here.  You can get the full year via d.getYear() + 1900 under all circumstances.  Or you can get the two-digit year via d.getYear() % 100.

    Of course, getFullYear() is preferable.


    You assumed I was referring to ECMAScript.  The ECMAScript specification is an after-the-fact attempt to standardize Netscape's JavaScript (nee LiveScript) and Microsoft's JScript.  As others have pointed out, these two languages behave differently from each other relative to the Date.getYear() method.


    The fact remains that some idiot at Netscape thought it was a grand idea to have Date.getYear() return a two digit year.  Pick your poison:  either they 1) built the Y2K bug in and came up with the (year - 1900) thing later after realizing what dolts they were or 2) thought that a method returning (year - 1900) called getYear() was much more useful than a getYear() method that returns the year unmolested.  So if you like your useful values linearly translated by constants guaranteed to be useless in less than 10 years, this is the language for you!


    If you are still not convinced that this is a WTF, please write some JS meeting the following requirements:


    1. Does something easily recognizable as useful to a viewer of a web page

    2. Uses Date.getYear() as in the ECMAScript specification (not the JScript version (see, I'm not even asking for cross-browser compatibility))

    3. Doesn't use the magic number 1900 either directly or indirectly (i.e., 191010 is out)

    4. Applies Date.getYear() to the current date

    5. Works the same no matter what century it is

    6. Could not be simplified or unobfuscated via the use of Date.getFullYear()


    Good luck.


    Cool -- the CAPTCHA was "zork".

  • Tom (unregistered)

    Search for writedate in the following link: http://www.conzz.com/jsLibrary.txt

    Looks to me like someone snagged the code, couldn't figure out how to do 4-digit years and hardcoded it.

  • (cs) in reply to Anonynous Coward

    Anonymous:
    If you are still not convinced that this is a WTF, please write some JS meeting the following requirements:

    1) Does something easily recognizable as useful to a viewer of a web page
    2) Uses Date.getYear() as in the ECMAScript specification (not the JScript version (see, I'm not even asking for cross-browser compatibility))
    3) Doesn't use the magic number 1900 either directly or indirectly (i.e., 19*10*10 is out)
    4) Applies Date.getYear() to the current date
    5) Works the same no matter what century it is
    6) Could not be simplified or unobfuscated via the use of Date.getFullYear()

    I agree it's a WTF.  I disagree that it's a bug, though.  You should see some of the C time-handling functions.  For example, months go from 0 to 11, but days-in-the-month go from 1 to 31.  Just have to get used to it.

    But, anyway...

    var today = getDate();

    document.write("Welcome to TheDailyWTF, '" + (today.getYear() % 100) + " edition");

  • GrumpySimon (unregistered) in reply to Maurits

    I'm betting that they employed a highly paid "Search Engine Optimiser" to do this for them - if you don't have new content, fake it, right?

  • Alien426 (unregistered) in reply to GrumpySimon
    document.write("Last Update: " + document.lastModified);
  • Sanjay (unregistered) in reply to Andr&#233;s Villanueva

    This isn't really a WTF, it's just code written by a very pessimistic individual.

  • Anonymous Coward (unregistered) in reply to Maurits
    Maurits:

    Anonymous:
    If you are still not convinced that this is a WTF, please write some JS meeting the following requirements:

    1) Does something easily recognizable as useful to a viewer of a web page
    2) Uses Date.getYear() as in the ECMAScript specification (not the JScript version (see, I'm not even asking for cross-browser compatibility))
    3) Doesn't use the magic number 1900 either directly or indirectly (i.e., 19*10*10 is out)
    4) Applies Date.getYear() to the current date
    5) Works the same no matter what century it is
    6) Could not be simplified or unobfuscated via the use of Date.getFullYear()

    I agree it's a WTF.  I disagree that it's a bug, though.  You should see some of the C time-handling functions.  For example, months go from 0 to 11, but days-in-the-month go from 1 to 31.  Just have to get used to it.

    But, anyway...

    var today = getDate();

    document.write("Welcome to TheDailyWTF, '" + (today.getYear() % 100) + " edition");



    Fails requirement #6.

    Also, this would print out "Welcome to TheDailyWTF, 5 edition" this year and "Welcome to TheDailyWTF, 0 edition" in 2000.

    Furthermore I'm going to say it fails #5 because as the year changes century, the edition goes backwards.

    In case you failed to notice, ECMAScript (and Netscape JavaScript and JScript) have the same issues with Date.getDate() and Date.getMonth() that you accuse C of having.  (BTW, I love the fact we have a Date.getDate() method.  And don't get me started on Date.getDay() vs Date.getDate().)


  • (cs) in reply to emptyset
    emptyset:

    Anonymous:
    One of my students refered me to this site.[*]  It reminds me of a 1983 saying: Opus says "Don't look for logic." After 20 yrs in industry as a SE I thought I had seen it all...Hauser, PhD.  see www.nku.edu/~hauserj for a good review.  By the way .... building stuff is more fun; less rewarding.

    <font face="Courier New" size="2">what...is going on in that site?</font>


    Most hilarious part of the site:

    Paper 6: UI Patterns and Techniques

  • (cs) in reply to Maurits
    Maurits:
    Anonymous:

    The real WTF is that a language created in the late 1990s has the Y2K bug built into its API.


    Hmmm... allow me to quote from the ECMA spec...
    -- begin quote --
    B.2.4 Date.prototype.getYear ( )
    NOTE
    The getFullYear method is preferred for nearly all purposes, because it avoids the “year 2000
    problem.”
    When the getYear method is called with no arguments the following steps are taken:
    1. Let t be this time value.
    2. If t is NaN, return NaN.
    3. Return YearFromTime(LocalTime(t)) - 1900.
    -- end quote --

    There's no Y2K bug here.  You can get the full year via d.getYear() + 1900 under all circumstances.  Or you can get the two-digit year via d.getYear() % 100.

    Of course, getFullYear() is preferable.

    Condensing the above: Just because it's a spec doesn't mean it isn't stupid. This is why all browsers have extensions and non-conforming areas. (Netscape had a golden opportunity when rejigging mozilla to let the old moronic definition go and embrace IE's less brain-damaged interpretation, but they blew it. Maybe pique, maybe just a slavish adherence to specs good or bad.)
  • George Bezel (unregistered) in reply to foxyshadis
    foxyshadis:
    emptyset:

    Anonymous:
    One of my students refered me to this site.[*]  It reminds me of a 1983 saying: Opus says "Don't look for logic." After 20 yrs in industry as a SE I thought I had seen it all...Hauser, PhD.  see www.nku.edu/~hauserj for a good review.  By the way .... building stuff is more fun; less rewarding.

    <font face="Courier New" size="2">what...is going on in that site?</font>


    Most hilarious part of the site:

    Paper 6: UI Patterns and Techniques

    That site's beautiful, really. A WTF in its own regard.

  • George Bezel (unregistered) in reply to George Bezel

    Man, who wrote this forum software? It's surely eligible for the front page! Sorry everyone.

  • (cs) in reply to foxyshadis
    foxyshadis:
    Maurits:
    Anonymous:

    The real WTF is that a language created in the late 1990s has the Y2K bug built into its API.


    Hmmm... allow me to quote from the ECMA spec...
    -- begin quote --
    B.2.4 Date.prototype.getYear ( )
    NOTE
    The getFullYear method is preferred for nearly all purposes, because it avoids the “year 2000
    problem.”
    When the getYear method is called with no arguments the following steps are taken:
    1. Let t be this time value.
    2. If t is NaN, return NaN.
    3. Return YearFromTime(LocalTime(t)) - 1900.
    -- end quote --

    There's no Y2K bug here.  You can get the full year via d.getYear() + 1900 under all circumstances.  Or you can get the two-digit year via d.getYear() % 100.

    Of course, getFullYear() is preferable.

    Condensing the above: Just because it's a spec doesn't mean it isn't stupid. This is why all browsers have extensions and non-conforming areas. (Netscape had a golden opportunity when rejigging mozilla to let the old moronic definition go and embrace IE's less brain-damaged interpretation, but they blew it. Maybe pique, maybe just a slavish adherence to specs good or bad.)


    Uh, no. If I define and publish an API, I'd sure as hell better go out of my way to ensure that it continues to operate the way I defined it indefinitely. If getYear() was defined as returning the difference between the year of the date stored in the Date object and 1900, then it had better continue to do that for as long as the language exists. That's why getFullYear() was added to the language -- so one could make use of a "less brain-damaged" method without forcing anybody to change working, spec-compliant code currently in production.
  • telmesrin (unregistered) in reply to emurphy

    FYI - here is the latest version, two years after the original. From http://www.netcoast.nl/:

    <font size="-7" color="#0066FF"> <script language="JavaScript">

    var now = new Date();

    var dayName = now.getDay() +1; var dayNumber = now.getDate(); var monthName = now.getMonth() + 1;

    if(dayName==1) Day = "Sunday"; if(dayName==2) Day = "Monday"; if(dayName==3) Day = "Tuesday"; if(dayName==4) Day = "Wednesday"; if(dayName==5) Day = "Thursday"; if(dayName==6) Day = "Friday"; if(dayName==7) Day = "Saturday";

    if(monthName==1) Month="Jan."; if(monthName==2) Month="Feb."; if(monthName==3) Month="Mar."; if(monthName==4) Month="Apr."; if(monthName==5) Month="May"; if(monthName==6) Month="Jun."; if(monthName==7) Month="Jul."; if(monthName==8) Month="Aug."; if(monthName==9) Month="Sept."; if(monthName==10) Month="Oct."; if(monthName==11) Month="Nov."; if(monthName==12) Month="Dec.";

    document.open(); document.write( Day + ", " + dayNumber + " " + Month);

    </script>
                                2007</font>
    
  • gnolm (unregistered)

    Someone should have mercy, hack the site and fix it. It hurts me to see that it is still a real WTF after 4 years. :-( Tonight, I'm gonna cry because of things like this ...

Leave a comment on “Automatic Updates”

Log In or post as a guest

Replying to comment #46889:

« Return to Article