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

LibJS: Allow formatting UTC-offset time zones with Intl.DateTimeFormat

These are normative changes in the ECMA-402 spec. See:
896ffcc
af4ec46
e25c455

(This combines the above commits into one patch as they each do not work
on their own).
This commit is contained in:
Timothy Flynn 2023-10-04 15:45:59 -04:00 committed by Andreas Kling
parent f31540e419
commit 39be5cb73a
7 changed files with 123 additions and 42 deletions

View file

@ -48,9 +48,14 @@ describe("errors", () => {
});
test("timeZone option is invalid", () => {
expect(() => {
new Intl.DateTimeFormat("en", { timeZone: "hello!" });
}).toThrowWithMessage(RangeError, "hello! is not a valid value for option timeZone");
["hello!", "+1", "+1:02", "+01:02:03"].forEach(timeZone => {
expect(() => {
new Intl.DateTimeFormat("en", { timeZone: timeZone });
}).toThrowWithMessage(
RangeError,
`${timeZone} is not a valid value for option timeZone`
);
});
});
test("era option is invalid", () => {
@ -273,9 +278,11 @@ describe("normal behavior", () => {
});
test("valid timeZone options", () => {
expect(() => {
new Intl.DateTimeFormat("en", { timeZone: "UTC" });
}).not.toThrow();
["UTC", "EST", "+01:02", "-20:30", "+00:00"].forEach(timeZone => {
expect(() => {
new Intl.DateTimeFormat("en", { timeZone: timeZone });
}).not.toThrow();
});
});
test("all valid weekday options", () => {

View file

@ -512,6 +512,13 @@ describe("timeZoneName", () => {
{ timeZone: "Asia/Kathmandu", timeZoneName: "longOffset", en0: "12/7/2021, 11:25\u202fPM GMT+05:45", en1: "1/23/1989, 12:53\u202fPM GMT+05:45", ar0: "٧/١٢‏/٢٠٢١، ١١:٢٥ م غرينتش+٠٥:٤٥", ar1: "٢٣‏/١/١٩٨٩، ١٢:٥٣ م غرينتش+٠٥:٤٥" },
{ timeZone: "Asia/Kathmandu", timeZoneName: "shortGeneric", en0: "12/7/2021, 11:25\u202fPM GMT+5:45", en1: "1/23/1989, 12:53\u202fPM GMT+5:45", ar0: "٧/١٢‏/٢٠٢١، ١١:٢٥ م غرينتش+٥:٤٥", ar1: "٢٣‏/١/١٩٨٩، ١٢:٥٣ م غرينتش+٥:٤٥" },
{ timeZone: "Asia/Kathmandu", timeZoneName: "longGeneric", en0: "12/7/2021, 11:25\u202fPM GMT+05:45", en1: "1/23/1989, 12:53\u202fPM GMT+05:45", ar0: "٧/١٢‏/٢٠٢١، ١١:٢٥ م غرينتش+٠٥:٤٥", ar1: "٢٣‏/١/١٩٨٩، ١٢:٥٣ م غرينتش+٠٥:٤٥" },
{ timeZone: "+04:15", timeZoneName: "short", en0: "12/7/2021, 9:55\u202fPM +04:15", en1: "1/23/1989, 11:23\u202fAM +04:15", ar0: "٧/١٢‏/٢٠٢١، ٩:٥٥ م +04:15", ar1: "٢٣‏/١/١٩٨٩، ١١:٢٣ ص +04:15" },
{ timeZone: "+04:15", timeZoneName: "long", en0: "12/7/2021, 9:55\u202fPM +04:15", en1: "1/23/1989, 11:23\u202fAM +04:15", ar0: "٧/١٢‏/٢٠٢١، ٩:٥٥ م +04:15", ar1: "٢٣‏/١/١٩٨٩، ١١:٢٣ ص +04:15" },
{ timeZone: "+04:15", timeZoneName: "shortOffset", en0: "12/7/2021, 9:55\u202fPM +04:15", en1: "1/23/1989, 11:23\u202fAM +04:15", ar0: "٧/١٢‏/٢٠٢١، ٩:٥٥ م +04:15", ar1: "٢٣‏/١/١٩٨٩، ١١:٢٣ ص +04:15" },
{ timeZone: "+04:15", timeZoneName: "longOffset", en0: "12/7/2021, 9:55\u202fPM +04:15", en1: "1/23/1989, 11:23\u202fAM +04:15", ar0: "٧/١٢‏/٢٠٢١، ٩:٥٥ م +04:15", ar1: "٢٣‏/١/١٩٨٩، ١١:٢٣ ص +04:15" },
{ timeZone: "+04:15", timeZoneName: "shortGeneric", en0: "12/7/2021, 9:55\u202fPM +04:15", en1: "1/23/1989, 11:23\u202fAM +04:15", ar0: "٧/١٢‏/٢٠٢١، ٩:٥٥ م +04:15", ar1: "٢٣‏/١/١٩٨٩، ١١:٢٣ ص +04:15" },
{ timeZone: "+04:15", timeZoneName: "longGeneric", en0: "12/7/2021, 9:55\u202fPM +04:15", en1: "1/23/1989, 11:23\u202fAM +04:15", ar0: "٧/١٢‏/٢٠٢١، ٩:٥٥ م +04:15", ar1: "٢٣‏/١/١٩٨٩، ١١:٢٣ ص +04:15" },
];
test("all", () => {

View file

@ -91,6 +91,14 @@ describe("correct behavior", () => {
const el = new Intl.DateTimeFormat("el", { timeZone: "UTC" });
expect(el.resolvedOptions().timeZone).toBe("UTC");
["UTC", "EST", "+01:02", "-20:30", "+00:00"].forEach(timeZone => {
const en = new Intl.DateTimeFormat("en", { timeZone: timeZone });
expect(en.resolvedOptions().timeZone).toBe(timeZone);
const el = new Intl.DateTimeFormat("el", { timeZone: timeZone });
expect(el.resolvedOptions().timeZone).toBe(timeZone);
});
});
test("dateStyle", () => {