HighDots Forums  

Re: Java and Netscape

Javascript JavaScript language (comp.lang.javascript)


Discuss Re: Java and Netscape in the Javascript forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Chris Smith
 
Posts: n/a

Default Re: Java and Netscape - 10-12-2003 , 06:01 PM






[Wrong newsgroup; JavaScript is not Java. Followups set.]

Brian H¹© wrote:
Quote:
The following script works wonderfully when browsed with IE, but the yearshows
as 103 when browsed with Netscape, is there anything that can be done to correct
this to show 2003 instead please?
Sure. Actually, the fact that this works in IE indicates that IE is a
non-conforming implementation of JavaScript. The problem lies in this
code:

Quote:
(theDate.getYear() < 100 ? theDate.getYear() + 1900 :
theDate.getYear()) +
The first problem is that this code uses getYear() at all. That's a
really bad idea. Nevertheless, getYear() is specified to return the
current year minus 1900. It appears, though, that the author discovered
that some implementations don't do so, and worked around the problem
with the strange conditional expression.

The problem with that strange conditional expression is that it fails
with the correctly specified behavior for some very common cases... one
of those being the current date.

You have two options. You could alter the workaround to allow for more
room (so that instead of being biased for the date to be greater than
100 AD, it's biased to be greater than, say, 500 AD. That way, when
Netscape correctly returns 103 for the year (i.e., 2003 minus 1900, as
specified), the workaround will ignore that and pass it through rather
than trying to correct for a bug.

The other option is to use the more reliable and simpler method
getFullYear(), which will return 2003 for the year as you might expect.
You might want to test for the existence of getFullYear if you plan on
using very old browsers, and maybe fall back to your corrected getYear()
version.

--
www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.