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(.., true) incorrect around DST #871

Open
mongoose700 opened this issue Jul 10, 2020 · 3 comments
Open

.tz(.., true) incorrect around DST #871

mongoose700 opened this issue Jul 10, 2020 · 3 comments
Labels

Comments

@mongoose700
Copy link

Fiddle: https://jsfiddle.net/r3qx7zh9/2/

const utc = moment.utc('2018-03-11T04:00');
const converted = utc.tz('America/Los_Angeles', true);
console.log(converted.toString());
console.log(converted.toISOString(true));

const direct = moment.tz('2018-03-11T04:00', 'America/Los_Angeles');
console.log(direct.toString());
console.log(direct.toISOString(true));

Output:

"Sun Mar 11 2018 05:00:00 GMT-0700"
"2018-03-11T04:00:00.000-08:00"
"Sun Mar 11 2018 04:00:00 GMT-0700"
"2018-03-11T04:00:00.000-07:00"

It's very strange that the converted moment has different offsets for toString and toISOString. It stops happening at '2018-03-11T10:00'.

@mongoose700
Copy link
Author

I've looked into the code a bit, and it seems that it's doing the conversion in two steps. First it converts the time from 2018-03-11T04:00Z to 2018-03-10T20:00-08:00, then it tries to move it into the future by eight hours, which puts it at 2018-03-11T04:00-08:00, which is actually 2018-03-11T05:00-07:00 because of the DST shift.

@ichernev
Copy link
Contributor

Yep, I can verify that the bug exists. We could try to extract pieces (year, month, day, hour, minute, second) and re-create a new moment from that, it should work better.

@ichernev ichernev added the bug label Aug 26, 2022
@ichernev ichernev changed the title Converting a moment to another time zone preserving the local time is incorrect near DST transitions .tz(.., true) incorrect around DST Aug 26, 2022
@ichernev
Copy link
Contributor

Possibly related to #935

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

No branches or pull requests

2 participants