mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 08:37:46 +00:00
LibJS/Temporal: Allow annotations after YYYY-MM and MM-DD
This is a normative change in the Temporal spec.
See: 160e836
This commit is contained in:
parent
421b1eee49
commit
588dae8aa6
8 changed files with 290 additions and 136 deletions
|
@ -46,6 +46,28 @@ describe("correct behavior", () => {
|
|||
expect(plainMonthDay.monthCode).toBe("M07");
|
||||
expect(plainMonthDay.day).toBe(6);
|
||||
});
|
||||
|
||||
test("compares calendar name in month day string in lowercase", () => {
|
||||
const values = [
|
||||
"02-10[u-ca=iso8601]",
|
||||
"02-10[u-ca=isO8601]",
|
||||
"02-10[u-ca=iSo8601]",
|
||||
"02-10[u-ca=iSO8601]",
|
||||
"02-10[u-ca=Iso8601]",
|
||||
"02-10[u-ca=IsO8601]",
|
||||
"02-10[u-ca=ISo8601]",
|
||||
"02-10[u-ca=ISO8601]",
|
||||
];
|
||||
|
||||
for (const value of values) {
|
||||
expect(() => {
|
||||
Temporal.PlainMonthDay.from(value);
|
||||
}).not.toThrowWithMessage(
|
||||
RangeError,
|
||||
"MM-DD string format can only be used with the iso8601 calendar"
|
||||
);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe("errors", () => {
|
||||
|
@ -84,4 +106,33 @@ describe("errors", () => {
|
|||
Temporal.PlainMonthDay.from("−000000-01-01"); // U+2212
|
||||
}).toThrowWithMessage(RangeError, "Invalid month day string '−000000-01-01'");
|
||||
});
|
||||
|
||||
test("can only use iso8601 calendar with month day strings", () => {
|
||||
expect(() => {
|
||||
Temporal.PlainMonthDay.from("02-10[u-ca=iso8602]");
|
||||
}).toThrowWithMessage(
|
||||
RangeError,
|
||||
"MM-DD string format can only be used with the iso8601 calendar"
|
||||
);
|
||||
|
||||
expect(() => {
|
||||
Temporal.PlainMonthDay.from("02-10[u-ca=SerenityOS]");
|
||||
}).toThrowWithMessage(
|
||||
RangeError,
|
||||
"MM-DD string format can only be used with the iso8601 calendar"
|
||||
);
|
||||
});
|
||||
|
||||
test("doesn't throw non-iso8601 calendar error when using a superset format string such as DateTime", () => {
|
||||
// NOTE: This will still throw, but only because "serenity" is not a recognised calendar, not because of the string format restriction.
|
||||
try {
|
||||
Temporal.PlainMonthDay.from("2023-02-10T22:56[u-ca=serenity]");
|
||||
} catch (e) {
|
||||
expect(e).toBeInstanceOf(RangeError);
|
||||
expect(e.message).not.toBe(
|
||||
"MM-DD string format can only be used with the iso8601 calendar"
|
||||
);
|
||||
expect(e.message).toBe("Invalid calendar identifier 'serenity'");
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue