1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 12:37:44 +00:00

LibJS: Update Temporal RoundDuration AO to some spec changes

This commit effectively just does a bulk update of this function to the
spec. Since there have been so many spec changes, no specific change was
made in mind, and many FIXMEs have been left for where we are still out
of date.

These changes also appear to include a normative change to the temporal
spec which was previously resulting in timeouts for some tests, and is
now resulting in a timeout.

Furthermore, this also resolves some crashes by protecting against
division by zero, instead throwing a RangeError. This can only happen
when a custom calender is provided which returns funky values. See:

https://github.com/tc39/proposal-temporal/commit/ed85e9

Diff Tests:
    +8     -4 💀    -4 💥
This commit is contained in:
Shannon Booth 2024-01-05 13:28:39 +13:00 committed by Andrew Kaster
parent 83b84cf0bd
commit a7316d3641
4 changed files with 283 additions and 273 deletions

View file

@ -173,4 +173,24 @@ describe("errors", () => {
"A starting point is required for balancing calendar units"
);
});
test("invalid calendar throws range exception when performing round", () => {
const duration = Temporal.Duration.from({ nanoseconds: 0 });
const calendar = new (class extends Temporal.Calendar {
dateAdd(date, duration, options) {
return date;
}
})("iso8601");
expect(() => {
duration.round({
relativeTo: new Temporal.PlainDate(1997, 5, 10, calendar),
smallestUnit: "years",
});
}).toThrowWithMessage(
RangeError,
"Invalid calendar, dateAdd() function returned result implying a year is zero days long"
);
});
});