Thorough Duration rounding tests (without relativeTo)#3287
Merged
Conversation
Collaborator
Author
|
Specific tests for the cases that I caught with these tests: tc39/test262#4960 |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #3287 +/- ##
==========================================
+ Coverage 97.39% 97.40% +0.01%
==========================================
Files 22 22
Lines 10766 10771 +5
Branches 1865 1866 +1
==========================================
+ Hits 10486 10492 +6
Misses 258 258
+ Partials 22 21 -1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Ms2ger
approved these changes
Mar 2, 2026
With a sufficiently large rounding increment, this calculation may overflow the TimeDuration limit. However, we don't need to do this calculation at all unless we're being called from the total() method, and the rounding increment will only ever be 1 when called from total(). So if the rounding increment is not 1, we can skip it.
This was triggered by a sufficiently large rounding increment.
Snapshot tests for the Temporal.Duration.p.round() method, covering hundreds of thousands of combinations of time-only duration, largest unit of days or smaller, smallest unit of days or smaller, rounding increment, and rounding mode. Also verifies the invariant that for these durations, the presence or absence of relativeTo doesn't matter for the result, except if the duration itself or the nudge window would be unable to be added to the relativeTo, or in the case of halfEven rounding mode.
c5c7128 to
aaf2277
Compare
aaf2277 to
fb489b5
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Snapshot tests for the Temporal.Duration.p.round() method, covering hundreds of thousands of combinations of time-only duration, largest unit of days or smaller, smallest unit of days or smaller, rounding increment, and rounding mode.
Also verifies the invariant that for these durations, the presence or absence of
relativeTodoesn't matter for the result, except if the duration itself or the nudge window would be unable to be added to therelativeTo, or in the case ofhalfEvenrounding mode.Also includes 2 commits fixing bugs in the reference code, found with these snapshot tests. One floating-point overflow that should've been calculated with bigints, and one overflow of TimeDuration - turns out we can skip that calculation in the cases where TimeDuration would overflow. (I checked, neither of these are spec bugs.)
I hope to follow this up next week with another PR with snapshot tests for
relativeTo, but the snapshot file is too large and I'll need to figure out a way to shrink it.