Commit dafcb538 authored by Frank Tang's avatar Frank Tang Committed by V8 LUCI CQ

[intl] Return "UTC" instead of "Etc/UTC" or "Etc/GMT" as DefaultTimeZone

Bug: v8:13112
Change-Id: I84e025e889fa3a0e5a52cc3ca986935ebe4b0c62
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3868712Reviewed-by: 's avatarShu-yu Guo <syg@chromium.org>
Commit-Queue: Frank Tang <ftang@chromium.org>
Cr-Commit-Position: refs/heads/main@{#83010}
parent b424baba
......@@ -2829,11 +2829,8 @@ MaybeHandle<String> Intl::CanonicalizeTimeZoneName(Isolate* isolate,
icu::UnicodeString canonical;
icu::TimeZone::getCanonicalID(time_zone_ustring, canonical, status);
CHECK(U_SUCCESS(status));
if (canonical == UNICODE_STRING_SIMPLE("Etc/UTC") ||
canonical == UNICODE_STRING_SIMPLE("Etc/GMT")) {
return isolate->factory()->UTC_string();
}
return Intl::ToString(isolate, canonical);
return JSDateTimeFormat::TimeZoneIdToString(isolate, canonical);
}
bool Intl::IsValidTimeZoneName(Isolate* isolate, Handle<String> id) {
......@@ -2951,7 +2948,8 @@ Handle<String> Intl::DefaultTimeZone(Isolate* isolate) {
icu::UnicodeString canonical;
icu::TimeZone::getCanonicalID(id, canonical, status);
DCHECK(U_SUCCESS(status));
return Intl::ToString(isolate, canonical).ToHandleChecked();
return JSDateTimeFormat::TimeZoneIdToString(isolate, canonical)
.ToHandleChecked();
}
namespace {
......
......@@ -492,9 +492,23 @@ int FractionalSecondDigitsFromPattern(const std::string& pattern) {
}
return result;
}
} // namespace
MaybeHandle<String> JSDateTimeFormat::TimeZoneIdToString(
Isolate* isolate, const icu::UnicodeString& id) {
// In CLDR (http://unicode.org/cldr/trac/ticket/9943), Etc/UTC is made
// a separate timezone ID from Etc/GMT even though they're still the same
// timezone. We have Etc/UTC because 'UTC', 'Etc/Universal',
// 'Etc/Zulu' and others are turned to 'Etc/UTC' by ICU. Etc/GMT comes
// from Etc/GMT0, Etc/GMT+0, Etc/GMT-0, Etc/Greenwich.
// ecma402#sec-canonicalizetimezonename step 3
if (id == UNICODE_STRING_SIMPLE("Etc/UTC") ||
id == UNICODE_STRING_SIMPLE("Etc/GMT")) {
return isolate->factory()->UTC_string();
}
return Intl::ToString(isolate, id);
}
Handle<Object> JSDateTimeFormat::TimeZoneId(Isolate* isolate,
const icu::TimeZone& tz) {
Factory* factory = isolate->factory();
......@@ -503,26 +517,14 @@ Handle<Object> JSDateTimeFormat::TimeZoneId(Isolate* isolate,
UErrorCode status = U_ZERO_ERROR;
icu::UnicodeString canonical_time_zone;
icu::TimeZone::getCanonicalID(time_zone, canonical_time_zone, status);
Handle<Object> timezone_value;
if (U_SUCCESS(status)) {
// In CLDR (http://unicode.org/cldr/trac/ticket/9943), Etc/UTC is made
// a separate timezone ID from Etc/GMT even though they're still the same
// timezone. We have Etc/UTC because 'UTC', 'Etc/Universal',
// 'Etc/Zulu' and others are turned to 'Etc/UTC' by ICU. Etc/GMT comes
// from Etc/GMT0, Etc/GMT+0, Etc/GMT-0, Etc/Greenwich.
// ecma402#sec-canonicalizetimezonename step 3
if (canonical_time_zone == UNICODE_STRING_SIMPLE("Etc/UTC") ||
canonical_time_zone == UNICODE_STRING_SIMPLE("Etc/GMT")) {
timezone_value = factory->UTC_string();
} else {
ASSIGN_RETURN_ON_EXCEPTION_VALUE(
isolate, timezone_value, Intl::ToString(isolate, canonical_time_zone),
Handle<Object>());
}
} else {
if (U_FAILURE(status)) {
// Somehow on Windows we will reach here.
timezone_value = factory->undefined_value();
return factory->undefined_value();
}
Handle<String> timezone_value;
ASSIGN_RETURN_ON_EXCEPTION_VALUE(
isolate, timezone_value, TimeZoneIdToString(isolate, canonical_time_zone),
Handle<Object>());
return timezone_value;
}
......
......@@ -100,6 +100,9 @@ class JSDateTimeFormat
V8_EXPORT_PRIVATE static const std::set<std::string>& GetAvailableLocales();
Handle<Object> static TimeZoneId(Isolate* isolate, const icu::TimeZone& tz);
V8_WARN_UNUSED_RESULT static MaybeHandle<String> TimeZoneIdToString(
Isolate* isolate, const icu::UnicodeString& id);
std::unique_ptr<icu::TimeZone> static CreateTimeZone(const char* timezone);
V8_EXPORT_PRIVATE static std::string CanonicalizeTimeZoneID(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment