Skip to content

Thorough Duration rounding tests (without relativeTo)#3287

Merged
ptomato merged 4 commits intomainfrom
duration-rounding-tests
Mar 2, 2026
Merged

Thorough Duration rounding tests (without relativeTo)#3287
ptomato merged 4 commits intomainfrom
duration-rounding-tests

Conversation

@ptomato
Copy link
Copy Markdown
Collaborator

@ptomato ptomato commented Feb 28, 2026

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.

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.

@ptomato ptomato requested a review from Ms2ger February 28, 2026 02:42
@ptomato
Copy link
Copy Markdown
Collaborator Author

ptomato commented Feb 28, 2026

Specific tests for the cases that I caught with these tests: tc39/test262#4960

@codecov
Copy link
Copy Markdown

codecov bot commented Feb 28, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.40%. Comparing base (465a098) to head (fb489b5).
⚠️ Report is 4 commits behind head on main.

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

ptomato added 3 commits March 2, 2026 12:14
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.
@ptomato ptomato force-pushed the duration-rounding-tests branch from c5c7128 to aaf2277 Compare March 2, 2026 20:15
@ptomato ptomato force-pushed the duration-rounding-tests branch from aaf2277 to fb489b5 Compare March 2, 2026 20:39
@ptomato ptomato merged commit be4e0ef into main Mar 2, 2026
10 checks passed
@ptomato ptomato deleted the duration-rounding-tests branch March 2, 2026 20:58
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