-
Notifications
You must be signed in to change notification settings - Fork 172
Change NudgeToCalendarUnit to use relative date when comparing durations #3172
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
base: main
Are you sure you want to change the base?
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #3172 +/- ##
==========================================
- Coverage 96.91% 96.85% -0.06%
==========================================
Files 22 22
Lines 10209 10270 +61
Branches 1839 1848 +9
==========================================
+ Hits 9894 9947 +53
- Misses 266 273 +7
- Partials 49 50 +1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
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 |
a3f6b1f to
47ad4c4
Compare
This should be fixed now. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@arshaw If you have a moment to weigh in on this, I'd really appreciate it — you probably have a deeper understanding of the NudgeCalendarUnit algorithm than I do.
60b2640 to
d910018
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, I went through the spec text and that made me revisit some things that I didn't catch before — sorry about that!
Co-authored-by: Philip Chimento <philip.chimento@gmail.com>
Co-authored-by: Philip Chimento <philip.chimento@gmail.com>
Co-authored-by: Philip Chimento <philip.chimento@gmail.com>
Co-authored-by: Philip Chimento <philip.chimento@gmail.com>
Co-authored-by: Philip Chimento <philip.chimento@gmail.com>
Co-authored-by: Philip Chimento <philip.chimento@gmail.com>
…ec (changed arguments to CompareDurations)
b241de7 to
d4d36bc
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
| // Create a separate duration that incorporates roundingIncrement | ||
| let r1, r2, startDuration, endDuration; | ||
| var didExpandCalendarUnit = false; | ||
| const compare = (d1, d2) => CompareDurations(d1, d2, undefined, undefined, calendar, isoDateTime.isoDate, unit, unit); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we not need to pass originEpochNs and timeZone into this function? (Or is it only supposed to use the PlainRelativeTo comparison by definition?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't thought of a test case where the time component matters. But there might be one.
Co-authored-by: Philip Chimento <philip.chimento@gmail.com>
See #3168