tc39 / proposal-temporal

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

DifferenceZonedDateTime: CreateNormalizedDurationRecord is fallible #2779

Closed anba closed 2 months ago

anba commented 9 months ago

DifferenceZonedDateTime, step 11:

Return ! CreateNormalizedDurationRecord(dateDifference.[[Years]], dateDifference.[[Months]], dateDifference.[[Weeks]], result.[[Days]], result.[[Remainder]]).

The CreateNormalizedDurationRecord call is fallible. Test case:

const oneDay = BigInt(Temporal.Duration.from("P1D").total("nanoseconds"));

let cal = new class extends Temporal.Calendar {
  dateUntil(one, two, options) {
    return super.dateUntil(one, two, options).negated();
  }
}("iso8601");

let zdt1 = new Temporal.ZonedDateTime(0n, "UTC", cal);
let zdt2 = new Temporal.ZonedDateTime(50n * oneDay, "UTC", cal);

zdt1.until(zdt2, {
  largestUnit: "weeks",
});
ptomato commented 9 months ago

Thanks for figuring this out. Have you looked at #2760 yet? This may be obsolete once it lands.

anba commented 8 months ago

Have you looked at #2760 yet? This may be obsolete once it lands.

No, I haven't yet looked at that PR.

ptomato commented 2 months ago

Fixed by #2760.