All users were logged out of Bugzilla on October 13th, 2018

Y2K error in .getYear()

RESOLVED DUPLICATE of bug 22964

Status

()

P3
normal
RESOLVED DUPLICATE of bug 22964
19 years ago
14 years ago

People

(Reporter: simon.lucy, Assigned: rogerl)

Tracking

Trunk
x86
Windows 2000
Points:
---

Firefox Tracking Flags

(Not tracked)

Details

(Reporter)

Description

19 years ago
From Bugzilla Helper:
User-Agent: Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)
BuildID:    

I have the following function in navigator.js to update a date time string 
within the chrome.  getYear() returns '100'for the year 2000.

function datetimeDisplay()
{
	var dateObj = new Date()
	var hour = dateObj.getHours()
	var minutes = dateObj.getMinutes()
	var date = dateObj.getDate()
	var datedisplay = document.getElementById("NetDate");
	if( minutes < 10 ) {
		minutes = "0"+minutes ;
	}
	// javascript .getYear() isn't Y2K compliant 
	datedisplay.setAttribute("value", dateObj.getDate()+"/"+
(dateObj.getMonth()+1)+"/"+(2100-dateObj.getYear())+" "+hour+":"+minutes);
}

Any other to...String function works correctly
This is using M16 tarball


Reproducible: Always
Steps to Reproduce:
1. Create new Date variable
2. use variable.getYear()=
3. print the result and you'll see its '100' for the year 2000

Expected Results:  Should return a two digit year string (4 digit would be 
allowable)

Comment 1

19 years ago
Thank you for the submission! However, I'm afraid I have to mark this one 
as "Invalid", because the getYear() method is behaving according to spec.

(see ECMA Edition 3, 13 October 1999 - Section B.2.4)

The getYear() method has been superseded by the getFullYear() method.
For more details, see bug 22964.
Status: UNCONFIRMED → RESOLVED
Last Resolved: 19 years ago
Resolution: --- → INVALID

Comment 2

19 years ago
Verifying Invalid -
Status: RESOLVED → VERIFIED
(Reporter)

Comment 3

19 years ago
No problem, other than bugzilla failing again to come up with a previous bug 
report to save everyone time.

It might also be worth noting that IE doesn't have the same issue with getYear
().

Comment 4

19 years ago
Your point is well taken !

I've looked into this further, and obtained some history of the problem from the 
developers, below. I hope it is useful -


Here's what happened -

Between JavaScript versions 1.2 and 1.3, we rewrote the Javascript Date
object from the ground up.  It handles all date operations internally, with
as few dependencies on the underlying operating system as possible.  This
new implementation has been in the Netscape browsers since version 4.06.

Our implementation was based on the ongoing ECMA-262 standardization work for
JavaScript.  At the time, the ECMA-262 draft included a definition of
getYear that returned the year - 1900.  In other words, years in the 20th
century come out as two digits, and years in the 21st century come out as
three digits.  This behavior was different from many (but not all)
JavaScript Date implementations, but we retained it to be compliant with the
evolving standard.

Later, after the release of 4.06 and 4.5 browsers incorporating the new Date
code, the getYear method was dropped from the developing ECMA-262 standard,
as getFullYear serves the same purpose without the associated problems. 
(getYear remains as an appendix to the standard, but is not required for
compliance.)  Rather than revert to the old getYear behavior and force
scriptwriters to be aware of yet another version difference, we decided to
keep the year - 1900 behavior for getYear, and encourage the use of
getFullYear.

It's not an ideal situation, but that's the history.

For JavaScript code that must work across browser versions that may not have
the getFullYear method, please see Michelle Wyner's tech note at

http://developer.netscape.com/viewsource/wyner_2k/wyner_2k.html

Comment 5

16 years ago
*** Bug 161885 has been marked as a duplicate of this bug. ***

Comment 6

16 years ago
*** Bug 162843 has been marked as a duplicate of this bug. ***

Comment 7

16 years ago
*** Bug 187962 has been marked as a duplicate of this bug. ***

Comment 8

16 years ago
*** Bug 192241 has been marked as a duplicate of this bug. ***

Comment 9

16 years ago
*** Bug 192481 has been marked as a duplicate of this bug. ***
*** Bug 194789 has been marked as a duplicate of this bug. ***
*** Bug 224265 has been marked as a duplicate of this bug. ***
*** Bug 235837 has been marked as a duplicate of this bug. ***
*** Bug 160532 has been marked as a duplicate of this bug. ***
*** Bug 169766 has been marked as a duplicate of this bug. ***
*** Bug 228929 has been marked as a duplicate of this bug. ***
Status: VERIFIED → UNCONFIRMED
Resolution: INVALID → ---

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