`dayjs.tz()` is building dates with incorrect timezone for many cases
- Dominant language
- JavaScript
- Stars
- 48.7k
- Forks
- 2.5k
- PR merge metrics
- No merged PRs in 30d
Description
**Describe the bug**
When you try to use `dayjs.tz` factory it isn't providing the instance properly, even using some ISO formats and Date object string outputs.
Some examples using a UTC environment :
|Input|Output|Expected|
|--- |--- |--- |
| `2022-03-11T14:29:26.319Z`|2022-03-11T14:29:26-03:00|2022-03-11T11:29:26-03:00|
|`Fri, 11 Mar 2022 14:29:26 GMT`| 2022-03-11T14:29:26-03:00| 2022-03-11T11:29:26-03:00|
|`3/11/2022, 2:29:26 PM`|2022-03-11T14:29:26-03:00|2022-03-11T11:29:26-03:00|
|`2014-02-03T16:50:21Z`|2014-02-03T16:50:21-03:00|2014-02-03T13:50:21-03:00|
|`2012-02-01T13:50:21.01-03:00`|2012-02-01T16:50:21-03:00|2012-02-01T13:50:21-03:00|
|`2022-02-03T13:50:21-00:00`|2022-02-03T13:50:21-03:00|2022-02-03T10:50:21-03:00|
The behavior is odd, for the Date input it fails sometimes but also should be accepted especially the ISO format native Date outputs.
Reproducible code:
https://gist.github.com/LeonanCarvalho/35d1596dcfb701255d04b93d70df69a0
**Expected behavior**
Construct dayjs with correct timezone.
**Information**
- Day.js Version v1.10.8
- OS: [e.g. iOS]
- Browser: nodeJS v14.17.3
- Time zone: UTC (tests in UTC but also in GMT -3)
Contributor guide
Research direction
Start with the dayjs.tz factory entry point and the linked reproduction gist, then compare its handling of the listed ISO, Date, and formatted-string inputs across UTC and GMT-3 environments. Done means the factory preserves the expected instant and timezone offset for the reported cases, with regression coverage for those inputs.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- api
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100