mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 16:57:46 +00:00
LibJS: Disallow negative day lengths in ZonedDateTime.protoype.round
This is a normative change in the Temporal spec.
See: 6f04074
This commit is contained in:
parent
114120852d
commit
61847b3cef
3 changed files with 34 additions and 5 deletions
|
@ -112,7 +112,35 @@ describe("errors", () => {
|
|||
zonedDateTime.round({ smallestUnit: "second" });
|
||||
}).toThrowWithMessage(
|
||||
RangeError,
|
||||
"Cannot round a ZonedDateTime in a calendar that has zero-length days"
|
||||
"Cannot round a ZonedDateTime in a calendar or time zone that has zero or negative length days"
|
||||
);
|
||||
});
|
||||
|
||||
test("time zone with negative length days", () => {
|
||||
class CustomTimeZone extends Temporal.TimeZone {
|
||||
constructor() {
|
||||
super("UTC");
|
||||
this.getPossibleInstantsForCallCount = 0;
|
||||
}
|
||||
|
||||
getPossibleInstantsFor(temporalDateTime) {
|
||||
this.getPossibleInstantsForCallCount++;
|
||||
|
||||
if (this.getPossibleInstantsForCallCount === 2) {
|
||||
return [new Temporal.Instant(-1n)];
|
||||
}
|
||||
|
||||
return super.getPossibleInstantsFor(temporalDateTime);
|
||||
}
|
||||
}
|
||||
|
||||
const zonedDateTime = new Temporal.ZonedDateTime(1n, new CustomTimeZone());
|
||||
|
||||
expect(() => {
|
||||
zonedDateTime.round({ smallestUnit: "second" });
|
||||
}).toThrowWithMessage(
|
||||
RangeError,
|
||||
"Cannot round a ZonedDateTime in a calendar or time zone that has zero or negative length days"
|
||||
);
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue