Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tz() produces incorrect time when passing in milliseconds since the epoch near DST boundary. #1817

Open
jwalton opened this issue Mar 1, 2022 · 0 comments

Comments

@jwalton
Copy link

jwalton commented Mar 1, 2022

Describe the bug

const dayjs = require('dayjs');
dayjs.extend(require('dayjs/plugin/utc'));
dayjs.extend(require('dayjs/plugin/timezone'));

// On March 13, 2022 in America/Montreal, at 2:00am, we roll the time back by 1 hour.
// This is the exact millisecond when that happens:
const dstBoundary = 1647154800000;

// This should obviously be true, and it is.
console.log(dayjs.tz(dstBoundary - 1, 'America/Montreal').valueOf() === dstBoundary - 1);

// This should also obviously be true, but it is false.  :(
console.log(dayjs.tz(dstBoundary, 'America/Montreal').valueOf() === dstBoundary);

Expected behavior

When explicitly setting the time as a value in ms since the epoch, dayjs should not change the time we set, but here it does, rewinding time by one hour. 1647154800000 and 1647151200000 are two very different times.

Information

  • Day.js Version: v1.10.8
  • OS: MacOS
  • Browser: node v16.14.0
  • Time zone: America/Montreal
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant