JavaScript .getYear() returns 104 for current Date()

RESOLVED DUPLICATE of bug 22964

Status

()

Core
JavaScript Engine
RESOLVED DUPLICATE of bug 22964
14 years ago
13 years ago

People

(Reporter: David Beahm, Unassigned)

Tracking

Trunk
x86
Windows 2000
Points:
---

Firefox Tracking Flags

(Not tracked)

Details

(Reporter)

Description

14 years ago
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

14 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
Last Resolved: 14 years ago
Resolution: --- → DUPLICATE

Updated

14 years ago
Status: RESOLVED → VERIFIED
Status: VERIFIED → UNCONFIRMED
Resolution: DUPLICATE → ---

*** This bug has been marked as a duplicate of 22964 ***
Status: UNCONFIRMED → RESOLVED
Last Resolved: 14 years ago13 years ago
Resolution: --- → DUPLICATE
You need to log in before you can comment on or make changes to this bug.