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

Duration.prototype.{round,total}: Missing checks for too large date-time values #3015

Open
anba opened this issue Oct 21, 2024 · 2 comments
Open
Assignees
Labels
editorial spec-text Specification text involved

Comments

@anba
Copy link
Contributor

anba commented Oct 21, 2024

Temporal.Duration.prototype.round, steps 27.f-h:

f. Let isoDateTime be CombineISODateAndTimeRecord(plainRelativeTo.[[ISODate]], MidnightTimeRecord()).
g. Let targetDateTime be CombineISODateAndTimeRecord(targetDate, targetTime).
h. Set internalDuration to ? DifferencePlainDateTimeWithRounding(isoDateTime, targetDateTime, calendar, largestUnit, roundingIncrement, smallestUnit, roundingMode).

Temporal.Duration.prototype.total, steps 12.f-h:

f. Let isoDateTime be CombineISODateAndTimeRecord(plainRelativeTo.[[ISODate]], MidnightTimeRecord()).
g. Let targetDateTime be CombineISODateAndTimeRecord(targetDate, targetTime).
h. Let total be ? DifferencePlainDateTimeWithTotal(isoDateTime, targetDateTime, calendar, unit).

isoDateTime and targetDateTime can be be outside the valid date-time limits, which breaks assertions in DifferencePlainDateTimeWithRounding and DifferencePlainDateTimeWithTotal when calling DifferenceISODateTime.

(This is already covered by test262 tests, but probably didn't get noticed because the polyfill doesn't implement the assertion steps.)

@ptomato ptomato self-assigned this Oct 26, 2024
@ptomato ptomato added spec-text Specification text involved editorial labels Oct 26, 2024
@ptomato
Copy link
Collaborator

ptomato commented Oct 26, 2024

@anba Are you sure it already has test coverage? I tried adding the assertion steps to the polyfill, and got no new test failures. Which ones fail on your end?

@anba
Copy link
Contributor Author

anba commented Oct 28, 2024

After updating more code to match the current spec text, the assertions no longer trigger. So you're correct, this is missing test262 coverage.

Edit: Forgot to reenable the test262 tests which were failing because of this missing check. 😅

This is covered by

  • built-ins/Temporal/Duration/prototype/total/relativeto-string-limits.js
  • built-ins/Temporal/Duration/prototype/round/relativeto-string-limits.js

When the input is "-271821-04-19", this step:

Let isoDateTime be CombineISODateAndTimeRecord(plainRelativeTo.[[ISODate]], MidnightTimeRecord()).

creates a date-time valid outside the valid ISO date-time valids, because the time part is midnight.

ptomato added a commit that referenced this issue Oct 31, 2024
See #3015, which posits that these assertions are hit in existing test262
tests.
ptomato added a commit that referenced this issue Nov 1, 2024
See #3015, which posits that these assertions are hit in existing test262
tests.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
editorial spec-text Specification text involved
Projects
None yet
Development

No branches or pull requests

2 participants