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

Closed
arshaw opened this issue Mar 31, 2024 · 3 comments
Closed

Improve test coverage for AdjustRoundedDurationDays #2814

arshaw opened this issue Mar 31, 2024 · 3 comments
Labels
Milestone

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.

@catamorphism
Copy link
Contributor

catamorphism commented Nov 5, 2024

I'm working on this, but I think it should wait until after #3036 lands; otherwise things get too confusing. (Never mind, it's fine.)

@ptomato
Copy link
Collaborator

ptomato commented Nov 7, 2024

I wonder if this case should've been included in #2916 and therefore disallowed. But on the other hand, with rounding vs 23-hour days it doesn't seem to be as confusing as the cases in #2916.

@ptomato
Copy link
Collaborator

ptomato commented Nov 7, 2024

Coverage added in test262.

@ptomato ptomato closed this as completed Nov 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants