iamkun / iamkun/dayjs

Invalid format after timezone is changed

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

**Describe the bug**
```js
let dt = dayjs('2024-09-18').tz('UTC', true).startOf('day');

for(let i = 0; i < 4; i++) {
console.log(dt.format('YYYY-MM-DD'), dt.toDate());
dt = dt.add(1, 'day')
}
```
Result:
2024-09-18 2024-09-18T00:00:00.000Z
2024-09-18 2024-09-19T00:00:00.000Z << Wrong formatted date
2024-09-19 2024-09-20T00:00:00.000Z << Wrong formatted date
2024-09-20 2024-09-21T00:00:00.000Z << Wrong formatted date

My current time is 01:00:00! It seems format doesn't count timezone

**Information**
- Day.js Version 1.11.13
- OS: Ubuntu (docker)
- Browser: - (on a server)
- Time zone: [e.g. GMT+3:00]

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the timezone example with Day.js 1.11.13, focusing on tz(), startOf(), add(), format(), and toDate(). Trace how the timezone-adjusted value is updated across the loop; done when the formatted date remains consistent with the returned Date for each day, with a regression test covering the example.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
tooling
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.