iamkun / iamkun/dayjs

Dayjs add extra day, when convert date from utc to timezone and time range in 00:00 - 00:59

Open
#2,440 1 comment 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**
Dayjs does not correctly convert the time in the selected timezone. When my time that came from the back in utc format is converted to time in timezone and this converted time falls between 12 am and 1 am, dayjs adds a day. Complete nonsense))

Code:
```js
dayjs.utc('2023-09-04 14:45:00').tz('Australia/Lindeman').format('YYYY-MM-DDTHH:mm:ss')
```
I got:
![image](https://github.com/iamkun/dayjs/assets/23406402/e86ecc37-1be7-4d4a-83a0-2588e0412d7c)

I expect
```js
5 Sep 2023 12:45 AM (+10:00)
```
But when I add just 1 hour
```js
dayjs.utc('2023-09-04 15:45:00').tz('Australia/Lindeman').format('D MMM YYYY h:mm A (Z)'),
```
It's work correctly
![image](https://github.com/iamkun/dayjs/assets/23406402/87427f41-a50e-4fe6-b004-c7f01df1c75a)

Please deal with timezone already, the whole library works great, but I have already encountered problems with timezone.
**Expected behavior**
Correct convertation time

**Information**
- Day.js Version: 1.11.7
- OS: MacOs
- Raect-Native: 0.71.8

Contributor guide

Open the contributing guide

Research direction

Start by running the reported dayjs.utc(...).tz('Australia/Lindeman').format(...) reproduction and compare it with the expected 5 Sep 2023 12:45 AM (+10:00) result. Trace the utc, tz, and format entry points to identify where the midnight conversion diverges, then verify the original and one-hour-later cases both produce correct dates.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 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.