You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
The text was updated successfully, but these errors were encountered:
Describe the bug
When calling
.tz
with a timezone that is at utc offset 0 (such asEurope/London
orEurope/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:
The flag is not set when the timezone is in daylight savings, such that the offset is no longer 0:
The culprit is this line in
utcOffset
that sets the flag if the passed offset is0
andkeepLocalTime
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
America/New_York
,Europe/London
for testingThe text was updated successfully, but these errors were encountered: