Closed Bug 718175 Opened 12 years ago Closed 7 years ago

Wrong result creating a Date object from milliseconds

Categories

(Core :: JavaScript Engine, defect)

9 Branch
x86
Linux
defect
Not set
normal

Tracking

()

RESOLVED INVALID

People

(Reporter: u410306, Unassigned)

Details

User Agent: Mozilla/5.0 (X11; Linux i686; rv:9.0.1) Gecko/20100101 Firefox/9.0.1
Build ID: 20111223083621

Steps to reproduce:

var a=new Date();
var b=new Date();
var c=new Date(b.getTime()-a.getTime());

console.log(c.getHours() + ", " + c.getMinutes() + ", " + c.getSeconds());


Actual results:

It shows "1, 0, 0".



Expected results:

It should be "0, 0, 0" (btw, Chromium does it right).

Using getUTC* methods, it works as expected. So I guess it's a problem related the non UTC methods.

My timezone is Europe/London.
I believe Firefox is correct here. Midnight on 1st January 1970 UTC (the time corresponding to 0 milliseconds in Javascript) was actually 1am UK time, not midnight, because at that time the UK was on BST year-round.
OK, thanks for your help!
Status: UNCONFIRMED → RESOLVED
Closed: 12 years ago
Resolution: --- → INVALID
Assignee: nobody → general
Component: Untriaged → JavaScript Engine
Product: Firefox → Core
QA Contact: untriaged → general
Actually, it might be a valid bug after all. According to ECMA-262, dates in the past should have the *current* daylight saving rules applied to them, not the daylight saving rules that were in place at the time of the date.

So while in reality midnight UTC on 1st January 1970 was 1am local time, if the current DST rules are used (ie. local UK time in January is UTC) then it would have been midnight local time. In which case, Firefox is wrong.

Maybe you should re-open the bug?
What made me open the bug in first place was Chromium JS implementation showing a different behaviour. If FF is wrong or not, it looks like the kind of method you can use safely.

OK, I reopened it. Thanks again!
Status: RESOLVED → UNCONFIRMED
Resolution: INVALID → ---
s/can/can't/g
I'm pretty sure this is a real bug. ECMA-262 15.9.1.8 backs comment 3:

"The implementation of ECMAScript should not try to determine whether the exact time was subject to daylight saving time, but just whether daylight saving time would have been in effect if the current daylight saving time algorithm had been used at the time. This avoids complications such as taking into account the years that the locale observed daylight saving time year round."

The last sentence applies directly to this bug.
Status: UNCONFIRMED → NEW
Ever confirmed: true
If I did everything right, I got "22, 0, 0" on Nightly and Chrome 34.
Assignee: general → nobody
No longer valid with the changes from ES2015, per https://tc39.github.io/ecma262/#sec-daylight-saving-time-adjustment:
> An implementation-dependent algorithm using best available information on time zones to determine the local daylight saving time adjustment DaylightSavingTA(t), measured in milliseconds. An implementation of ECMAScript is expected to make its best effort to determine the local daylight saving time adjustment.


IOW, `new Date(0).getHours()` should be `1` when the time zone is set to "Europe/London" for reasons stated in comment #1.
Status: NEW → RESOLVED
Closed: 12 years ago7 years ago
Resolution: --- → INVALID
You need to log in before you can comment on or make changes to this bug.