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

LibJS: Support non-UTC time zones in Temporal :^)

We can now recognize & normalize all time zones from the IANA time zone
database and not just 'UTC', which makes the LibJS Temporal
implementation a lot more useful! Thanks to the newly added LibTimeZone,
this was incredibly easy to implement :^)

This already includes these recent editorial changes in the Temporal
spec: 27bffe1
This commit is contained in:
Linus Groh 2022-01-11 20:20:16 +01:00
parent 205d63c3f0
commit d527eb62da
5 changed files with 49 additions and 27 deletions

View file

@ -10,6 +10,14 @@ describe("normal behavior", () => {
expect(Temporal.TimeZone.from(timeZone)).toBe(timeZone);
expect(Temporal.TimeZone.from(timeZoneLike)).toBe(timeZoneLike);
expect(Temporal.TimeZone.from(zonedDateTimeLike)).toBe(zonedDateTimeLike.timeZone);
// TODO: test from("string") once ParseTemporalTimeZoneString is working
expect(Temporal.TimeZone.from("UTC").id).toBe("UTC");
expect(Temporal.TimeZone.from("GMT").id).toBe("UTC");
expect(Temporal.TimeZone.from("Etc/UTC").id).toBe("UTC");
expect(Temporal.TimeZone.from("Etc/GMT").id).toBe("UTC");
// FIXME: https://github.com/tc39/proposal-temporal/issues/1993
// expect(Temporal.TimeZone.from("Etc/GMT+12").id).toBe("Etc/GMT+12");
// expect(Temporal.TimeZone.from("Etc/GMT-12").id).toBe("Etc/GMT-12");
expect(Temporal.TimeZone.from("Europe/London").id).toBe("Europe/London");
expect(Temporal.TimeZone.from("Europe/Isle_of_Man").id).toBe("Europe/London");
});
});

View file

@ -36,9 +36,22 @@ describe("normal behavior", () => {
});
test("canonicalizes time zone name", () => {
expect(new Temporal.TimeZone("Utc").id).toBe("UTC");
expect(new Temporal.TimeZone("utc").id).toBe("UTC");
expect(new Temporal.TimeZone("uTC").id).toBe("UTC");
const values = [
["UTC", "UTC"],
["Utc", "UTC"],
["utc", "UTC"],
["uTc", "UTC"],
["GMT", "UTC"],
["Etc/UTC", "UTC"],
["Etc/GMT", "UTC"],
["Etc/GMT+12", "Etc/GMT+12"],
["Etc/GMT-12", "Etc/GMT-12"],
["Europe/London", "Europe/London"],
["Europe/Isle_of_Man", "Europe/London"],
];
for (const [arg, expected] of values) {
expect(new Temporal.TimeZone(arg).id).toBe(expected);
}
});
test("numeric UTC offset", () => {

View file

@ -8,6 +8,11 @@ describe("correct behavior", () => {
["utc", "UTC"],
["Utc", "UTC"],
["UTC", "UTC"],
["GMT", "UTC"],
["Etc/UTC", "UTC"],
["Etc/GMT", "UTC"],
["Europe/London", "Europe/London"],
["Europe/Isle_of_Man", "Europe/London"],
["+00:00", "+00:00"],
["+00:00:00", "+00:00"],
["+00:00:00.000", "+00:00"],