iamkun / iamkun/dayjs

Manipulating after `.tz` creates incorrect value

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

When creating a timezone aware dayjs object and manipulating it, all timezone information seems to be lost and the manipulations happen on the internal representation (which is in system time).

E.g.

```
import dayjs from 'dayjs'
import utc from 'dayjs/plugin/utc'
import timezone from 'dayjs/plugin/timezone'

dayjs.extend(utc)
dayjs.extend(timezone)

dayjs.tz.setDefault('Europe/London')

console.log(dayjs.utc('2023-11-10T00:00:00Z').tz().hour(13).format())
// '2023-11-09T15:00:00Z'

```

My expectation would be that the manipulation would be timezone aware, e.g. the output should be `2023-11-10T13:00:00Z`

Strangely enough, it works fine when doing DST time, e.g:

```
console.log(dayjs.utc('2023-10-10T00:00:00Z').tz().hour(13).format())
// '2023-10-10T12:00:00Z'
```

**Information**
- Day.js Version: 1.11.10
- OS: Windows 11
- Browser: Node
- Time zone: UTC +02:00 DST

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.