iamkun / iamkun/dayjs

Timezone plugin unexpected daylight calculation

Open
#1,001 11 comments 1 reaction 0 assignees View on GitHub
☢️Bug
Dominant language
JavaScript
Stars
48.7k
Forks
2.5k
PR merge metrics
No merged PRs in 30d

Description

**Describe 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)

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the supplied Node.js example with the timezone and UTC plugins, then inspect the timezone plugin entry point and related tests. Compare the daylight-saving result with moment-timezone for the stated date and timezone; done means the Day.js formatted value matches the expected 2020-03-08T12:30:00-07:00 result.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.