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

Issue with converting to Europe/London timezone #1219

Open
anzap opened this issue Nov 14, 2020 · 17 comments
Open

Issue with converting to Europe/London timezone #1219

anzap opened this issue Nov 14, 2020 · 17 comments

Comments

@anzap
Copy link

anzap commented Nov 14, 2020

Describe the bug
I have dates formatted in ISO-8601 format and use dayjs to convert them to different timezones. Conversion works file for all cases except for "Europe/London". It seems the issue might apply to all timezones that match UTC one.

What i do is i use dayjs in an angular app where i have a custom pipe doing the following in the function:

dayjs.extend(utc);
dayjs.extend(timezone);
return dayjs(value).tz(tz).locale(locale).format(pattern);

where value is 2020-11-06T19:27:08Z and tz Europe/London and pattern DD MMM, HH:mm a

In this case i would expect 06 Nov, 19:27 pm but i get 06 Nov, 17:27 pm.
If i change timezone to something that does not match UTC like Europe/Athens or Europe/Paris the conversion works fine.

Information

  • Day.js Version 1.9.6
  • OS: [e.g. iOS]
  • Browser Chrome/Firefox
@iamkun
Copy link
Owner

iamkun commented Nov 14, 2020

Looks ok.
https://runkit.com/embed/2p2231hs3lji

@anzap
Copy link
Author

anzap commented Nov 14, 2020

Indeed it does @iamkun. Weird that the exact same code in my app does not work the same and that it is specific for "Europe/London" only. I am most probably missing something on my side.
Will close the issue for now and check again what is happening on my end. If i get something interesting i will post it for future reference.
Thanks a lot.

@anzap anzap closed this as completed Nov 14, 2020
@anzap
Copy link
Author

anzap commented Nov 15, 2020

Ok managed to get a better view on why this is happening.
Problem seems to be timezone with locale usage. Check this link https://runkit.com/embed/gaitj4v88l8d

If i put .locale() call after .timezone() call i get the issue.
If i put .locale() call before .timezone() call i get the correct time, but output is not localized based on locale. This is easier to verify with the greek locale el.

@anzap anzap reopened this Nov 15, 2020
@AlexGrafe
Copy link

Hi @anzap, I have the same issue. It's showing the wrong time but only for UTC-ish timezones like Europe/London and Europe/Dublin.
Can this issue please be reopened? Or, @anzap, can you create a new one with your input and runkit example?

@anzap
Copy link
Author

anzap commented Nov 20, 2020

@AlexGrafe it is already reopened.
I also got a workaround to work in my case, and even though it is very ugly and most probably non-performant, it can help as a temporary solution till this is fixed. Solution is to first convert to appropriate timezone and then to string. Then parse the string and print out with appropriate locale. See last example in this link https://runkit.com/embed/izgfo00kpis9

@AlexGrafe
Copy link

Thanks @anzap. Everything works with enough duct tape I guess. Thanks for the workaround 👍

@leup
Copy link

leup commented Mar 25, 2021

You just saved my night, thanks @anzap

@simonwep
Copy link

simonwep commented Apr 20, 2021

@iamkun Any update on this one?

@daviddfm
Copy link

daviddfm commented Nov 8, 2021

This is still an issue with the latest update. This is a significant bug with the locale() function right? Basically what its doing is its marking any date that's in timezone +0 as UTC when locale() is called. At least that's what it seems to be doing... Can someone look into this?

@gl-aagostino
Copy link

Timezone seems broken for London in general. It keeps adding my timezone locale. Very frustating.

console.log(dayjs.tz(new Date(), "Europe/London").month(1).startOf('month').format())
2022-02-01T05:00:00Z

@justingolden21
Copy link

Anyone find any fix to this?

@justingolden21
Copy link

Is there anyone looking into this? Need locale and timezone to work before publishing my app, and I imagine it's not an uncommon scenario.

@bingnz
Copy link

bingnz commented Mar 22, 2022

@iamkun I think this reproduces the issue as I've seen it: https://runkit.com/bingnz/dayjs-london-bug

@tduyng
Copy link

tduyng commented Aug 29, 2022

I have same problem too.

@arpitprod
Copy link

arpitprod commented Nov 4, 2022

I have same problem. I recommended this in my company and moved here because of small size. but facing issue here also

@N-Awabdy
Copy link

N-Awabdy commented Jan 16, 2023

This problem exists for the following time zones with UTC +00:00.
[
'Africa/Abidjan', 'Africa/Accra',
'Africa/Bamako', 'Africa/Banjul',
'Africa/Bissau', 'Africa/Conakry',
'Africa/Dakar', 'Africa/Freetown',
'Africa/Lome', 'Africa/Monrovia',
'Africa/Nouakchott', 'Africa/Ouagadougou',
'Africa/Sao_Tome', 'America/Danmarkshavn',
'Antarctica/Troll', 'Atlantic/Canary',
'Atlantic/Faroe', 'Atlantic/Madeira',
'Atlantic/Reykjavik', 'Atlantic/St_Helena',
'Europe/Dublin', 'Europe/Guernsey',
'Europe/Isle_of_Man', 'Europe/Jersey',
'Europe/Lisbon', 'Europe/London'
]

@chrisjagoda
Copy link

chrisjagoda commented Nov 30, 2023

@iamkun this issue still persists in the latest release.

I've created a codesandbox reproducing the issue, it occurs when calling startOf/endOf/add/subtract with a dayjs date using a tz in GMT-0.
https://codesandbox.io/p/sandbox/new-grass-hfmczy
I provided equivalent moment-timezone examples to show the expected output.

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