Closed
Bug 251437
Opened 20 years ago
Closed 20 years ago
JavaScript .getYear() returns 104 for current Date()
Categories
(Core :: JavaScript Engine, defect)
Tracking
()
People
(Reporter: dvdbeahm, Unassigned)
Details
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.7.1) Gecko/20040707 Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.7.1) Gecko/20040707 <html> <head> <title>labrat</title> <script type="text/javascript"> <!-- function checkDate() { var foo; foo = document.form1.tbxpurchdy.value + document.form1.tbxpurchmo.value + document.form1.tbxpurchyr.value; if(foo != "") { var dy; var mo; var yr; var daze = new Array(31,28,31,30,31,30,31,31,30,31,30,31); var msg; msg = ""; yr = parseInt(document.form1.tbxpurchyr.value,10); mo = parseInt(document.form1.tbxpurchmo.value,10); dy = parseInt(document.form1.tbxpurchdy.value,10); if(yr < 0 || isNaN(yr)) { msg = msg + "\n Invalid Year: " + document.form1.tbxpurchyr.value; } if(yr > 80) { var today = new Date(); var maxyr = today.getYear(); if(yr < 1996 || yr > maxyr) { msg = msg + "\n Invalid Year: " + document.form1.tbxpurchyr.value; msg = msg + "\n Maxyr: " + maxyr; msg = msg + "\n today: " + today; } } else { yr += 2000; } if(mo < 0 || mo > 12 || isNaN(mo)) { msg = msg + "\n Invalid Month: " + document.form1.tbxpurchmo.value; } if(dy < 0 || isNaN(dy) || dy > 31) { msg = msg + "\n Invalid Day: " + document.form1.tbxpurchdy.value; } if(msg == "") { daze[1] += (yr % 4 ? 0: yr %100 ? 1 : yr % 400 ? yr == 200 ? 1 : 0 : 1); // leap year calc if(dy > daze[mo - 1]) { msg = msg + "\n Invalid Day: " + document.form1.tbxpurchdy.value; } } if(msg != "") { alert(msg); } else { //document.form1.test.value = daze[mo - 1]; document.form1.test.value = mo + "/" + dy + "/" + yr; } } } --> </script> </head> <body onLoad="checkDate()"> <form id="form1" name="form1"> Month <input name="tbxpurchmo" type="text" size="2" value="12"/>/ Day <input name="tbxpurchdy" type="text" size="2" value="21"/>/ Year <input name="tbxpurchyr" type="text" size="4" value="2004"/> Date: <input id="test" name="test" type="text" size="20" /> <input type="button" name="Doit" value="Do it" onClick="checkDate()"> </form> </body> </html> Reproducible: Always Steps to Reproduce: 1.Save the above as a web page and view it. 2.JavaScript will run on load and error message will show what getYear() returned. (Verified that IE doesn't trip over this) Actual Results: Alert box shows Invalid Year: 2004 Maxyr: 104 today: Wed Jul 14 2004 15:35:22 GMT-0400 (Eastern Daylight Time) Expected Results: The alert box shouldn't show, because maxyr should be 2004.
Comment 1•20 years ago
|
||
It's supposed to return 104. Use getFullYear to get your desired result. IE is doing it wrong. *** This bug has been marked as a duplicate of 100123 ***
Status: UNCONFIRMED → RESOLVED
Closed: 20 years ago
Resolution: --- → DUPLICATE
Updated•20 years ago
|
Status: VERIFIED → UNCONFIRMED
Resolution: DUPLICATE → ---
Comment 2•20 years ago
|
||
*** This bug has been marked as a duplicate of 22964 ***
Status: UNCONFIRMED → RESOLVED
Closed: 20 years ago → 20 years ago
Resolution: --- → DUPLICATE
You need to log in
before you can comment on or make changes to this bug.
Description
•