iamkun / iamkun/dayjs

Wrong timezone conversion when tz != browser tz

Open
#2,580 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
48.7k
Forks
2.5k
PR merge metrics
No merged PRs in 30d

Description

Hello,

On our product we need to display dates in customer timezone, I am myself in `Europe/Paris` tz where currently it is GMT+1 and will be GMT+2 on March 31, while the customer is in `Asia/Tokyo`.

I have an issue when formatting those two dates in this format `HH:mm` in the customer timezone:

```
Sat Mar 30 2024 18:00:00 GMT+0100 (Central European Standard Time)
Sat Mar 30 2024 19:00:00 GMT+0100 (Central European Standard Time)

dayjs(date).tz('Asia/Tokyo').format('HH:mm')
```

They both returned me `03:00`, this is wrong to us, we should have `02:00` and `03:00`. We think this is due to the DST change occurring in `Europe/Paris` tz the 31 March at 2AM.

Here is a stackblitz reproducing this (only visible if you're in the same tz as me, but for sure it could be reproduced with other dates for other tz having dst) https://stackblitz.com/edit/dayjs-playground-6uuyuv?file=index.js

For information using Luxon it works fine

**Information**
- Day.js Version 1.11.10
- OS: Windows 10 - Browser: Chrome 121
- Time zone: GMT+1 (Paris)

Contributor guide

Open the contributing guide

Research direction

Start with the linked StackBlitz reproduction in index.js and run it in the reported Europe/Paris timezone. Compare the two Asia/Tokyo results with the expected 02:00 and 03:00 values; done means both dates format correctly across the DST boundary.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.