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

Multiple calls to utcOffset cause formatted time to drift when time is across Daylight Savings Time boundary #1534

Open
zzzzBov opened this issue Jun 16, 2021 · 0 comments

Comments

@zzzzBov
Copy link

zzzzBov commented Jun 16, 2021

Describe the bug
Assigning the same utcOffset multiple times causes the formatted time to shift when the time is across a Daylight Savings Time boundary.

The following code demonstrates the issue:

const dayjs = require("dayjs");
const utc = require("dayjs/plugin/utc");

dayjs.extend(utc);

console.table({
  // March 13th 2021 at 12:00PM -04:00 is during Standard Time

  // Force a specific timezone offset.
  "13th 1xUTC offset": dayjs("2021-03-13T16:00:00.000Z")
    .utcOffset(-4)
    .format("h:mm A"),
  // Force a specific timezone offset multiple times. This should have no
  // effect, but unfortunately the formatted time shifts.
  "13th 2xUTC offset": dayjs("2021-03-13T16:00:00.000Z")
    .utcOffset(-4)
    .utcOffset(-4)
    .format("h:mm A"),
  // Force a specific timezone offset multiple times but reset in-between.
  // This has no effect and appears to be an adequte work-around.
  "13th Change UTC offset": dayjs("2021-03-13T16:00:00.000Z")
    .utcOffset(-4)
    .utcOffset(0)
    .utcOffset(-4)
    .format("h:mm A"),

  // March 14th, 2021 at 12:00PM -04:00 is during Daylight Savings Time

  // Force a specific timezone offset.
  "14th 1xUTC offset": dayjs("2021-03-14T16:00:00.000Z")
    .utcOffset(-4)
    .format("h:mm A"),
  // Force a specific timezone offset multiple times. This should have no
  // effect, but it's likely that the time would shift if tests are run during
  // standard time.
  "14th 2xUTC offset": dayjs("2021-03-14T16:00:00.000Z")
    .utcOffset(-4)
    .utcOffset(-4)
    .format("h:mm A"),
  // Force a specific timezone offset multiple times but reset in-between.
  // This has no effect and appears to be an adequte work-around.
  "14th Change UTC offset": dayjs("2021-03-14T16:00:00.000Z")
    .utcOffset(-4)
    .utcOffset(0)
    .utcOffset(-4)
    .format("h:mm A"),
});

Expected behavior
The output table ought to return "12:00 PM" for all cases.

Actual behavior
The "13th 2xUTC offset" value produces "11:00 AM" during DST.

Information

  • Day.js Version v1.10.5
  • OS: Windows
  • Browser: Chrome, Node
  • Time zone: All
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