iamkun / iamkun/dayjs

Inconsistent TZ Behavior Around UTC

Open
#1,606 1 comment 5 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
48.7k
Forks
2.5k
PR merge metrics
No merged PRs in 30d

Description

**Setup**
```js
import dayjs from 'dayjs';
import utc from 'dayjs/plugin/utc';
import timezone from 'dayjs/plugin/timezone';

dayjs.extend(utc);
dayjs.extend(timezone);
```

**Describe the bug**
`dayjs('2021-08-14').tz('Etc/GMT').hour(12).unix()` => `1628924400`
`dayjs('2021-08-14').tz('UTC').hour(12).unix()` => `1628924400`

`1628924400` is `GMT: Saturday, August 14, 2021 7:00:00 AM`

**Expected behavior**
`1628942400` is the expected value (`GMT: Saturday, August 14, 2021 12:00:00 PM`)

Time zones around UTC behave as expected:
`dayjs('2021-08-14').tz('Etc/GMT-1').hour(12).unix()` => `1628938800` (`GMT: Saturday, August 14, 2021 11:00:00 AM`)
`dayjs('2021-08-14').tz('Etc/GMT+1').hour(12).unix()` => `1628946000` (`GMT: Saturday, August 14, 2021 1:00:00 PM`)

It seems like something special is happening behind the scenes when the timezone is at UTC vs. other time zones. It's like it uses my local time zone when using `.unix` in the UTC case but not the others.

**Information**
- Day.js Version `v1.10.6`
- OS: macOS
- Node.js `v16.5.0`
- Time zone: US Central (currently UTC−05:00)

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.