Commit 758212a8 authored by Frank Tang's avatar Frank Tang Committed by Commit Bot

[Intl] Fix hour cycle in formatRange

Bug: v8:9934
Change-Id: I8e4c0bb647913b703c01fd0d11329fba254e5350
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2195491Reviewed-by: 's avatarJakob Kummerow <jkummerow@chromium.org>
Commit-Queue: Frank Tang <ftang@chromium.org>
Cr-Commit-Position: refs/heads/master@{#67760}
parent 2b2f3a42
......@@ -34,6 +34,23 @@ namespace internal {
namespace {
std::string ToHourCycleString(JSDateTimeFormat::HourCycle hc) {
switch (hc) {
case JSDateTimeFormat::HourCycle::kH11:
return "h11";
case JSDateTimeFormat::HourCycle::kH12:
return "h12";
case JSDateTimeFormat::HourCycle::kH23:
return "h23";
case JSDateTimeFormat::HourCycle::kH24:
return "h24";
case JSDateTimeFormat::HourCycle::kUndefined:
return "";
default:
UNREACHABLE();
}
}
JSDateTimeFormat::HourCycle ToHourCycle(const std::string& hc) {
if (hc == "h11") return JSDateTimeFormat::HourCycle::kH11;
if (hc == "h12") return JSDateTimeFormat::HourCycle::kH12;
......@@ -1158,10 +1175,18 @@ icu::DateIntervalFormat* LazyCreateDateIntervalFormat(
icu::SimpleDateFormat* icu_simple_date_format =
date_time_format->icu_simple_date_format().raw();
UErrorCode status = U_ZERO_ERROR;
icu::Locale loc = *(date_time_format->icu_locale().raw());
// We need to pass in the hc to DateIntervalFormat by using Unicode 'hc'
// extension.
std::string hcString = ToHourCycleString(date_time_format->hour_cycle());
if (!hcString.empty()) {
loc.setUnicodeKeywordValue("hc", hcString, status);
}
std::unique_ptr<icu::DateIntervalFormat> date_interval_format(
icu::DateIntervalFormat::createInstance(
SkeletonFromDateFormat(*icu_simple_date_format),
*(date_time_format->icu_locale().raw()), status));
SkeletonFromDateFormat(*icu_simple_date_format), loc, status));
if (U_FAILURE(status)) {
return nullptr;
}
......
......@@ -33,9 +33,6 @@
# https://code.google.com/p/v8/issues/detail?id=7481
'collator/check-kf-option': [FAIL],
'collator/check-kn-option': [FAIL],
# http://crbug/v8/9930
'date-format/format_range_hour_cycle': [FAIL],
}], # ALWAYS
['variant == no_wasm_traps', {
......
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