North American Network Operators Group

Date Prev | Date Next | Date Index | Thread Index | Author Index | Historical

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

  • From: Will Pierce
  • Date: Sat Jan 01 23:40:47 2000

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:

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.

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):
 The CNN "ticker" toolbar (downloadable at: )
 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
 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

 Rocky Mountaineer Tours
 Same problem as for CTAI above.  The date is only used for display purposes.

 JJournal Jeep Owners Resource
 Same problem as CTAI and Rocky Mountaineer Tours.  The date is only used for
 display purposes.
 PegasoWeb Web Site Promotion
 Again, year is shown as 192000.  The date is used only for display purposes.
 Web Medicine
 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
 Displays current date as year 192000.  Date only used for display purposes.

 World Trade Center Institute
 Displays current date as year 192000.  Date only used for display purposes.
 Inland Empire Online
 Displays current date as year 192000.  Date only used for display purposes.

Resources related to this:
Overcoming Different Year Conventions - Doc JavaScript
Y2K JavaScripts
JS Year 2000 Very Basic Test Page
Java City 2000 - Year 2000 Fix
JSBible Calendar Scripts and Y2K

Will Pierce
Systems Programmer
Nuts & Bolts Interactive, Inc.
[email protected]

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.