mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 19:57: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
|
@ -54,4 +54,20 @@ describe("errors", () => {
|
|||
"Got unexpected TimeZone object in conversion to Calendar"
|
||||
);
|
||||
});
|
||||
|
||||
test("yyyy-mm and mm-dd strings can only use the iso8601 calendar", () => {
|
||||
// FIXME: The error message doesn't really indicate this is the case.
|
||||
const values = [
|
||||
"02-10[u-ca=iso8602]",
|
||||
"02-10[u-ca=SerenityOS]",
|
||||
"2023-02[u-ca=iso8602]",
|
||||
"2023-02[u-ca=SerenityOS]",
|
||||
];
|
||||
|
||||
for (const value of values) {
|
||||
expect(() => {
|
||||
Temporal.Calendar.from(value);
|
||||
}).toThrowWithMessage(RangeError, `Invalid calendar string '${value}'`);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
|
@ -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'");
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
|
@ -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'");
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
|
@ -27,19 +27,9 @@ describe("normal behavior", () => {
|
|||
["Etc/GMT-12", "Etc/GMT-12"],
|
||||
["Europe/London", "Europe/London"],
|
||||
["Europe/Isle_of_Man", "Europe/London"],
|
||||
["1970-01-01+01", "+01:00"],
|
||||
["1970-01-01+01[-12:34]", "-12:34"],
|
||||
["1970-01-01T00:00:00+01", "+01:00"],
|
||||
["1970-01-01T00:00:00.000000000+01", "+01:00"],
|
||||
["1970-01-01T00:00:00.000000000+01:00:00", "+01:00"],
|
||||
["1970-01-01+12:34", "+12:34"],
|
||||
["1970-01-01+12:34:56", "+12:34:56"],
|
||||
["1970-01-01+12:34:56.789", "+12:34:56.789"],
|
||||
["1970-01-01+12:34:56.789[-01:00]", "-01:00"],
|
||||
["1970-01-01-12:34", "-12:34"],
|
||||
["1970-01-01-12:34:56", "-12:34:56"],
|
||||
["1970-01-01-12:34:56.789", "-12:34:56.789"],
|
||||
["1970-01-01-12:34:56.789[+01:00]", "+01:00"],
|
||||
];
|
||||
for (const [arg, expected] of values) {
|
||||
expect(Temporal.TimeZone.from(arg).id).toBe(expected);
|
||||
|
@ -75,4 +65,25 @@ describe("errors", () => {
|
|||
"Got unexpected Calendar object in conversion to TimeZone"
|
||||
);
|
||||
});
|
||||
|
||||
test("invalid time zone strings", () => {
|
||||
const values = [
|
||||
"1970-01-01+01",
|
||||
"1970-01-01+01[-12:34]",
|
||||
"1970-01-01+12:34",
|
||||
"1970-01-01+12:34:56",
|
||||
"1970-01-01+12:34:56.789",
|
||||
"1970-01-01+12:34:56.789[-01:00]",
|
||||
"1970-01-01-12:34",
|
||||
"1970-01-01-12:34:56",
|
||||
"1970-01-01-12:34:56.789",
|
||||
"1970-01-01-12:34:56.789[+01:00]",
|
||||
];
|
||||
|
||||
for (const value of values) {
|
||||
expect(() => {
|
||||
Temporal.TimeZone.from(value);
|
||||
}).toThrowWithMessage(RangeError, "Invalid ISO date time");
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue