Date.setMinutes(0) changes date by one hour when operating on DST boundary
Categories
(Core :: JavaScript Engine, defect)
Tracking
()
People
(Reporter: patrick, Unassigned)
Details
User Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:78.0) Gecko/20100101 Firefox/78.0
Steps to reproduce:
Execute the following JS code (e.g. in the dev console):
const d = new Date(1635642000000);
console.log(d);
d.setMinutes(0);
console.log(d);
Actual results:
Actual log output:
Sun Oct 31 2021 02:00:00 GMT+0100 (Mitteleuropäische Normalzeit)
Sun Oct 31 2021 02:00:00 GMT+0200 (Mitteleuropäische Sommerzeit)
Observe how the time zone changed from GMT+0100 to GMT+0200 while the other parts of the date stay the same.
Expected results:
The date should have been the same in both log outputs and should NOT have changed by one hour (cf. changed time zone from GMT+0100 to GMT+0200).
Note that this issue does not happen in Safari.
Comment 1•5 years ago
|
||
Bugbug thinks this bug should belong to this component, but please revert this change in case of error.
Also observe how the UTC timestamp changes, even though getTime docs say:
"getTime() always uses UTC for time representation. For example, a client browser in one timezone, getTime() will be the same as a client browser in any other timezone."
const d1 = new Date(1635642000000);
console.log(d1.getTime());
// 1635642000000
d1.setMinutes(0);
console.log(d1.getTime());
// 1635638400000
Comment 3•5 years ago
|
||
This behaviour is actually required by the ECMAScript specification:
setMinutes effectively calls MakeDate(MakeDay(2021, 10-1, 31), MakeTime(2, 0, 0, 0)).. This value is then passed to UTC, which in turn calls LocalTZA. At daylight saving boundaries LocalTZA is required to return the time zone adjustment before the transition. So at 2 o'clock the spec requires us to use 2 AM summer time instead of standard time. And this is reflected in the output, which says "GMT+0200 (Mitteleuropäische Sommerzeit)".
The same behaviour is visible in Chrome. It's not visible in Safari, because Safari hasn't yet implemented this part of the spec. (The spec changed in https://github.com/tc39/ecma262/pull/778.)
Comment 5•5 years ago
|
||
Kein Problem. :-)
Description
•