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

moment.utc(date).tz(timezone, true) incorrect date around DST days #935

Open
arturzealves opened this issue Mar 30, 2021 · 2 comments
Open
Labels

Comments

@arturzealves
Copy link

Moment-timezone version which you use:

Version: 0.5.33

Issue description:

Australia/Sydney changes its time on 2020-04-04 at 03:00:00, moving backward to 02:00:00
moment-timezone has an issue parsing a date from UTC to Australia/Sydney (with Boolean = true) on the day before Daylight Saving Time Ends:

  - moment.tz('2021-04-03 15:00:00', 'Australia/Sydney');
  Moment<2021-04-03T15:00:00+11:00> // Correct
  
  - moment.tz('2021-04-03 15:00:00', 'Australia/Sydney').toISOString();
  '2021-04-03T04:00:00.000Z' // Correct
  
  - moment.utc('2021-04-03T15:00:00.000Z').tz('Australia/Sydney', true);
  Moment<2021-04-03T15:00:00+11:00> // Correct
  
  - moment.utc('2021-04-03T15:00:00.000Z').tz('Australia/Sydney', true).toISOString();
  '2021-04-03T04:00:00.000Z' // Correct

But:

  - moment.tz('2021-04-03 16:00:00', 'Australia/Sydney');
  Moment<2021-04-03T16:00:00+11:00> // Correct

  - moment.tz('2021-04-03 16:00:00', 'Australia/Sydney').toISOString();
  '2021-04-03T05:00:00.000Z' // Correct

  - moment.utc('2021-04-03T16:00:00.000Z').tz('Australia/Sydney', true);
  Moment<2021-04-03T16:00:00+10:00> // Incorrect

  - moment.utc('2021-04-03T16:00:00.000Z').tz('Australia/Sydney', true).toISOString();
  '2021-04-03T06:00:00.000Z' // Incorrect
@gilmoreorless
Copy link
Member

From what I can tell, moment-timezone is first grabbing the UTC offset for the Australia/Sydney zone for the existing timestamp, then storing the inverted result as the internal offset calculation.

This works fine most of the time, but in the case you've found, it means Sydney's offset for 2021-04-03 16:00 UTC is being used (which is +10:00), instead of the correct offset for 2021-04-03 16:00 Sydney (which is +11:00).

@adityapachpor978478
Copy link

epoch 1678615200000 is actually Sunday March 12, 2023 03:00:00 (am) in time zone America/Los Angeles (PDT) but moment results in "Sun, Mar 12 2023 - 02:00"
https://www.epochconverter.com/timezones?q=1678615200&tz=America%2FLos_Angeles
https://jsfiddle.net/adityapachpor/abqsmu40/

Is this the same issue as yours?

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

4 participants