Commit 75f8f2f8 authored by Frank Tang's avatar Frank Tang Committed by Commit Bot

[Intl] Fix resolved-locale-with-hc-unicode

Remove hc from -u- if does not agree with the resolved one.


Bug: v8:7482
Change-Id: I635c5357b8fd2b630ed80577a9b6a116e9a0e3f4
Reviewed-on: https://chromium-review.googlesource.com/c/1417170
Commit-Queue: Frank Tang <ftang@chromium.org>
Reviewed-by: 's avatarJakob Kummerow <jkummerow@chromium.org>
Cr-Commit-Position: refs/heads/master@{#59084}
parent 373f9d32
......@@ -992,6 +992,34 @@ MaybeHandle<JSDateTimeFormat> JSDateTimeFormat::Initialize(
// a. Set dateTimeFormat.[[HourCycle]] to undefined.
date_time_format->set_hour_cycle(Intl::HourCycle::kUndefined);
}
// 12.1.1 InitializeDateTimeFormat ( dateTimeFormat, locales, options )
//
// Steps 8-9 set opt.[[hc]] to value *other than undefined*
// if "hour12" is set or "hourCycle" is set in the option.
//
// 9.2.6 ResolveLocale (... )
// Step 8.h / 8.i and 8.k
//
// An hour12 option always overrides an hourCycle option.
// Additionally hour12 and hourCycle both clear out any existing Unicode
// extension key in the input locale.
//
// See details in https://github.com/tc39/test262/pull/2035
if (maybe_get_hour12.FromJust() ||
maybe_hour_cycle.FromJust() != Intl::HourCycle::kUndefined) {
auto hc_extension_it = r.extensions.find("hc");
if (hc_extension_it != r.extensions.end()) {
if (date_time_format->hour_cycle() !=
Intl::ToHourCycle(hc_extension_it->second.c_str())) {
// Remove -hc- if it does not agree with what we used.
UErrorCode status = U_ZERO_ERROR;
icu_locale.setKeywordValue(uloc_toLegacyKey("hc"), nullptr, status);
CHECK(U_SUCCESS(status));
}
}
}
Handle<Managed<icu::Locale>> managed_locale =
Managed<icu::Locale>::FromRawPtr(isolate, 0, icu_locale.clone());
......
......@@ -26,7 +26,8 @@ let locales = [
];
invalid_hc.forEach(function(hc) {
let df = new Intl.DateTimeFormat(["en-u-hc-" + hc + "-fo-obar"]);
let df = new Intl.DateTimeFormat(
["en-u-hc-" + hc + "-fo-obar"], {hour: "2-digit"});
assertEquals("en", df.resolvedOptions().locale);
}
);
......@@ -34,7 +35,8 @@ invalid_hc.forEach(function(hc) {
valid_hc.forEach(function(hc) {
locales.forEach(function(base) {
let l = base + "-u-hc-" + hc;
let df = new Intl.DateTimeFormat([l + "-fo-obar"]);
let df = new Intl.DateTimeFormat(
[l + "-fo-obar"], {hour: "2-digit"});
assertEquals(l, df.resolvedOptions().locale);
});
}
......
......@@ -524,9 +524,6 @@
# https://bugs.chromium.org/p/v8/issues/detail?id=7472
'intl402/NumberFormat/currency-digits': [FAIL],
# https://bugs.chromium.org/p/v8/issues/detail?id=7482
'intl402/DateTimeFormat/prototype/resolvedOptions/resolved-locale-with-hc-unicode': [FAIL],
# https://bugs.chromium.org/p/v8/issues/detail?id=7483
'annexB/built-ins/Function/createdynfn-html-close-comment-params': [FAIL],
......
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