Netscape JavaScript getYear() problem? Also bad JavaScript on CNN.
From what I've read on the net (which is NOT extensive and I'm in no way shape or
Hello folks, I discovered to my utter delight that my lights stayed on during the roll-over. However, after poking around looking for the year 1900, I only found one issue. It appears that the javascript function "getYear" in the Date class is inconsistent between Java implementations. This happens when getYear() is called with no arguments, in other words, when getYear() is queried for the current year. I am not terribly JavaScript "Clue-Compliant" so if I make any blunders in this post, please set me back on track. Specifically, I get the following test results: Platform Browser Version getYear() returns -------- -------- ----------- ----------------- Win98 Netscape 4.61 100 Win98 Netscape 4.7 100 Win98 MSIE 5.00.2919 2000 You can look at what your browser's JavaScript interpreter returns for getYear() by loading: http://www.dreamscape.com/willp/y2k.html Apparently, Netscape 4.61/4.7 is not properly reporting the year in a getYear() call. form a java guru)- the getYear() function should return a 2 digit date up to and including the year 1999. However, in the year 2000 and beyond, getYear() should return a 4-digit date. Now, whoever thought up this getYear() function behavior should be shot, IMNSHO. I saw this when my "CNN Ticker window" in MSIE5 indicated that the current year was 2300. The CNN JavaScript assumes the getYear() function returns the # of years since 1900. Caveat: I have not tried looking at the return values of getYear() in JavaScript on anything other than my own home computer. It is possible (though unlikely I hope) that what I've seen is due to a strange problem with -just- my computer and its mangled DLL files under Windows 98. I would appreciate any confirmation of this strange behavior of getYear() under Netscape and/or any help in understanding this problem. If someone could confirm that they too see the year 3900 on the CNN "ticker bar" and that these results -are- in fact problems, I would really appreciate the feedback! The risk: Any web sites that use the getYear() function will need to accomodate various return values of getYear() and properly distinguish the bizarre results that some browser versions will return. In the case of sites that only use getYear() to *display* the date for the edification of the user, this won't have any operational effects. However, for sites that use date processing in a mission critical situation, there may be some problems. While I have strong hopes that no one would use client-side JavaScript in a mission-critical application, there is still the possibility that this will be a problem on some websites. For most sites affected by this, it will only cause embarassment. Random List of Affected Sites (found so far): CNN http://www.cnn.com/ The CNN "ticker" toolbar (downloadable at: http://www.cnn.com/browsers/explorer.bar/ ) indicates to me that the date is 3900, because their javascript function "ShowDate" adds 1900 to the result of getYear(). (MSIE5.00.2919.6307 on Win98) The date is only used for display purposes (as far as I can tell). Computer Technology Associates http://www.ctai.com/ The date displayed on their homepage indicates "January 1, 192000" under MSIE 5 on Windows 98. Their JavaScript assumes that it is always the 1900's and that getYear() always returns the last two digits of the year. The date is only used for display purposes. Rocky Mountaineer Tours http://www.rkymtnrail.com/ Same problem as for CTAI above. The date is only used for display purposes. JJournal Jeep Owners Resource http://www.jjournal.net/ Same problem as CTAI and Rocky Mountaineer Tours. The date is only used for display purposes. PegasoWeb Web Site Promotion http://www.pegasoweb.com/ Again, year is shown as 192000. The date is used only for display purposes. Web Medicine http://www.webmed.com/ The "last date modified" on this site indicates that the site was last updated on January 1, 3900. Apparently the date is only used for indicating to the visitor that the website is modified daily. Sport/Utility Vehicle Owners Resources http://www.suv.com/ Displays current date as year 192000. Date only used for display purposes. World Trade Center Institute http://www.wtci.org/frmain.htm Displays current date as year 192000. Date only used for display purposes. Inland Empire Online http://www.inlandempireonline.com/business/index.shtml Displays current date as year 192000. Date only used for display purposes. Resources related to this: Overcoming Different Year Conventions - Doc JavaScript http://www.webreference.com/js/pharmacy/article1/overcome.html Y2K JavaScripts http://server9.hypermart.net/ucprogramming/javascript/article1.html JS Year 2000 Very Basic Test Page http://www.nikwilliams.co.uk/jsdate01.html Java City 2000 - Year 2000 Fix http://www.jc2k.com/y2k.html JSBible Calendar Scripts and Y2K http://www.dannyg.com/calendarY2K.html -- Will Pierce Systems Programmer Nuts & Bolts Interactive, Inc. willp@nbinteractive.com P.S. If someone could confirm this behavior as being due to 1. differences in the implementation of the getYear() javascript function, and 2. poorly coded JavaScripts, I would be very grateful for the confirmation. I am no JavaScript programmer by any means, so this whole post could be way off base. I am only posting it so that some more experienced Java guru can either correct my mistakes or confirm and expand on what I'm seeing. Flames to /dev/null pls.
We've found the same thing, and have coded around it for our software. I'll post details as soon as I get them from our Engineering department. --Lloyd Taylor VP Operations Keynote Systems On Sat, 1 Jan 2000, Will Pierce wrote:
Date: Sat, 1 Jan 2000 23:37:01 -0500 From: Will Pierce <willp@nbinteractive.com> To: nanog@merit.edu Subject: Netscape JavaScript getYear() problem? Also bad JavaScript on CNN.
It appears that the javascript function "getYear" in the Date class is inconsistent between Java implementations. This happens when getYear() is called with no arguments, in other words, when getYear() is queried for the current year.
Looks like it's not a bug, but a feature. Here's the official info from Netscape's developer's pages: http://developer.netscape.com/docs/manuals/js/core/jsref/date.htm#1194138 getYear Returns the year in the specified date according to local time. JavaScript 1.3: deprecated; also, getYear returns the year minus 1900 regardless of the year specified ECMA version ECMA-262 Description getYear is no longer used and has been replaced by the getFullYear method. The getYear method returns the year minus 1900; thus: For years above 2000, the value returned by getYear is 100 or greater. For example, if the year is 2026, getYear returns 126. For years between and including 1900 and 1999, the value returned by getYear is between 0 and 99. For example, if the year is 1976, getYear returns 76. For years less than 1900 or greater than 1999, the value returned by getYear is less than 0. For example, if the year is 1800, getYear returns -100. To take into account years before and after 2000, you should use Date.getFullYear instead of getYear so that the year is specified in full. ---------------------------------------------------------------------- http://developer.netscape.com/docs/manuals/js/core/jsref/date.htm#1193607 getFullYear Returns the year of the specified date according to local time. Implemented in JavaScript 1.3 ECMA version ECMA-262 Description The value returned by getFullYear is an absolute number. For dates between the years 1000 and 9999, getFullYear returns a four-digit number, for example, 1995. Use this function to make sure a year is compliant with years after 2000. Use this method instead of the getYear method. ==== So, apparently Microsoft does it wrong, so it works, and Netscape does it right, so it doesn't. *grin* 'course, it'll be interesting to see how the press reports on all the sites showing addresses like "Jan 1, 19100" due to this little item..... --Lloyd On Sat, 1 Jan 2000, Lloyd Taylor wrote:
Date: Sat, 1 Jan 2000 21:38:23 -0800 (PST) From: Lloyd Taylor <ltaylor@keynote.com> To: Will Pierce <willp@nbinteractive.com> Cc: nanog@merit.edu Subject: Re: Netscape JavaScript getYear() problem? CONFIRMED
We've found the same thing, and have coded around it for our software. I'll post details as soon as I get them from our Engineering department.
--Lloyd Taylor VP Operations Keynote Systems
On Sat, 1 Jan 2000, Will Pierce wrote:
Date: Sat, 1 Jan 2000 23:37:01 -0500 From: Will Pierce <willp@nbinteractive.com> To: nanog@merit.edu Subject: Netscape JavaScript getYear() problem? Also bad JavaScript on CNN.
It appears that the javascript function "getYear" in the Date class is inconsistent between Java implementations. This happens when getYear() is called with no arguments, in other words, when getYear() is queried for the current year.
The value returned by getFullYear is an absolute number. For dates between the years 1000 and 9999, getFullYear returns a four-digit number, for example, 1995. Use this function to make sure a year is compliant with years after 2000.
Is this a Y10K problem? (I promise, my last YxK joke). Deepak Jain AiNET
participants (3)
-
Deepak Jain
-
Lloyd Taylor
-
Will Pierce