iamkun / iamkun/dayjs

Dayjs returning wrong offsets when local browser time zone is changed

Open
#2,374 2 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

**Describe the bug**
I'm seeing some strange behavior that I don't really understand what is happening. I'm using Dayjs as a library and want to display user data based on the time zone that the user has specified on my app. In the below example, the user may be in `America/Chicago`, but the user specified `Africa/Accra` as their time zone, so all their data in my app will be in the `Africa/Accra` time zone.

Great, I simply use:

`dayjs.tz(1234567890, "Africa/Accra")`

Afterward, I can always do something like `dayjs.tz(1234567890, "Africa/Accra").offsetName()` to get the name of the time zone (in this case `Africa/Accra`, which is a `GMT` or `GMT+0` offset.

However, when I install a Chrome plugin to change my Chrome browser time zone (for example, https://chrome.google.com/webstore/detail/change-timezone-for-googl/cejckpjfigehbeecbbfhangbknpidcnh), and change to any time zone from the list, dayjs returns wrong time zone offset names.

It returns exclusively time zone offsets of the time zone specified by the browsere plugin. It completely ignores the time zone that I specify in the dayjs object.

For example, if I use that plugin to change the browser time zone to `America/Nassau`, `dayjs.tz(1234567890, "Africa/Accra").offsetName()` will return `GMT+7`, which is wrong. Refreshing the page to re-run the offsetName method will return a different offset name every time, so it's not even consistent.

I was under the assumption that dayjs will return the time zone offset that is inputted in the dayjs.tz function...which it always does. However, when I use this browser plugin, it doesn't and I do not know why.

**Expected behavior**
The time zone offset name and all other time zone values should return the value of the time zone provided to the dayjs object, no matter what a user does on the browser.

**Information**
- Day.js Version 1.11.8
- OS: Windows 10
- Browser Version 114.0.5735.199 (Official Build) (64-bit)
- Time zone: variable

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the browser-time-zone change and tracing the timezone plugin entry point used by dayjs.tz(...).offsetName(). No repository file or test is named in the issue. Done means the specified Africa/Accra zone determines the offset name and related timezone values consistently, regardless of the browser's configured zone.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
internationalization
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.