mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 10:07:44 +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
|
@ -72,6 +72,28 @@ describe("correct behavior", () => {
|
|||
expect(plainYearMonth.monthsInYear).toBe(12);
|
||||
expect(plainYearMonth.inLeapYear).toBeFalse();
|
||||
});
|
||||
|
||||
test("compares calendar name in year month string in lowercase", () => {
|
||||
const values = [
|
||||
"2023-02[u-ca=iso8601]",
|
||||
"2023-02[u-ca=isO8601]",
|
||||
"2023-02[u-ca=iSo8601]",
|
||||
"2023-02[u-ca=iSO8601]",
|
||||
"2023-02[u-ca=Iso8601]",
|
||||
"2023-02[u-ca=IsO8601]",
|
||||
"2023-02[u-ca=ISo8601]",
|
||||
"2023-02[u-ca=ISO8601]",
|
||||
];
|
||||
|
||||
for (const value of values) {
|
||||
expect(() => {
|
||||
Temporal.PlainYearMonth.from(value);
|
||||
}).not.toThrowWithMessage(
|
||||
RangeError,
|
||||
"YYYY-MM string format can only be used with the iso8601 calendar"
|
||||
);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe("errors", () => {
|
||||
|
@ -110,4 +132,33 @@ describe("errors", () => {
|
|||
Temporal.PlainYearMonth.from("−000000-01"); // U+2212
|
||||
}).toThrowWithMessage(RangeError, "Invalid year month string '−000000-01'");
|
||||
});
|
||||
|
||||
test("can only use iso8601 calendar with year month strings", () => {
|
||||
expect(() => {
|
||||
Temporal.PlainYearMonth.from("2023-02[u-ca=iso8602]");
|
||||
}).toThrowWithMessage(
|
||||
RangeError,
|
||||
"YYYY-MM string format can only be used with the iso8601 calendar"
|
||||
);
|
||||
|
||||
expect(() => {
|
||||
Temporal.PlainYearMonth.from("2023-02[u-ca=SerenityOS]");
|
||||
}).toThrowWithMessage(
|
||||
RangeError,
|
||||
"YYYY-MM 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.PlainYearMonth.from("2023-02-10T22:57[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