Closed Bug 58120 Opened 25 years ago Closed 25 years ago

Date.setYear() modifies the time

Categories

(Rhino Graveyard :: Core, defect, P3)

defect

Tracking

(Not tracked)

RESOLVED FIXED

People

(Reporter: david, Assigned: mike+mozilla)

Details

Attachments

(1 file)

Date.setYear() modifies the time as well as the year: oxymoron:47 % java -jar js.jar js> d = new Date() Thu Oct 26 14:41:50 GMT-0700 (PDT) 2000 js> d.setYear(2000) 972621710313 js> d Thu Oct 26 21:41:50 GMT-0700 (PDT) 2000 Note that the time changes by 7 hours (which is the difference between local time and UTC time). I think this behavior is incorrect, and it differs from the behavior of spidermonkey. See ECMA v3, section B.2.5 (in appendix B, since this is a deprecated method)
I'll look at this.
Assignee: nboyd → mccabe
Here is the ECMA section: B.2.5 Date.prototype.setYear(year) NOTE The setFullYear method is preferred for nearly all purposes, because it avoids the “year 2000 problem.” When the setYear method is called with one argument year the following steps are taken: 1. Let t be the result of LocalTime(this time value); but if this time value is NaN, let t be +0. 2. Call ToNumber(year). 3. If Result(2) is NaN, set the [[Value]] property of the this value to NaN and return NaN. 4. If Result(2) is not NaN and 0 £ ToInteger(Result(2)) £ 99 then Result(4) is ToInteger(Result(2)) + 1900. Otherwise, Result(4) is Result(2). 5. Compute MakeDay(Result(4), MonthFromTime(t), DateFromTime(t)). 6. Compute UTC(MakeDate(Result(5), TimeWithinDay(t))). 7. Set the [[Value]] property of the this value to TimeClip(Result(6)). 8. Return the value of the [[Value]] property of the this value.
Yep, this is busted. Sorry for not resolving it earlier - at first glance, I thought it might be related to a daylight savings transition - points at which unintuitive behavior can occur. We're missing a LocalTime call. Thanks for catching this.
Fix checked in.
Status: NEW → RESOLVED
Closed: 25 years ago
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: