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

utcToZonedTime returns next day when time matches offset #41

Closed
a1russell opened this issue Jan 30, 2020 · 0 comments · Fixed by #43
Closed

utcToZonedTime returns next day when time matches offset #41

a1russell opened this issue Jan 30, 2020 · 0 comments · Fixed by #43

Comments

@a1russell
Copy link

From #38, which was prematurely closed by its author. Here I'm pasting and editing relevant parts from #38.

The issue appears to exist on Chrome versions 80 and above. Relevant Chrome bug report, which has been closed and marked as WON'T FIX: https://bugs.chromium.org/p/chromium/issues/detail?id=1045791

An example of the problem: https://codepen.io/atomcorp/pen/gObqoyX

In short the following returns a Date object for the 24th not 23rd:

utcToZonedTime(
  new Date('Thu Jan 23 2020 05:00:00 GMT+0000 (Greenwich Mean Time)'),
  'America/New_York' // -5 hours
);

It seems to happen when the inputted time matches the offset of the timezone. So if you move the time of the inputted date an hour back or forward, so it's different to the timezone offset, both utcToZonedTime and the native method return the same.

It's specifically related to do with Intl.DateTimeFormat which is used in tzTokenizeDate.

const dateTime = new Intl.DateTimeFormat('en-US', {
      hour12: false,
      timeZone: 'America/New_York',
      year: 'numeric',
      month: '2-digit',
      day: '2-digit',
      hour: '2-digit',
      minute: '2-digit',
      second: '2-digit'
    });

const date = dateTime.format(new Date(2020, 0, 25, 5, 0, 0));

// Chome 79/Firefox etc:  date === 01/25/2020, 00:00:00
// Chrome 81:  date === 01/25/2020, 24:00:00

Example: https://codepen.io/atomcorp/pen/bGNZzZz

hyyan added a commit to BasisHub/bbj-masks that referenced this issue Feb 6, 2020
the test is failing since chrome 80
see marnusw/date-fns-tz#41
will re-enable when the issue is fixed
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

Successfully merging a pull request may close this issue.

1 participant