Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

keepLocalTime does NOT work correctly at DST #2162

Open
kawanet opened this issue Dec 15, 2022 · 1 comment
Open

keepLocalTime does NOT work correctly at DST #2162

kawanet opened this issue Dec 15, 2022 · 1 comment

Comments

@kawanet
Copy link

kawanet commented Dec 15, 2022

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.

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.

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.
@kawanet
Copy link
Author

kawanet commented Jan 11, 2023

The issue is NOT fixed yet at fix/issue2037 branch commit 231ff0f on pr #2118

FYI: Now we have yet another alternative library cdate which returns the correct results as below:
https://www.npmjs.com/package/cdate

const dayjs = require("cdate").cdate; // API COMPATIBLE

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

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

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

dayjs("2022-03-13T03:00:01Z").utc().format();
// => '2022-03-13T03:00:01+00:00'

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'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant