From 6d49eab8a6132c9aa71f4fde0d3c4fd1dc12e6df Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Thu, 23 Mar 2023 08:00:16 -0400 Subject: [PATCH] LibJS+LibTimeZone: Explicitly canonicalize "GMT" to "UTC" This is a normative change in the ECMA-402 spec. See: https://github.com/tc39/ecma402/commit/50eb413 Note that this canonicalization already occurred. As the above commit alludes to, we parse the rearguard format of the TZDB, so GMT is already an alias to Etc/GMT. But it doesn't hurt to be explicit here. --- Userland/Libraries/LibJS/Runtime/Temporal/TimeZone.cpp | 3 ++- Userland/Libraries/LibTimeZone/TimeZone.cpp | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/TimeZone.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/TimeZone.cpp index 75f24bb54ad..3fb5ec4c90a 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/TimeZone.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/TimeZone.cpp @@ -40,6 +40,7 @@ bool is_available_time_zone_name(StringView time_zone) return ::TimeZone::time_zone_from_string(time_zone).has_value(); } +// 6.4.2 CanonicalizeTimeZoneName ( timeZone ), https://tc39.es/ecma402/#sec-canonicalizetimezonename // 11.1.2 CanonicalizeTimeZoneName ( timeZone ), https://tc39.es/proposal-temporal/#sec-canonicalizetimezonename // 15.1.2 CanonicalizeTimeZoneName ( timeZone ), https://tc39.es/proposal-temporal/#sup-canonicalizetimezonename ThrowCompletionOr canonicalize_time_zone_name(VM& vm, StringView time_zone) @@ -48,7 +49,7 @@ ThrowCompletionOr canonicalize_time_zone_name(VM& vm, StringView time_zo // 2. If ianaTimeZone is a Link name, let ianaTimeZone be the String value of the corresponding Zone name as specified in the file backward of the IANA Time Zone Database. auto iana_time_zone = ::TimeZone::canonicalize_time_zone(time_zone); - // 3. If ianaTimeZone is "Etc/UTC" or "Etc/GMT", return "UTC". + // 3. If ianaTimeZone is one of "Etc/UTC", "Etc/GMT", or "GMT", return "UTC". // NOTE: This is already done in canonicalize_time_zone(). // 4. Return ianaTimeZone. diff --git a/Userland/Libraries/LibTimeZone/TimeZone.cpp b/Userland/Libraries/LibTimeZone/TimeZone.cpp index e687510bd09..c290721fb43 100644 --- a/Userland/Libraries/LibTimeZone/TimeZone.cpp +++ b/Userland/Libraries/LibTimeZone/TimeZone.cpp @@ -177,7 +177,7 @@ Optional canonicalize_time_zone(StringView time_zone) return {}; auto canonical_time_zone = time_zone_to_string(*maybe_time_zone); - if (canonical_time_zone.is_one_of("Etc/UTC"sv, "Etc/GMT"sv)) + if (canonical_time_zone.is_one_of("Etc/UTC"sv, "Etc/GMT"sv, "GMT"sv)) return "UTC"sv; return canonical_time_zone;