nanog mailing list archives

Netscape JavaScript getYear() problem? Also bad JavaScript on CNN.


From: "Will Pierce" <willp () nbinteractive com>
Date: Sat, 1 Jan 2000 23:37:01 -0500


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.
From what I've read on the net (which is NOT extensive and I'm in no way shape or
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.





Current thread: