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

Relax error checking requiring exclusive end in NudgeToCalendarUnit #2924

Closed

Conversation

arshaw
Copy link
Contributor

@arshaw arshaw commented Jul 25, 2024

Fix for #2919

Looks like the sanity checking was a little too aggressive. Was asserting a range with an exclusive end. Should be inclusive end instead. To see what I mean, I'll breaking down the operations from #2919 ...

// original recreation
const dur = Temporal.Duration.from({ months: 11 });
const relativeTo = Temporal.PlainDate.from("2023-05-31");
dur.round({ relativeTo, smallestUnit: "months", roundingMode: "ceil" });

// granular operations
const durBalanced = relativeTo.until(relativeTo.add(dur), { largestUnit: 'months' }); // P10M30D
const months0 = 10 // because we trunc P10M30D down to 10 months
const months1 = 11 // because 10 plus roundingInc (1) is 11 months
const windowPd0 = relativeTo.add({ months: months0 }) // 2024-03-31
const windowPd1 = relativeTo.add({ months: months1 }) // 2024-04-30
const destPd = relativeTo.add(dur) // 2024-04-30

/*
You then must determine how far `destPd` is between `windowPd0` <-> `windowPd1`
As you can see, `destPd` === `windowPd1`, which should be allowed
*/

Copy link

codecov bot commented Jul 25, 2024

Codecov Report

Attention: Patch coverage is 66.66667% with 1 line in your changes missing coverage. Please review.

Project coverage is 96.26%. Comparing base (82ad54f) to head (c0bd886).
Report is 54 commits behind head on main.

Files Patch % Lines
polyfill/lib/ecmascript.mjs 66.66% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2924      +/-   ##
==========================================
- Coverage   96.51%   96.26%   -0.26%     
==========================================
  Files          23       23              
  Lines       12432    12073     -359     
  Branches     2258     2206      -52     
==========================================
- Hits        11999    11622     -377     
- Misses        374      387      +13     
- Partials       59       64       +5     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@arshaw
Copy link
Contributor Author

arshaw commented Aug 14, 2024

Updated per #2919 (comment)
CC @ptomato and @anba

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 @arshaw, I'll add the corresponding spec text to this branch. @anba, your input will be appreciated before we merge this.

@ptomato ptomato force-pushed the 2919-duration-rounding-false-error branch from 89d170a to d8f28b0 Compare August 14, 2024 16:38
@ptomato
Copy link
Collaborator

ptomato commented Aug 14, 2024

I wrote a test case that passes with this branch and fails on main: tc39/test262#4196

Copy link
Contributor

@anba anba left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't test if the proposed changes will always compute the expected results until I've updated SpiderMonkey's Temporal implementation to use the current DifferenceISODate. This won't happen before finishing the changes for #2925, so it'll probably take some time.

spec/duration.html Outdated Show resolved Hide resolved
spec/duration.html Outdated Show resolved Hide resolved
@ptomato ptomato force-pushed the 2919-duration-rounding-false-error branch from d8f28b0 to e3eb821 Compare August 21, 2024 19:23
@ptomato
Copy link
Collaborator

ptomato commented Aug 21, 2024

Thanks for taking a look. I've changed the assertion back to an exception for the time being, though, as you say, it may need to change back to an assertion after #2925 lands. We should land this only after #2925, I think.

@ptomato
Copy link
Collaborator

ptomato commented Sep 5, 2024

I'm going to roll this one into #2925 because test262 tests have already been merged for it. That also allows dropping the "Editorial: Downgrade assertion back to exception" commit, because without custom calendars that invariant can no longer be broken.

@ptomato
Copy link
Collaborator

ptomato commented Sep 5, 2024

Merged as part of #2925.

@ptomato ptomato closed this Sep 5, 2024
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.

3 participants