Date.setYear() modifies the time

RESOLVED FIXED

Status

P3
normal
RESOLVED FIXED
18 years ago
18 years ago

People

(Reporter: david, Assigned: mike+mozilla)

Tracking

Details

Attachments

(1 attachment)

(Reporter)

Description

18 years ago
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)
(Assignee)

Comment 1

18 years ago
I'll look at this.
Assignee: nboyd → mccabe

Comment 2

18 years ago
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.
(Assignee)

Comment 3

18 years ago
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.
(Assignee)

Comment 4

18 years ago
Created attachment 20289 [details] [diff] [review]
add local time adjustment.
(Assignee)

Comment 5

18 years ago
Fix checked in.
Status: NEW → RESOLVED
Last Resolved: 18 years ago
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.