LibJS: Adjust ad-hoc clamping behavior in RegulateISODate

Instead of clamping to the limits allowed by ISOYearMonthWithinLimits,
clamp to the limits allowed by the type we are converting to (i32). This
allows some callers to then reject years outside that range.
This commit is contained in:
Timothy Flynn 2025-01-16 08:46:49 -05:00 committed by Andreas Kling
commit 59162c8155
Notes: github-actions[bot] 2025-01-17 09:09:06 +00:00
2 changed files with 13 additions and 6 deletions

View file

@ -87,10 +87,15 @@ describe("errors", () => {
});
test("relativeTo with invalid date", () => {
const duration = new Temporal.Duration(0, 0, 0, 31);
expect(() => {
const duration = new Temporal.Duration(0, 0, 0, 31);
duration.total({ unit: "minute", relativeTo: "-271821-04-19" });
}).toThrowWithMessage(RangeError, "Invalid ISO date time");
expect(() => {
const duration = new Temporal.Duration(0, 0, 0, 0, 0, 0, 0, 0, 0, 1);
const relativeTo = new Temporal.ZonedDateTime(864n * 10n ** 19n - 1n, "UTC");
duration.total({ unit: "years", relativeTo: relativeTo });
}).toThrowWithMessage(RangeError, "Invalid ISO date");
});
});