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

Normative: [Alt PR] Fix intermediate value in ZonedDateTime difference #2810

Merged

Conversation

arshaw
Copy link
Contributor

@arshaw arshaw commented Mar 29, 2024

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!

Copy link

codecov bot commented Mar 29, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.46%. Comparing base (2c9979f) to head (3f30bd0).

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.
📢 Have feedback on the report? Share it here.

ptomato and others added 3 commits March 29, 2024 17:06
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.
@ptomato ptomato force-pushed the 2742-zoned-date-time-diff-intermediate branch from b82c6ab to ac1aa00 Compare March 30, 2024 01:10
Copy link
Collaborator

@ptomato ptomato left a 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.

@ptomato ptomato mentioned this pull request Mar 30, 2024
91 tasks
@ptomato ptomato merged commit a493578 into tc39:main Apr 2, 2024
9 checks passed
@ptomato ptomato deleted the 2742-zoned-date-time-diff-intermediate branch April 2, 2024 00:56
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 this pull request may close these issues.

2 participants