Commit dff4f7a9 authored by Frank Tang's avatar Frank Tang Committed by Commit Bot

Fix resolvedOption calendar for "iso8601"

Use a bit to work around the issue of ICU getType() bug.

Bug: v8:11295
Change-Id: I15d65bd44c489031d789e7638ea8abab90128124
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2614216
Commit-Queue: Frank Tang <ftang@chromium.org>
Reviewed-by: 's avatarJakob Kummerow <jkummerow@chromium.org>
Reviewed-by: 's avatarShu-yu Guo <syg@chromium.org>
Cr-Commit-Position: refs/heads/master@{#72028}
parent cbed65f4
...@@ -28,6 +28,8 @@ ACCESSORS(JSDateTimeFormat, icu_simple_date_format, ...@@ -28,6 +28,8 @@ ACCESSORS(JSDateTimeFormat, icu_simple_date_format,
ACCESSORS(JSDateTimeFormat, icu_date_interval_format, ACCESSORS(JSDateTimeFormat, icu_date_interval_format,
Managed<icu::DateIntervalFormat>, kIcuDateIntervalFormatOffset) Managed<icu::DateIntervalFormat>, kIcuDateIntervalFormatOffset)
BOOL_ACCESSORS(JSDateTimeFormat, flags, iso8601, Iso8601Bit::kShift)
inline void JSDateTimeFormat::set_hour_cycle(HourCycle hour_cycle) { inline void JSDateTimeFormat::set_hour_cycle(HourCycle hour_cycle) {
int hints = flags(); int hints = flags();
hints = HourCycleBits::update(hints, hour_cycle); hints = HourCycleBits::update(hints, hour_cycle);
......
...@@ -510,7 +510,11 @@ MaybeHandle<JSObject> JSDateTimeFormat::ResolvedOptions( ...@@ -510,7 +510,11 @@ MaybeHandle<JSObject> JSDateTimeFormat::ResolvedOptions(
// and // and
// http://www.unicode.org/repos/cldr/tags/latest/common/bcp47/calendar.xml // http://www.unicode.org/repos/cldr/tags/latest/common/bcp47/calendar.xml
if (calendar_str == "gregorian") { if (calendar_str == "gregorian") {
calendar_str = "gregory"; if (date_time_format->iso8601()) {
calendar_str = "iso8601";
} else {
calendar_str = "gregory";
}
} else if (calendar_str == "ethiopic-amete-alem") { } else if (calendar_str == "ethiopic-amete-alem") {
calendar_str = "ethioaa"; calendar_str = "ethioaa";
} }
...@@ -1563,6 +1567,7 @@ MaybeHandle<JSDateTimeFormat> JSDateTimeFormat::New( ...@@ -1563,6 +1567,7 @@ MaybeHandle<JSDateTimeFormat> JSDateTimeFormat::New(
icu_locale.setUnicodeKeywordValue("ca", calendar_str.get(), status); icu_locale.setUnicodeKeywordValue("ca", calendar_str.get(), status);
DCHECK(U_SUCCESS(status)); DCHECK(U_SUCCESS(status));
} }
bool iso8601 = strstr(icu_locale.getName(), "calendar=iso8601") != nullptr;
if (numbering_system_str != nullptr && if (numbering_system_str != nullptr &&
Intl::IsValidNumberingSystem(numbering_system_str.get())) { Intl::IsValidNumberingSystem(numbering_system_str.get())) {
...@@ -1870,6 +1875,7 @@ MaybeHandle<JSDateTimeFormat> JSDateTimeFormat::New( ...@@ -1870,6 +1875,7 @@ MaybeHandle<JSDateTimeFormat> JSDateTimeFormat::New(
date_time_format->set_time_style(time_style); date_time_format->set_time_style(time_style);
} }
date_time_format->set_hour_cycle(dateTimeFormatHourCycle); date_time_format->set_hour_cycle(dateTimeFormatHourCycle);
date_time_format->set_iso8601(iso8601);
date_time_format->set_locale(*locale_str); date_time_format->set_locale(*locale_str);
date_time_format->set_icu_locale(*managed_locale); date_time_format->set_icu_locale(*managed_locale);
date_time_format->set_icu_simple_date_format(*managed_format); date_time_format->set_icu_simple_date_format(*managed_format);
......
...@@ -128,6 +128,8 @@ class JSDateTimeFormat ...@@ -128,6 +128,8 @@ class JSDateTimeFormat
DECL_ACCESSORS(icu_simple_date_format, Managed<icu::SimpleDateFormat>) DECL_ACCESSORS(icu_simple_date_format, Managed<icu::SimpleDateFormat>)
DECL_ACCESSORS(icu_date_interval_format, Managed<icu::DateIntervalFormat>) DECL_ACCESSORS(icu_date_interval_format, Managed<icu::DateIntervalFormat>)
DECL_BOOLEAN_ACCESSORS(iso8601)
DECL_PRINTER(JSDateTimeFormat) DECL_PRINTER(JSDateTimeFormat)
TQ_OBJECT_CONSTRUCTORS(JSDateTimeFormat) TQ_OBJECT_CONSTRUCTORS(JSDateTimeFormat)
......
...@@ -10,6 +10,7 @@ bitfield struct JSDateTimeFormatFlags extends uint31 { ...@@ -10,6 +10,7 @@ bitfield struct JSDateTimeFormatFlags extends uint31 {
hour_cycle: HourCycle: 3 bit; hour_cycle: HourCycle: 3 bit;
date_style: DateTimeStyle: 3 bit; date_style: DateTimeStyle: 3 bit;
time_style: DateTimeStyle: 3 bit; time_style: DateTimeStyle: 3 bit;
iso8601: bool: 1bit;
} }
@generateCppClass @generateCppClass
......
// Copyright 2021 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
let cal = (new Intl.DateTimeFormat('en-u-ca-iso8601'))
.resolvedOptions().calendar;
assertEquals('iso8601', cal);
cal = (new Intl.DateTimeFormat('en-u-ca-ISO8601'))
.resolvedOptions().calendar;
assertEquals('iso8601', cal);
cal = (new Intl.DateTimeFormat('en', {calendar: 'iso8601'}))
.resolvedOptions().calendar;
assertEquals('iso8601', cal);
cal = (new Intl.DateTimeFormat('en', {calendar: 'ISO8601'}))
.resolvedOptions().calendar;
assertEquals('iso8601', cal);
cal = (new Intl.DateTimeFormat('en-u-ca-ISO8601x'))
.resolvedOptions().calendar;
assertEquals('gregory', cal);
cal = (new Intl.DateTimeFormat('en', {calendar: 'iso8601x'}))
.resolvedOptions().calendar;
assertEquals('gregory', cal);
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