tc39 / proposal-temporal

Provides standard objects and functions for working with dates and times.
https://tc39.es/proposal-temporal/docs/
Other
3.33k stars 152 forks source link

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

Open anba opened 1 week ago

anba commented 1 week ago

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 commented 4 days ago

@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 commented 2 days ago

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

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.