iamkun / iamkun/dayjs

day.tz(...).startOf('day') call returns an incorrect time sometimes

Open
#2,553 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**
When the browser is in Asia/Shanghai timezone, the following codes will get the absolute time presents for `2024-04-07 01:00:00` in Australia/Canberra, it's incorrect obviously.
```javascript
const timeZoneId = 'Australia/Canberra';
dayjs
.tz(
// 1712487599000,
dayjs.tz("2024-04-07 20:59:59", timeZoneId).valueOf(),
timeZoneId,
)
.startOf('day');
```

**Expected behavior**
`2024-04-07 00:00:00` in Australia/Canberra should be gained.

**Code sandbox**
https://codesandbox.io/p/devbox/dayjs-tz-bug-demo-mr327z?file=%2Fsrc%2FApp.js

If you can not reappear the issue, try to switch to another location and then switch back to Asia/Shanghai and finally refresh your browser.

**Supplementary instruction**
Australia/Canberra observes day light saving time. It will change DST to non-DST in 2024-04-07. So there're 25 hours in that day.

**Information**
- Day.js Version: 1.11.10
- OS: Mac OS 13.4 (22F66)
- Chip: Apple M2 Pro
- Browser: Chrome 120.0.6099.216 (Official Build) (arm64)
- Time zone: Asia/Shanghai

image

Contributor guide

Open the contributing guide

Research direction

Start with the linked CodeSandbox and reproduce dayjs.tz(...).startOf('day') using Asia/Shanghai as the browser zone and Australia/Canberra as the target. Trace the timezone and startOf behavior around the 2024-04-07 DST transition; done means the result represents 2024-04-07 00:00:00 in Australia/Canberra.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.