iamkun / iamkun/dayjs

It's wrong for dayjs.tz when the parameter is string with utc offset.

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

When this parameter is string without utc offset, it's right, keeping local time as same as moment.
`dayjs.tz("2023-04-19T04:00:00", 'Asia/Shanghai').format()`
output: 2023-04-19T04:00:00+08:00

But when this parameter is string with utc offset, it's wrong, neither keeping local time nor keeping the same time as same as moment.
`dayjs.tz("2023-04-19T04:00:00+04:00", 'Asia/Shanghai').format()`
output: 2023-04-19T00:00:00+08:00

**Expected behavior**

As same as moment, keeping the same time.
output: 2023-04-19T08:00:00+08:00

**Information**

- Day.js Version 1.11.9
- OS: [macOS]
- Browser [Chrome 116.0.5845.110]
- Time zone: [Asia/Shanghai]

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the reported dayjs.tz example with a string containing a UTC offset and compare it with the no-offset case and Moment's result. Trace the timezone parsing entry point and add a regression test covering the expected Asia/Shanghai output; done means the offset input preserves the expected local time.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.