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

UTC flag is set during timezone initialization if passed TZ has offset 0 (e.g. "Europe/London") #2254

Open
addiebarron opened this issue Mar 7, 2023 · 2 comments

Comments

@addiebarron
Copy link

addiebarron commented Mar 7, 2023

Describe the bug
When calling .tz with a timezone that is at utc offset 0 (such as Europe/London or Europe/Dublin), the UTC flag is set on the dayjs object. This causes date arithmetic and formatting to use UTC, rather than the particular timezone that was set, and can often cause the system timezone to leak into calculations.

An example:

const date = dayjs("2023-01-01T00:00:00Z").tz("Europe/London"); // January 1st 2023
console.log(date.utcOffset()) // 0
console.log(date.isUTC()) // true

The flag is not set when the timezone is in daylight savings, such that the offset is no longer 0:

const dateWithDST = dayjs("2023-04-01T00:00:00Z").tz("Europe/London"); // April 1st 2023, during BST
console.log(dateWithDST.utcOffset()) // 60
console.log(dateWithDST.isUTC()) // false

The culprit is this line in utcOffset that sets the flag if the passed offset is 0 and keepLocalTime is true. There's a call in the .tz method that meets this criteria, so the flag is set during timezone initialization. I propose that we should explicitly set the $u flag to false during the .tz call, unless the passed timezone is "UTC".

Expected behavior
The UTC flag shouldn't be set during timezone initialization, unless the passed timezone is "UTC".

Information

  • Day.js Version: Latest
  • OS: MacOS
  • Browser: Any
  • Time zone: America/New_York, Europe/London for testing
@adam-drozdz-ie
Copy link

Thanks for describing this. I stumbled upon this issue as well.

@ZLester
Copy link

ZLester commented Mar 27, 2024

Any progress on this issue?

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

Successfully merging a pull request may close this issue.

3 participants