1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 10:57:35 +00:00

LibJS: Disallow one day long time zone offsets

This is a normative change in the Temporal spec.
See: 9cc8b29b
This commit is contained in:
davidot 2022-10-13 23:30:51 +02:00 committed by Linus Groh
parent 1167fdb17a
commit 1b0ca52c54
7 changed files with 83 additions and 10 deletions

View file

@ -12,7 +12,7 @@ describe("correct behavior", () => {
test("custom time zone", () => {
const timeZone = {
getOffsetNanosecondsFor() {
return 86400000000000;
return 86399999999999;
},
};
const plainDate = Temporal.Now.plainDateISO("UTC");
@ -32,6 +32,20 @@ describe("correct behavior", () => {
}
}
});
test("cannot have a time zone with more than a day", () => {
[86400000000000, -86400000000000, 86400000000001, 86400000000002].forEach(offset => {
const timeZone = {
getOffsetNanosecondsFor() {
return offset;
},
};
expect(() => Temporal.Now.plainDateISO(timeZone)).toThrowWithMessage(
RangeError,
"Invalid offset nanoseconds value, must be in range -86400 * 10^9 + 1 to 86400 * 10^9 - 1"
);
});
});
});
describe("errors", () => {