Timezone plugin unexpected daylight calculation
See original GitHub issueDescribe the bug
When using the timezone plugin the date calculated by dayjs is unexpected for daylight datetime calculation, I’m comparing towards moment-timezone.
Expected behaviour
const moment = require('moment-timezone');
const dayjs = require('dayjs');
const utc = require('dayjs/plugin/utc');
const tz = require('dayjs/plugin/timezone');
dayjs.extend(utc);
dayjs.extend(tz);
const timezone = 'America/Vancouver';
const currentDate = new Date('2020-03-08T12:00-07:00');
const nowMoment = moment(currentDate);
const nowDayJs = dayjs(currentDate);
// milliseconds for currentDate: 1583694000000
console.log(nowDayJs.valueOf() === nowMoment.valueOf()); // -> true
// daylight
// https://www.timetemperature.com/canada/daylight_saving_time_canada.shtml
const plainDate = currentDate.toISOString().slice(0, 10); // 2020-08-08
const dlMoment = moment.tz(plainDate, timezone).set({
hour: 12,
minute: 30
});
const dlDayJs = dayjs.tz(plainDate, timezone)
.set('hour', 12)
.set('minute', 30);
console.log(dlDayJs.format() === dlMoment.format()); // -> false (true expected)
// 2020-03-07T12:30:00-08:00 !== 2020-03-08T12:30:00-07:00
Information
- dayjs: 1.8.33
- moment-timezone: 0.5.31
- OS: Ubuntu 18.04.4 LTS
- Nodejs 12.18.0
- Time zone: GMT-07:00 DST (Pacific Daylight Time)
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:10
Top Results From Across the Web
How to prevent Notes/Domino from adjusting for daylight ...
If the value is set to "No" and you experience behavior where the time zone setting reverts to an unexpected value, then check...
Read more >How to Change Your WordPress Timezone - CoSchedule
Select the city nearest to you with the same timezone (A city is preferred if one is available, rather than choosing UTC options,...
Read more >Time zone does not recognize daylight savings time
This time zone does not recognize daylight savings time. The user needed to reset their Enterprise application time zone to the proper regional ......
Read more >rrule.js - Recurrence series changes time of day in time zone ...
Try out the CodeSandbox. Should get similar results as long as you are in a time zone that has Daylight Savings and the...
Read more >Time zones - Product Documentation | ServiceNow
However, times appear to users in their local time zone, ... Time with the same zone offset and Daylight Savings Time (DST) schedule....
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Timezone support seems to be quite broken at the moment, unfortunately.
Compare to
moment:I have run in to the same issue. Here is my test case, which is a bit simpler than the one above:
Expected:
Actual:
And some information
dayjs: 1.8.35 OS: MacOS 10.15.5 Nodejs 14.10.1 Time zone: GMT-07:00 DST (Pacific Daylight Time)
Edit: I just noticed DST actually started in the early hours of March 8, so it appears dayjs may be incorrectly calculating when DST should start (March 9 should have already been using -4 offset, but instead dayjs.tz() didn’t start using -4 offset until March 10)