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

toDate shifts actual date by 1 hour #1791

Open
Nkmol opened this issue Feb 2, 2022 · 2 comments
Open

toDate shifts actual date by 1 hour #1791

Nkmol opened this issue Feb 2, 2022 · 2 comments

Comments

@Nkmol
Copy link

Nkmol commented Feb 2, 2022

Describe the bug
toDate() shifts time by 1 hour. This only happens when I am shifting from summertime (October 31 03:00:00 2021 GMT +2) to wintertime (October 31 02:00:00 2021 GMT +1) in runtime.

The problem stops persisting in runtime at 2021-11-02 02:16:05 +0100.

Current time: Sun Oct 31 2021 02:00:03 GMT+0100 (Central European Standard Time)
Input: 21-02-18 00:00:00

const dayjsResult = dayjs(input, format).tz(timeZone); // Wed Feb 21 2018 00:00:00 GMT+0100 (Central European Standard Time)
dayjsResult.toDate(); // Tue Feb 20 2018 23:00:00 GMT+0100 (Central European Standard Time)

Expected behavior
toDate() should have not shifted hours, but instead keep the same datetime

Work around

const dayjsResult = dayjs('21-02-18 00:00:00', 'DD-MM-YY HH:mm:ss').tz('Europe/Amsterdam');
const correctDate = new Date(dayjsResult.$d); // Wed Feb 21 2018 00:00:00 GMT+0100 (Central European Standard Time)

I am not sure where the core issue lies and why using the internal getTime() would not be enough for this.

Information

  • Day.js Version 1.10.4 / 1.10.7
  • Browser Node 16.13.2
  • Time zone: GMT +1 / GTM +2

Related
#1805

@Nkmol Nkmol changed the title toDate shifts actual data by 1 hour toDate shifts actual date by 1 hour Feb 2, 2022
@gianlucaparadise
Copy link

I'm experiencing the same issue. As an addition, the same behaviour is happening with toISOString() function.

@henhal
Copy link

henhal commented Feb 4, 2022

This may be the same as what I just submitted: #1795

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

3 participants