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

Improve test coverage for AdjustRoundedDurationDays #2814

Open
arshaw opened this issue Mar 31, 2024 · 0 comments
Open

Improve test coverage for AdjustRoundedDurationDays #2814

arshaw opened this issue Mar 31, 2024 · 0 comments

Comments

@arshaw
Copy link
Contributor

arshaw commented Mar 31, 2024

The AdjustRoundedDurationDays function has special behavior for balancing-up time units during a ZDT days:

// There's one more round of rounding possible: if relativeTo is a
// ZonedDateTime, the time units could have rounded up into enough hours
// to exceed the day length. If this happens, grow the date part by a
// single day and re-run exact time rounding on the smaller remainder. DO
// NOT RECURSE, because once the extra hours are sucked up into the date
// duration, there's no way for another full day to come from the next
// round of rounding. And if it were possible (e.g. contrived calendar
// with 30-minute-long "days") then it'd risk an infinite loop.

FullCalendar's temporal-polyfill has an incorrect implementation of this not caught by tests. It'd be great to improve test coverage.

dur = Temporal.Duration.from({ hours: 13 })
zdt = Temporal.ZonedDateTime.from('2024-03-10T00:00:00[America/New_York]') // a 23-hour day
roundedDur = dur.round({
  relativeTo: zdt,
  largestUnit: 'years',
  smallestUnit: 'hours',
  roundingIncrement: 12,
  roundingMode: 'ceil'
})
// EXPECTED: { days: 1, hours: 12 }

Things work fine in the reference implementation.

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

No branches or pull requests

1 participant