8000 Date pipe calculation with timezone offset is wrong at Daylight Saving Time transition · Issue #57916 · angular/angular · GitHub
[go: up one dir, main page]

Skip to content

Date pipe calculation with timezone offset is wrong at Daylight Saving Time transition #57916

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

Closed
cfinlinson-incomm opened this issue Sep 22, 2024 · 4 comments

Comments

@cfinlinson-incomm
Copy link
cfinlinson-incomm commented Sep 22, 2024

Which @angular/* package(s) are the source of the bug?

common

Is this a regression?

No

Description

When using the date pipe to transform an ISO-8601 date string, the calculation is affected by Daylight Saving Time in my system time zone, even if I specify an offset.

For example, I am in the "America/Denver" timezone, which observes Daylight Saving Time. I want to display a date in the "America/Phoenix" timezone. During standard time, both time zones, have the same offset, -07:00. But during Daylight Saving Time, "America/Denver" is -06:00 and "America/Phoenix" is -07:00. Using the date pipe to transform a date-time string that occurs exactly at the time when Daylight Saving Time begins, "2024-03-10T02:00:00.000", with the offset specified as -07:00 (to represent Phoenix time), I should see the time as "02:00:00". However, because my system clock is in "America/Denver" time zone, it always skips the time forward to "03:00:00".

I should be able to display a date with an offset, without my system time zone affecting the calculation.

See the linked StackBlitz for examples of date strings that should be formatted correctly but are being affected by Daylight Saving Time calculations.

Please provide a link to a minimal reproduction of the bug

https://stackblitz.com/edit/stackblitz-starters-dtm85s

Please provide the exception or error you saw

A date string of "2024-03-10T02:00:00.000" is being displayed as "2024-03-10T03:00:00.000", even if I specify an offset of "-07:00" (or whatever the offset is on the system clock where this is being reproduced).

Please provide the environment you discovered this bug in (run ng version)

Browser: Google Chrome

Angular CLI: 18.2.3
Node: 22.6.0
Package Manager: npm 10.8.2
OS: darwin arm64

Angular: 18.2.3
... animations, cdk, cli, common, compiler, compiler-cli, core
... forms, language-service, material, material-moment-adapter
... platform-browser, platform-browser-dynamic, router

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1802.3
@angular-devkit/build-angular   18.2.3
@angular-devkit/core            18.2.3
@angular-devkit/schematics      18.2.3
@angular/flex-layout            15.0.0-beta.42
@schematics/angular             18.2.3
rxjs                            7.8.1
typescript                      5.4.5
zone.js                         0.14.10

Anything else?

I stepped through the date pipe code, and I believe this line is the cause:

date.setMinutes(date.getMinutes() + minutes);

When date.setMinutes is called, if the resulting date lands between hours 02:00 and 03:00 on March 10, the time is coerced to be on or after 03:00. The reason (as far as I can tell) is that hour doesn't exist, since Daylight Saving Time would kick in and jump everything forward an hour.

Again, this makes no sense when you are trying to display a date in a time zone that does not observe Daylight Saving Time. I should be able to display a date with an arbitrary offset and not have it be affected by my system clock's time zone.

I believe this issue could be resolved by this one: #48279.

@JeanMeche
Copy link
Member

This issue would indeed be adressed by supporting IANA timezones, absolute offsets are not ideal in situation like the one you described.

We intend to address this issue/feature by providing an Intl based implementation to our i18n-subsystem. See #55283.

I'll close it as a duplicate of #48279.

@JeanMeche JeanMeche closed this as not planned Won't fix, can't repro, duplicate, stale Sep 22, 2024
@cfinlinson-incomm
Copy link
Author

@JeanMeche do you have an estimate on when #55283 will be merged? Just wondering if I need to come up with a workaround for now.

@JeanMeche
Copy link
Member

I hope that we can ship it with v19, mid November.

@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Oct 25, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None 3B41 yet
Projects
None yet
Development

No branches or pull requests

2 participants
0