Bläddra i källkod

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.
Timothy Flynn 2 år sedan
förälder
incheckning
6d49eab8a6

+ 2 - 1
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<String> canonicalize_time_zone_name(VM& vm, StringView time_zone)
@@ -48,7 +49,7 @@ ThrowCompletionOr<String> 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.

+ 1 - 1
Userland/Libraries/LibTimeZone/TimeZone.cpp

@@ -177,7 +177,7 @@ Optional<StringView> 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;