From 05e7e4a2e0ca50558d556e205eb990e043ec4163 Mon Sep 17 00:00:00 2001 From: chrsmys Date: Sat, 8 Feb 2025 11:45:49 -0500 Subject: [PATCH] Fix invalid timezone errors for valid timezones on Apple platforms. --- lib/Platform/Intl/PlatformIntlApple.mm | 10 ++++++++-- test/hermes/intl/date-time-format-apple.js | 3 +++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/Platform/Intl/PlatformIntlApple.mm b/lib/Platform/Intl/PlatformIntlApple.mm index 090bb952350..6d66168e3fc 100644 --- a/lib/Platform/Intl/PlatformIntlApple.mm +++ b/lib/Platform/Intl/PlatformIntlApple.mm @@ -1462,8 +1462,14 @@ uint8_t getCurrencyDigits(std::u16string_view code) { timeZone = timeZoneIt->second.getString(); // b. If the result of IsValidTimeZoneName(timeZone) is false, then if (!isValidTimeZoneName(timeZone)) { - // i. Throw a RangeError exception. - return runtime.raiseRangeError("Incorrect timeZone information provided"); + if ([[NSTimeZone alloc] initWithName:u16StringToNSString(timeZone)] != nil) { + validTimeZoneNames().update(timeZone); + } else { + // i. Throw a RangeError exception. + return runtime.raiseRangeError( + vm::TwineChar16("Incorrect timeZone information provided: ") + + vm::TwineChar16(timeZone.c_str())); + } } // c. Let timeZone be CanonicalizeTimeZoneName(timeZone). timeZone = canonicalizeTimeZoneName(timeZone); diff --git a/test/hermes/intl/date-time-format-apple.js b/test/hermes/intl/date-time-format-apple.js index 83e1c28e50b..ac498e35883 100644 --- a/test/hermes/intl/date-time-format-apple.js +++ b/test/hermes/intl/date-time-format-apple.js @@ -39,6 +39,9 @@ print(new Intl.DateTimeFormat('en-US', { timeStyle: 'long', timeZone: 'PST'}).fo print(new Intl.DateTimeFormat('en-US', { timeStyle: 'long', timeZone: 'EET'}).format(date)); // CHECK-NEXT: 5:45:00{{.+}}AM GMT+2 +print(new Intl.DateTimeFormat("en-US", { timeZone: "US/Eastern", timeZoneName: "short" }).resolvedOptions().timeZone); +// CHECK-NEXT: US/Eastern + try { print(new Intl.DateTimeFormat('en-US', { timeStyle: 'long', timeZone: 'XXX'}).format(date)); print("Succeeded");