dayjs: Timezone conversion incorrect when daylight saving in effect
Describe the bug Dayjs does not seem to convert timezone correctly when DST is in effect. It produces different results from Moment. The Moment results seem intuitively what I’d expect, so believe to be correct unless there is some subtlety I’m missing.
Expected behavior With this code:
const when = '2020-07-30T12:00:00+00:00'; // Midday GMT in summer
console.log('Moment London: ' + moment(when).tz('Europe/London').format('HH:mm Z'));
console.log('Moment New York: ' + moment(when).tz('America/New_York').format('HH:mm Z'));
console.log('Dayjs London: ' + dayjs(when).tz('Europe/London').format('HH:mm Z'));
console.log('Dayjs New York: ' + dayjs(when).tz('America/New_York').format('HH:mm Z'));
The output is:
Moment London: 13:00 +01:00
Moment New York: 08:00 -04:00
Dayjs London: 12:00 +00:00 // Expect 13:00 +01:00
Dayjs New York: 08:00 -05:00 // Expect 08:00 -04:00
Information
- Day.js: v1.9.6
- OS: Windows 10 Home
- Nodejs: v12.8.3
- Time zone: GMT+00:00
About this issue
- Original URL
- State: open
- Created 4 years ago
- Reactions: 32
- Comments: 21
a year and a half after this bug was reported and it’s still no fixed? damn… should i revert to momentjs after all?
The problem is still relevant.
Just noting that this is still an issue in 1.11.10
The issue remains,
EDIT: updated to 1.11.6, the issue remains.
Verified with unixtimestamp.com and python.
EDIT2: If the time is specified this way then the conversion is correct,
was there ever a solution for this?
Seems the issue still in place.
I tried to run this script in different time zones and got quite diverged results.
ServerTime: Wed Sep 15 2021 08:14:59 GMT+0200 (Central European Summer Time)
ServerTime: Wed Sep 15 2021 07:15:53 GMT+0100 (British Summer Time)
ServerTime: Wed Sep 15 2021 16:16:46 GMT+1000 (Vladivostok Standard Time)
This issue affects also development process when remote developers run it on their own local machines across the world.
I expect to have the same result which is not related to the server’s timezone.
Please correct me if I’m wrong.
It sounds like it hasn’t. I thought #1352 would fix it but others have reported not. Note that these changes are not officially released. In other words, you have to use the
dev
branch in order to get the latest changes.If you’re interested, try with the
dev
branch and see if it’s still broken