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

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

This reverts commit 6b682148.

Reason for revert: Cause CHECK violation in https://bugs.chromium.org/p/chromium/issues/detail?id=1356838 
Original change's description:
> [intl] Return "UTC" instead of "Etc/UTC" or "Etc/GMT" as DefaultTimeZone
>
> Refactoring the code dealing with TimeZone Canonicalization.
> Change CanonicalizeTimeZoneName from return MaybeHandle<String> to Handle<String>
> Move TimeZoneId from JSDateTimeFormat to Intl and return Handle<String> instead of Handle<Object>
>
>
> Bug: v8:13112
> Change-Id: I678b0e0d407e5e4e9dd8b7120c0e99e7e2d9c5ea
> Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3833435
> Reviewed-by: Shu-yu Guo <syg@chromium.org>
> Commit-Queue: Frank Tang <ftang@chromium.org>
> Cr-Commit-Position: refs/heads/main@{#82505}

Bug: v8:13112
Change-Id: If4df4bc19b5d1a02c51e2c944abaca8a25b76a1e
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3863883Reviewed-by: 's avatarShu-yu Guo <syg@chromium.org>
Commit-Queue: Frank Tang <ftang@chromium.org>
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Cr-Commit-Position: refs/heads/main@{#82796}
parent 75240892
......@@ -2819,37 +2819,21 @@ bool IsUnicodeStringValidTimeZoneName(const icu::UnicodeString& id) {
}
} // namespace
Handle<String> Intl::CanonicalizeTimeZoneID(Isolate* isolate,
const icu::UnicodeString& id) {
MaybeHandle<String> Intl::CanonicalizeTimeZoneName(Isolate* isolate,
Handle<String> identifier) {
UErrorCode status = U_ZERO_ERROR;
std::string time_zone =
JSDateTimeFormat::CanonicalizeTimeZoneID(identifier->ToCString().get());
icu::UnicodeString time_zone_ustring =
icu::UnicodeString(time_zone.c_str(), -1, US_INV);
icu::UnicodeString canonical;
icu::TimeZone::getCanonicalID(id, canonical, status);
icu::TimeZone::getCanonicalID(time_zone_ustring, canonical, status);
CHECK(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 == UNICODE_STRING_SIMPLE("Etc/UTC") ||
canonical == UNICODE_STRING_SIMPLE("Etc/GMT")) {
return isolate->factory()->UTC_string();
}
return Intl::ToString(isolate, canonical).ToHandleChecked();
}
Handle<String> Intl::CanonicalizeTimeZoneName(Isolate* isolate,
Handle<String> identifier) {
std::string time_zone =
JSDateTimeFormat::CanonicalizeTimeZoneID(identifier->ToCString().get());
return CanonicalizeTimeZoneID(
isolate, icu::UnicodeString(time_zone.c_str(), -1, US_INV));
}
Handle<String> Intl::TimeZoneId(Isolate* isolate, const icu::TimeZone& tz) {
icu::UnicodeString time_zone;
tz.getID(time_zone);
return Intl::CanonicalizeTimeZoneID(isolate, time_zone);
return Intl::ToString(isolate, canonical);
}
bool Intl::IsValidTimeZoneName(Isolate* isolate, Handle<String> id) {
......@@ -2958,8 +2942,16 @@ Handle<String> Intl::SourceString(Isolate* isolate, FormatRangeSource source) {
}
Handle<String> Intl::DefaultTimeZone(Isolate* isolate) {
std::unique_ptr<icu::TimeZone> tz(icu::TimeZone::createDefault());
return TimeZoneId(isolate, *tz);
icu::UnicodeString id;
{
std::unique_ptr<icu::TimeZone> tz(icu::TimeZone::createDefault());
tz->getID(id);
}
UErrorCode status = U_ZERO_ERROR;
icu::UnicodeString canonical;
icu::TimeZone::getCanonicalID(id, canonical, status);
DCHECK(U_SUCCESS(status));
return Intl::ToString(isolate, canonical).ToHandleChecked();
}
namespace {
......
......@@ -390,13 +390,8 @@ class Intl {
static std::vector<int64_t> GetTimeZonePossibleOffsetMilliseconds(
Isolate* isolate, int32_t time_zone_index, int64_t time_ms);
static Handle<String> CanonicalizeTimeZoneName(Isolate* isolate,
Handle<String> identifier);
static Handle<String> CanonicalizeTimeZoneID(
Isolate* isolate, const icu::UnicodeString& identifier);
static Handle<String> TimeZoneId(Isolate* isolate, const icu::TimeZone& tz);
V8_WARN_UNUSED_RESULT static MaybeHandle<String> CanonicalizeTimeZoneName(
Isolate* isolate, Handle<String> identifier);
// ecma402/#sec-coerceoptionstoobject
V8_WARN_UNUSED_RESULT static MaybeHandle<JSReceiver> CoerceOptionsToObject(
......
......@@ -495,6 +495,37 @@ int FractionalSecondDigitsFromPattern(const std::string& pattern) {
} // namespace
Handle<Object> JSDateTimeFormat::TimeZoneId(Isolate* isolate,
const icu::TimeZone& tz) {
Factory* factory = isolate->factory();
icu::UnicodeString time_zone;
tz.getID(time_zone);
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 {
// Somehow on Windows we will reach here.
timezone_value = factory->undefined_value();
}
return timezone_value;
}
namespace {
Handle<String> GetCalendar(Isolate* isolate,
const icu::SimpleDateFormat& simple_date_format,
......@@ -526,8 +557,8 @@ Handle<String> GetCalendar(Isolate* isolate,
Handle<Object> GetTimeZone(Isolate* isolate,
const icu::SimpleDateFormat& simple_date_format) {
return Intl::TimeZoneId(isolate,
simple_date_format.getCalendar()->getTimeZone());
return JSDateTimeFormat::TimeZoneId(
isolate, simple_date_format.getCalendar()->getTimeZone());
}
} // namespace
......
......@@ -99,6 +99,7 @@ class JSDateTimeFormat
V8_EXPORT_PRIVATE static const std::set<std::string>& GetAvailableLocales();
Handle<Object> static TimeZoneId(Isolate* isolate, const icu::TimeZone& tz);
std::unique_ptr<icu::TimeZone> static CreateTimeZone(const char* timezone);
V8_EXPORT_PRIVATE static std::string CanonicalizeTimeZoneID(
......
......@@ -4591,7 +4591,7 @@ bool IsValidTimeZoneName(Isolate* isolate, Handle<String> time_zone) {
Handle<String> CanonicalizeTimeZoneName(Isolate* isolate,
Handle<String> identifier) {
return Intl::CanonicalizeTimeZoneName(isolate, identifier);
return Intl::CanonicalizeTimeZoneName(isolate, identifier).ToHandleChecked();
}
#else // V8_INTL_SUPPORT
......
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