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

[DST] Wrong date when adding one day #593

Closed
AndreLorenz opened this issue Apr 3, 2018 · 5 comments
Closed

[DST] Wrong date when adding one day #593

AndreLorenz opened this issue Apr 3, 2018 · 5 comments

Comments

@AndreLorenz
Copy link

AndreLorenz commented Apr 3, 2018

Hello!!

I need to add one day before DST, but when I set moment.tz.setDefault to "America/Sao_Paulo" and add one day to October 20, 2018 the moment returns the same day at 11:00PM instead of October 21, 2018 at 01:00AM.

Already when I reset tz (setDefault()) it returns the correct date.

moment.tz.setDefault() // Reset tz
moment('10/20/2018', "MM/DD/YYYY").startOf('day').add(1, 'day').format()
// "2018-10-21T01:00:00-02:00" (Correct date)

moment.tz.guess()
// "America/Sao_Paulo"
moment.tz.setDefault(moment.tz.guess())
moment('10/20/2018', "MM/DD/YYYY").startOf('day').add(1, 'day').format()
// "2018-10-20T23:00:00-03:00" (Incorrect date)

Workaround for this issue:

moment.tz.guess()
// "America/Sao_Paulo"
moment.tz.setDefault(moment.tz.guess())
const date = moment('10/20/2018', "MM/DD/YYYY").hour(12).add(1, 'day')
date.startOf('day').format()
// "2018-10-21T01:00:00-02:00" (Correct date)

Thanks

@ellenaua
Copy link
Contributor

ellenaua commented Apr 13, 2018

FYI: this happens because data/latest.json contains invalid dates of time change for America/Sao_Paulo

86= 2017-02-19T02:00:00.000Z
87= 2017-10-15T03:00:00.000Z
88= 2018-02-18T02:00:00.000Z
89= 2018-10-21T03:00:00.000Z
90= 2019-02-17T02:00:00.000Z
91= 2019-10-20T03:00:00.000Z

Time change was on 2018-02-18 this February, but next time change will be not on 2018-10-21 but on 2018-11-04 (I check here https://www.timeanddate.com/time/zone/brazil/sao-paulo)
So, data/latest.json contains invalid data.

Because of that, when user adds +1 day, it adds +1 day and -1 hour (library thinks that time change happens on 2018-10-21) so user gets same day 23:00

@ellenaua
Copy link
Contributor

This PR will deliver updated data #577

@ellenaua
Copy link
Contributor

@AndreLorenz in moment-timezone 0.5.16 this problem does not happen for 10/20/2018, but happens for 11/03/2018 because Clock Change is happening on 11/04/2018 00:00 according to updated data from IANA TZ database.

moment.tz.setDefault('America/Sao_Paulo');
const v1 = moment('11/03/2018', "MM/DD/YYYY").startOf('day').add(1, 'day');
const v2 = moment('11/03/2018', "MM/DD/YYYY").startOf('day').add(24, 'hour');
console.log(v1.toString()); // Sat Nov 03 2018 23:00:00 GMT-0300
console.log(v2.toString()); // Sun Nov 04 2018 01:00:00 GMT-0200

I'll post more info about this issue later.

@joshwils82
Copy link

joshwils82 commented Feb 13, 2019

I am experiencing this issue as well. Any chance this could get fixed soon?

@mattjohnsonpint
Copy link
Contributor

Duplicate of #409. Tracking there. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants