iamkun / iamkun/dayjs

keepLocalTime does NOT work correctly at DST

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

`keepLocalTime` flag does NOT work correctly at `.tz("America/Los_Angeles", true)`. See No.5 below.
Note that, in LA, March 13 was the day to switch from STD to DST at 2022.

```js
const dayjs = require("dayjs");
dayjs.extend(require("dayjs/plugin/utc"));
dayjs.extend(require("dayjs/plugin/timezone"));

// #1 - OK
dayjs("2022-03-13T01:59:59Z").utc().format();
// => '2022-03-13T01:59:59Z'

// #2 - OK
dayjs("2022-03-13T01:59:59Z").utc().tz("America/Los_Angeles", true).format();
// => '2022-03-13T01:59:59-08:00'

// #3 - OK
dayjs("2022-03-13T01:59:59Z").utc().tz("America/Los_Angeles", true).tz("America/Los_Angeles").format();
// => '2022-03-13T01:59:59-08:00'

// #4 - OK. It's 3 o'clock.
dayjs("2022-03-13T03:00:01Z").utc().format();
// => '2022-03-13T03:00:01Z'

// #5 - NG. It's 4 o'clock NOT 3. keepLocalTime does not work. Incorrect time zone offset.
dayjs("2022-03-13T03:00:01Z").utc().tz("America/Los_Angeles", true).format();
// actual => '2022-03-13T04:00:01-08:00'
// expected => '2022-03-13T03:00:01-07:00'

// #6 - NG. It's 5 o'clock. Time zone offset is correct.
dayjs("2022-03-13T03:00:01Z").utc().tz("America/Los_Angeles", true).tz("America/Los_Angeles").format();
// actual => '2022-03-13T05:00:01-07:00'
// expected => '2022-03-13T03:00:01-07:00'
```

**Expected behavior**

`keepLocalTime` should work. Correct time zone offset `-07:00`.

```js
dayjs("2022-03-13T03:00:01Z").utc().tz("America/Los_Angeles", true).format();
// => '2022-03-13T03:00:01-07:00'

dayjs("2022-03-13T03:00:01Z").utc().tz("America/Los_Angeles", true).tz("America/Los_Angeles").format();
// => '2022-03-13T03:00:01-07:00'
```

**Information**
- Day.js Version: 1.11.7
- OS: macOS
- Browser: node v18
- Time zone: `America/Los_Angeles` and any other DST switching areas.

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.