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

Most upvoted comments

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,

    "dayjs": {
      "version": "1.11.5",

EDIT: updated to 1.11.6, the issue remains.

dayjs.utc("2022-04-22 15:08:45").unix() // wrong, expected: 1650640125, actual: 1650636525 
dayjs.utc("2022-08-22 15:08:45").unix() // wrong, expected: 1661180925, actual: 1661177325
dayjs.utc("2022-01-22 15:08:45").unix() // ok, expected: 1642864125, actual: 1642864125

Verified with unixtimestamp.com and python.

EDIT2: If the time is specified this way then the conversion is correct,

dayjs.utc("2022-04-22T15:08:45.000Z").unix() // ok, expected: 1650640125, actual: 1650640125

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.

console.log(dayjs("2027-10-31T00:00:00Z").tz("Europe/Berlin").format());

console.log(dayjs("2027-10-31T01:00:00Z").tz("Europe/Berlin").format()); // +1hr

ServerTime: Wed Sep 15 2021 08:14:59 GMT+0200 (Central European Summer Time)

2027-10-31T02:00:00+02:00
2027-10-31T02:00:00Z

ServerTime: Wed Sep 15 2021 07:15:53 GMT+0100 (British Summer Time)

2027-10-31T02:00:00+03:00
2027-10-31T02:00:00+01:00

ServerTime: Wed Sep 15 2021 16:16:46 GMT+1000 (Vladivostok Standard Time)

2027-10-31T02:00:00+02:00
2027-10-31T02:00:00+01:00

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