Closed
Bug 235569
Opened 21 years ago
Closed 21 years ago
Javascript Date() Function returns wrong value
Categories
(Core :: JavaScript Engine, defect)
Tracking
()
RESOLVED
WORKSFORME
People
(Reporter: mhall, Unassigned)
Details
User-Agent:
Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.4) Gecko/20030624 Netscape/7.1 (ax)
I ran the following Javascript in my location bar:
javascript:new Date();
And this is what I got:
Wed Feb 25 2004 08:14:12 GMT-0800 (EST)
Now, this is a problem. EST is GMT-500, NOT GMT-800!
Please tell me this will be fixed soon (probably a simple typo in the code).
Reproducible: Always
Steps to Reproduce:
1. Put the following unquoted text in the URL bar: "javascript:new Date();"
2. Check the browser output to make sure the timezone is right.
3.
Actual Results:
Got: Wed Feb 25 2004 08:14:12 GMT-0800 (EST)
Expected Results:
Should have gotten: Wed Feb 25 2004 11:14:12 GMT-0500 (EST)
Note the change in time and GMT-0x00
Comment 1•21 years ago
|
||
Is this an issue with a current Mozilla build? Netscape 7.1 is _really_ old
(and this worksforme, though I am in CST, not EST).
| Reporter | ||
Comment 2•21 years ago
|
||
This was also found on Mozilla 1.6b
| Reporter | ||
Comment 3•21 years ago
|
||
I just downloaded and installed Mozilla 1.6 from www.mozilla.org, and it has the
same problem.
Comment 4•21 years ago
|
||
Could be another occurence of bug 127246 (ignore the "after time zone change" in
the summary, that's probably bogus).
I am probably coming across the same or a very similar bug on my homepage. I
won't change any of the JavaScript code there, and you will easily be able to
see the difference between IE and Mozilla when you press the "Mike's been alive
for how long?" button. (It's supposed to calculate my current age down to the
second).
http://miketwo.8m.com , about halfway down the page.
Hope it helps with the debugging!
| Reporter | ||
Updated•21 years ago
|
Severity: critical → blocker
Comment 6•21 years ago
|
||
Page referenced in comment #5 uses JS getYear() function that was deprecated in
JS 1.3. Reference http://www.mozilla.org/js/language/E262-2.pdf page 96 -
"getFullYear() is to be much preferred to getYear() to avoid year 2000 problems".
javascript: new Date().getFullYear(); will return 2004 as desired by this
script. Netscape 7.1/Mozilla 1.7/Firefox 0.8 returns 104 per ECMA specs, however
IE 6 returns 2004 -that probably led to the expectation that the function should
return 2004.
If getYear must be used for compatiblity with older browsers, it should be done
in the context of a function that checks if return value of getYear() is less
than 1000 and adds 1900 (the offset of getYear per ECMA specs JS 1.3 is based
on) to the return value.
Comment 7•21 years ago
|
||
Original Issue (comments 1-4) does look like duplicate of bug 127426 as pointed
out by Nick Allen. This user is also getting the "GMT-0800" offset instead of
the appropriate one for thier timezone.
Comment 8•21 years ago
|
||
I have come across another web page with a problem that seems to be related to
how Mozilla/Firefox imlpements the javascript Date() and associated getYear().
In an online bank from Spain, in the form where you provide your personal data,
you enter your birthdate and the Javascipt code checks whether you are more than
18 years old or not. It seems being born in the year 1975 is not old enough :-)
URL (content in spanish): http://www.ingdirect.es/
Click on the upper left link named "CUENTAS NARANJA". Then click on the
"CONTRATAR" link at the left (you are going to open a bank account, but don't
worry, there are quite a few more steps ahead, your money won't leave you
still). The form for the personal data now appears, but I think you shouldn't
ever bother giving the form bogus data, the frame source is quite
self-explanatory by itself (birthdate is "Fecha de nacimiento" in the form, with
a "day - month - year" format). The following function is the one that tries to
calculate based on your "birthdate" whether you are more than 18 years old or not.
function MayorDeEdad()
{
day=document.forms['ContractForm'].birthDay.value;
month=document.forms['ContractForm'].birthMonth.value;
year=document.forms['ContractForm'].birthYear.value;
var fechahoy = new Date()
diahoy = fechahoy.getDate();
meshoy = fechahoy.getMonth() + 1;
aniohoy = fechahoy.getYear();
diffanios = parseFloat(aniohoy) - parseFloat(year);
diffmeses = parseFloat(meshoy) - parseFloat(month);
diffdias = parseFloat(diahoy) - parseFloat(day);
if (parseFloat(diffanios) < 18){
alert('Para la contratación es necesario ser mayor de edad.\nEn el caso de que
el titular sea menor, por favor introduzca en el formulario los datos del
representante legal.\nLos datos del menor y su documentación nos lo puede
facilitar en el formulario que recibirá por correo ordinario\ndentro de 2 ó 3
días.');
return(false);
}
if ((parseFloat(diffanios) == 18) && ((parseFloat(diffmeses) < 0)
||(parseFloat(diffdias) < 0))){
alert('Para la contratación es necesario ser mayor de edad.\nEn el caso de que
el titular sea menor, por favor introduzca en el formulario los datos del
representante legal.\nLos datos del menor y su documentación nos lo puede
facilitar en el formulario que recibirá por correo ordinario\ndentro de 2 ó 3
días.');
return(false);
}
return (true);
}
It happen that with my current Firefox version (Mozilla/5.0 (X11; U; Linux i686;
en-US; rv:1.6) Gecko/20040207 Firefox/0.8) I always get the message showing that
I am under 18, so the first test "parseFloat(diffanios) < 18" seems to be always
true. I tried several older birthdates to no avail.
However, giving the same data but using Konqueror 3.2.1 everything works OK. So
it seems Date() and/or getYear() in Mozilla/Firefox are not behaving as expected
(by the web designers at www.ingdirect.es).
Just to help confirm this "bug", hope it helps. I will try to mail the webmaster
at the online bank to see if they are willing to help.
Comment 9•21 years ago
|
||
I got a reply from the online bank stating that the won't try to make their web
site "compatible" with Mozilla or Netscape anytime soon, because:
- Their website is designed to work OK with MSIE 5.x or higher, and there is
hardly anyone using other browsers.
- Making the web site "compatible" with Mozilla would be highly costly, so they
(as an online bank) wouln't be able to continue offering banking products with
high interest rates.
I hope the "extremely high cost" of adding a couple of additional JavaScript
doesn't mean they won't invest in protecting highly sensitive customer
information, as well as the money people put under their custody.
Comment 10•21 years ago
|
||
Tell the bank to use getFullYear, it works in all browsers and is the
ECMA-recommended "Y2K" solution.
/be
Comment 11•21 years ago
|
||
please one problem per bug. the original bug is about timezones not years.
Comment 12•21 years ago
|
||
javascript:new Date(); returns the expected results with the latest Aviary build
on Windows XP.
Output: Thu Jun 24 2004 15:47:39 GMT+0200 (Romance Daylight Time)
GMT+0200 is correct for Belgium at summer time.
Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7) Gecko/20040623
Firefox/0.9.0+
Comment 13•21 years ago
|
||
Agreed, this is now WFM with the 20040722 build. Could some others please
confirm so that I can close?
Comment 14•21 years ago
|
||
javascript:new Date();
Mon Aug 16 2004 11:59:22 GMT+0200 (Romance Daylight Time)
This looks correct for Belgium
Comment 15•21 years ago
|
||
Following the steps to reproduce I get Thu Oct 07 2004 08:32:48 GMT-0400
(Eastern Daylight Time) which seems to be correct. This works for me.
Comment 16•21 years ago
|
||
Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8a5) Gecko/20041018
WorkForMe
Tue Oct 19 2004 14:02:02 GMT+0200
Comment 17•21 years ago
|
||
Six different WFM should be enough; feel free to reopen if this is still a
problem for someone.
Status: UNCONFIRMED → RESOLVED
Closed: 21 years ago
Resolution: --- → WORKSFORME
You need to log in
before you can comment on or make changes to this bug.
Description
•