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

Wrong time in GMT timezones when locale is set #1813

Open
justingolden21 opened this issue Feb 23, 2022 · 2 comments
Open

Wrong time in GMT timezones when locale is set #1813

justingolden21 opened this issue Feb 23, 2022 · 2 comments

Comments

@justingolden21
Copy link

Describe the bug

The following code:

new dayjs(newDate())
  .tz('Europe/London')
  .locale('en')
  .format('h:mm A');

Returns a time in EST (5 hours behind London, 3 hours ahead of me)

I'm located in California, not that that should matter here.

All other timezones that aren't in GMT time work perfectly fine

new dayjs(newDate())
  .tz('Europe/London')
  .format('h:mm A');

Not setting the locale this works perfectly fine.

Please assist

Expected behavior

The correct time in London

Information

  • Day.js Version ^1.10.7
  • OS: Windows
  • Browser: Chrome Version 97.0.4692.71 (Official Build) (64-bit)
  • Time zone: GMT-08:00 PST (Pacific Standard Time)
@justingolden21 justingolden21 changed the title Wrong Time for London when Locale is set to 'en' Wrong time in GMT timezones when locale is set Feb 23, 2022
@justingolden21
Copy link
Author

It's not off by 4 hours which is interesting. Haven't had daylight savings in either timezone since I reported the bug.

@Juanc1to
Copy link

What a curious little bug you've found! For one, it is actually daylight savings sensitive. When you first reported the bug, the current date and time were in daylight savings time, which, in order to be reproducible, should be written like this:

> let bugexample = dayjs('2022-02-23T10:00:00-05:00');
> bugexample.tz('Europe/London').locale('en').format('h:mm A');
'8:00 PM'
> bugexample.tz('Europe/London').format('h:mm A');
'3:00 PM'

But if we use a date in standard time (like right now as of this writing), the anomaly disappears:

> let bugexample2 = dayjs('2022-06-14T10:00:00-05:00');
> bugexample2.tz('Europe/London').locale('en').format('h:mm A');
'4:00 PM'
> bugexample2.tz('Europe/London').format('h:mm A');
'4:00 PM'

As a note, invoking .utc() seems to be a workaround for the bug in the first case:

> bugexample.tz('Europe/London').utc().locale('en').format('h:mm A');
'3:00 PM'

Thanks for the report!

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

No branches or pull requests

2 participants