Re: Need quick JS help...

by Romek Zylla <zylla(at)ck-sg.p.lodz.pl>

 Date:  Thu, 06 Jan 2000 00:38:13 -0100
 To:  <karen(at)magellan.edu>
 Cc:  hwg-techniques(at)hwg.org
todo: View Thread, Original
 
At  09:08 1/5/2000 PST,  Karen Ahrens  wrote:
>My JS isn't up to speed yet but boss has insisted on 
>having a date script on our homepage. Now, the date 
>displays correctly in IE but is at year 100 in Netscape 
>and I don't have the skills (yet) to tell what to tweak. 
>
>Could someone give our homepage a gander and let me know 
>how to fix the problem or perhaps, point me to a better 
>script to use? Thank you very much in advance!
>Homepage URL: http://magellan.edu
>
>Karen Ahrens

  After some discussion on the wdg list we agreed to
  not so simple solution but which works even in Opera :)
  Body part is for ilustrating how to use the script.
  Below there are two screeshots and some comments.

<head>
<script language='javascript' type="text/javascript"><!--

function getfullyearfix() {
   // use standard y2k fix technique here
var tmp  = this.getYear(); 
    tmp  = tmp % 100; 
    if (tmp > 50) return tmp+1900;
    return tmp+2000;
}

//  if (!Date.getFullYear) {
//  line above changed to

if (Date.getFullYear != '') {
    Date.prototype.getFullYear=getfullyearfix;
}

// --></script>
</head>
<body>
<script><!--
var today = new Date();
var birth = new Date(2037,1,27,12,12,12);
var birt2 = new Date(2038,1,27,12,12,12);
document.write( "<pre>");

document.write( "today= Date()      = " + today +'<br>' );
document.write( "today.getYear()    = " + today.getYear() +'<br>' );
document.write( "today.getFullYear()= " + today.getFullYear() +'<br>');

document.write( "<br>");
document.write( "My birthday in the year 2037 <br>" );
document.write( "birth= Date(....)  = " + birth +'<br>' );
document.write( "birth.getYear()    = " + birth.getYear() +'<br>' );
document.write( "birth.getFullYear()= " + birth.getFullYear() +'<br>');

document.write( "<br>");
document.write( "My birthday in the year 2038 - 32 bit clock stops!<br>" );
document.write( "birt2= Date(....)  = " + birt2 +'<br>' );
document.write( "birt2.getYear()    = " + birt2.getYear() +'<br>' );
document.write( "birt2.getFullYear()= " + birt2.getFullYear() +'<br>');

document.write( "<br>All is OK <br>");

// --></script>
</body>

=========== below is the screen shot of Opera output ===========
today= Date()      = Wed Jan 5 17:23:13 GMT-0100 (MET) 2000
today.getYear()    = 100
today.getFullYear()= 2000
My birthday in the year 2037
birth= Date(....)  = Fri Feb 27 12:12:12 GMT-0100 (MET) 2037
birth.getYear()    = 137
birth.getFullYear()= 2037
My birthday in the year 2038 - 32bit clock stops!
birt2= Date(....)  = -1000
birt2.getYear()    = null
birt2.getFullYear()= 2000
All is OK
================================================================


And of course E-minor' comment on 32 bit clock is valid.
Opera is using standard C time library.  The library uses
32 bit clock starting from 1970.  After year 2037 clock will
overflow and many C programs will calculate wrong time.
Mind that C is the most common language for writing
computer programs.
So the next Y2K bug will be actually  Y2038 Bug

But for IE 4.0  clock works for the year 2038 and later.

=========== below is the screenshot of IE 4.0 output ===========
today= Date()      = Wed Jan 5 02:19:36 UTC+0100 2000
today.getYear()    = 2000
today.getFullYear()= 2000
My birthday in the year 2037
birth= Date(....)  = Fri Feb 27 12:12:12 UTC+0100 2037
birth.getYear()    = 2037
birth.getFullYear()= 2037
My birthday in the year 2038 - 32 bit clock stops!
birt2= Date(....)  = Sat Feb 27 12:12:12 UTC+0100 2038
birt2.getYear()    = 2038
birt2.getFullYear()= 2038
All is OK
================================================================

--
 Romek Zylla ~~~~~


--------------------------- ONElist Sponsor ----------------------------

    GRAB THE GATOR! FREE SOFTWARE DOES ALL THE TYPING FOR YOU!
Tired of filling out forms and remembering passwords? Gator fills in
forms and passwords with just one click! Comes with $50 in free coupons!
  <a href=" http://clickme.onelist.com/ad/gator4 ">Click Here</a>