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

LibJS: Require 'T' prefix for ambiguous time-only strings

This is a normative change in the Temporal spec.

See: 514ede3
This commit is contained in:
Linus Groh 2021-12-22 22:44:46 +01:00
parent a73c71e877
commit 3ab1c52e2b
4 changed files with 443 additions and 29 deletions

View file

@ -64,4 +64,26 @@ describe("errors", () => {
"Invalid time string '2021-07-06T23:42:01Z': must not contain a UTC designator"
);
});
test("ambiguous string must contain a time designator", () => {
const values = [
// YYYY-MM or HHMM-UU
"2021-12",
// MMDD or HHMM
"1214",
"0229",
"1130",
// MM-DD or HH-UU
"12-14",
// YYYYMM or HHMMSS
"202112",
];
for (const value of values) {
expect(() => {
Temporal.PlainTime.from(value);
}).toThrowWithMessage(RangeError, `Invalid time string '${value}'`);
// Doesn't throw
Temporal.PlainTime.from(`T${value}`);
}
});
});