dayjs icon indicating copy to clipboard operation
dayjs copied to clipboard

Issue with converting to Europe/London timezone

Open anzap opened this issue 4 years ago • 17 comments

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

anzap avatar Nov 14 '20 11:11 anzap

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

iamkun avatar Nov 14 '20 16:11 iamkun

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 avatar Nov 14 '20 18:11 anzap

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 avatar Nov 15 '20 15:11 anzap

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?

AlexGrafe avatar Nov 19 '20 23:11 AlexGrafe

@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

anzap avatar Nov 20 '20 18:11 anzap

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

AlexGrafe avatar Nov 21 '20 08:11 AlexGrafe

You just saved my night, thanks @anzap

leup avatar Mar 25 '21 23:03 leup

@iamkun Any update on this one?

simonwep avatar Apr 20 '21 06:04 simonwep

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?

daviddfm avatar Nov 08 '21 16:11 daviddfm

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

gl-aagostino avatar Feb 16 '22 18:02 gl-aagostino

Anyone find any fix to this?

justingolden21 avatar Mar 04 '22 00:03 justingolden21

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.

justingolden21 avatar Mar 06 '22 20:03 justingolden21

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

bingnz avatar Mar 22 '22 12:03 bingnz

I have same problem too.

tduyng avatar Aug 29 '22 15:08 tduyng

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

arpitprod avatar Nov 04 '22 15:11 arpitprod

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' ]

N-Awabdy avatar Jan 16 '23 14:01 N-Awabdy

@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.

chrisjagoda avatar Nov 30 '23 23:11 chrisjagoda