Skip to content

Conversation

@catamorphism
Copy link
Contributor

See #3168

@codecov
Copy link

codecov bot commented Oct 28, 2025

Codecov Report

❌ Patch coverage is 82.35294% with 12 lines in your changes missing coverage. Please review.
✅ Project coverage is 96.79%. Comparing base (c8571ae) to head (47ad4c4).
⚠️ Report is 14 commits behind head on main.

Files with missing lines Patch % Lines
polyfill/lib/ecmascript.mjs 80.00% 11 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3172      +/-   ##
==========================================
- Coverage   96.91%   96.79%   -0.12%     
==========================================
  Files          22       22              
  Lines       10209    10247      +38     
  Branches     1839     1845       +6     
==========================================
+ Hits         9894     9919      +25     
- Misses        266      278      +12     
- Partials       49       50       +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
Copy link
Collaborator

ptomato commented Oct 28, 2025

So I haven't sat down yet to think through the code but I did run this on my in-progress snapshot tests. It definitely fixes the assertion failures, and the results seem correct:

Temporal.Duration.from({ months: 1, hours: 10 }).round({ smallestUnit: 'months', roundingMode: 'expand', relativeTo: '2020-01-31' })
  // old: assertion failure
  // new: P2M (seems correct)

Temporal.Duration.from({ years: 2345, hours: 12 }).round({ smallestUnit: 'years', roundingMode: 'expand', relativeTo: '2020-02-29' })
  // old: assertion failure
  // new: P2346Y (seems correct)

Temporal.Duration.from({ months: 1, hours: 10 }).total({ unit: 'months', relativeTo: '2020-01-31' })
  // old: assertion failure
  // new: 1.0134408602150538
  // (seems correct: the bounding box is from 2020-02-29T00:00 (relativeTo + 1 month)
  // to 2020-03-31T00:00 (relativeTo + 2 months), which is 744 hours, and the result is
  // the floating point approximation of 1+10/744)

(Additionally, these cases produced wrong answers in a build of the existing code with assertions disabled)

But I also found one case that seems to produce a wrong result where the old code was correct:

Temporal.Duration.from({ years: 1 }).round({ smallestUnit: 'months', relativeTo: '2020-02-29' })
  // old: P1Y
  // new: P12M (seems wrong, should balance back up to the implicit largestUnit in the original duration)

(I'd have liked to push an in-progress branch with the snapshot tests but currently the testing space is too large, and the snapshots run afoul of GitHub's file size limit. So here's what I've currently got, without snapshots: bd34a53 To recreate the snapshots, run node polyfill/test/thorough/durationrounding.mjs -u and node polyfill/test/thorough/durationtotal.mjs -u, then rebase your fixes on top of it and run them again without -u to compare)

@catamorphism
Copy link
Contributor Author

But I also found one case that seems to produce a wrong result where the old code was correct:

This should be fixed now.

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