moment-timezone icon indicating copy to clipboard operation
moment-timezone copied to clipboard

.tz(.., true) incorrect around DST

Open mongoose700 opened this issue 5 years ago • 3 comments

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 avatar Jul 10 '20 19:07 mongoose700

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.

mongoose700 avatar Jul 12 '20 02:07 mongoose700

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 avatar Aug 26 '22 13:08 ichernev

Possibly related to #935

ichernev avatar Aug 27 '22 17:08 ichernev