mirror of
https://github.com/RGBCube/serenity
synced 2025-07-28 12:27:36 +00:00
LibJS: Add calendarName: "critical" option to toString() methods
This is a normative change in the Temporal spec.
See: e715a50
This commit is contained in:
parent
192aa75279
commit
4a167cfbec
9 changed files with 73 additions and 15 deletions
|
@ -125,6 +125,23 @@ describe("correct behavior", () => {
|
|||
expect(zonedDateTime.toString(options)).toBe("2022-08-08T14:38:40.1002003+00:00[UTC]");
|
||||
expect(calledToString).toBeFalse();
|
||||
});
|
||||
|
||||
test("calendarName option", () => {
|
||||
const plainDateTime = new Temporal.PlainDateTime(2022, 11, 2, 19, 4, 35, 100, 200, 300);
|
||||
const timeZone = new Temporal.TimeZone("UTC");
|
||||
const zonedDateTime = plainDateTime.toZonedDateTime(timeZone);
|
||||
const values = [
|
||||
["auto", "2022-11-02T19:04:35.1002003+00:00[UTC]"],
|
||||
["always", "2022-11-02T19:04:35.1002003+00:00[UTC][u-ca=iso8601]"],
|
||||
["never", "2022-11-02T19:04:35.1002003+00:00[UTC]"],
|
||||
["critical", "2022-11-02T19:04:35.1002003+00:00[UTC][!u-ca=iso8601]"],
|
||||
];
|
||||
|
||||
for (const [calendarName, expected] of values) {
|
||||
const options = { calendarName };
|
||||
expect(zonedDateTime.toString(options)).toBe(expected);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe("errors", () => {
|
||||
|
@ -140,4 +157,11 @@ describe("errors", () => {
|
|||
zonedDateTime.toString();
|
||||
}).toThrowWithMessage(TypeError, "null is not a function");
|
||||
});
|
||||
|
||||
test("calendarName option must be one of 'auto', 'always', 'never', 'critical'", () => {
|
||||
const zonedDateTime = new Temporal.ZonedDateTime(0n, "UTC");
|
||||
expect(() => {
|
||||
zonedDateTime.toString({ calendarName: "foo" });
|
||||
}).toThrowWithMessage(RangeError, "foo is not a valid value for option calendarName");
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue