-
Notifications
You must be signed in to change notification settings - Fork 156
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
Normative: [Alt PR] Fix intermediate value in ZonedDateTime difference #2810
Normative: [Alt PR] Fix intermediate value in ZonedDateTime difference #2810
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #2810 +/- ##
==========================================
- Coverage 96.49% 96.46% -0.03%
==========================================
Files 23 23
Lines 12258 12310 +52
Branches 2265 2271 +6
==========================================
+ Hits 11828 11875 +47
- Misses 369 374 +5
Partials 61 61 ☔ View full report in Codecov by Sentry. |
To find the difference between two ZonedDateTimes, we first find the calendar difference between their date parts. Then we find the time difference between an intermediate ZonedDateTime value (calculated by adding the calendar parts to the first ZonedDateTime) and the second ZonedDateTime. Previously we would calculate the intermediate value by adding years, months, and weeks from the date difference, because the days were calculated as part of the time difference. This was incorrect, because the intermediate value can shift if it falls in the middle of a DST transition. However, that could be on a completely different date than would be expected, leading to surprising results like this: const duration = Temporal.Duration.from({ months: 1, days: 15, hours: 12 }); const past = Temporal.ZonedDateTime.from('2024-02-10T02:00[America/New_York]'); const future = past.add(duration); duration // => 1 month, 15 days, 12 hours past.until(future, { largestUnit: 'months' }) // => 1 month, 15 days, 11 hours This result would occur because of a DST change on 2024-03-10T02:00, unrelated to either the start date of 2024-02-10 or the end date of 2024-03-25. With this change, the intermediate value occurs on 2024-03-25T02:00 and would only shift if that was when the DST change occurred.
Fixes bug mentioned here: tc39#2760 (comment)
b82c6ab
to
ac1aa00
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks very much for doing this. I've added the spec text.
Tests are consolidated in tc39/test262#4012 now. I added a couple of extra regression tests for the 1 month / 30 days 23 hours bug that this latest update fixed.
On Monday, unless anyone hollers for more time, I'll plan to merge the test262 tests, update the test262 ref in this PR, and then merge this one.
This PR supersedes #2760
@ptomato
Test262 branch with updated tests:
https://github.com/fullcalendar/test262/tree/temporal-2760
Diff from main: tc39/test262@main...fullcalendar:test262:temporal-2760
Diff from previous: ptomato/test262@temporal-2760...fullcalendar:test262:temporal-2760
I have not updated the spec text. I'd really appreciate some help with that.
Plz lmk if questions. Thanks!