Commit 1be577d4 authored by Frank Tang's avatar Frank Tang Committed by Commit Bot

[Intl] Fix DefaultHourCycle to skip hHkK in literal

Bug: chromium:925216
Change-Id: I29d71df0c4c7850a80a86cd0719dea04fcc61816
Reviewed-on: https://chromium-review.googlesource.com/c/1436597Reviewed-by: 's avatarSathya Gunasekaran <gsathya@chromium.org>
Commit-Queue: Frank Tang <ftang@chromium.org>
Cr-Commit-Position: refs/heads/master@{#59146}
parent 4bc5932f
......@@ -799,14 +799,26 @@ std::unique_ptr<icu::SimpleDateFormat> CreateICUDateFormat(
Intl::HourCycle HourCycleDefault(icu::SimpleDateFormat* date_format) {
icu::UnicodeString pattern;
date_format->toPattern(pattern);
if (pattern.indexOf('K') >= 0) {
return Intl::HourCycle::kH11;
} else if (pattern.indexOf('h') >= 0) {
return Intl::HourCycle::kH12;
} else if (pattern.indexOf('H') >= 0) {
return Intl::HourCycle::kH23;
} else if (pattern.indexOf('k') >= 0) {
return Intl::HourCycle::kH24;
bool in_quote = false;
for (int32_t i = 0; i < pattern.length(); i++) {
char16_t ch = pattern[i];
switch (ch) {
case '\'':
in_quote = !in_quote;
break;
case 'K':
if (!in_quote) return Intl::HourCycle::kH11;
break;
case 'h':
if (!in_quote) return Intl::HourCycle::kH12;
break;
case 'H':
if (!in_quote) return Intl::HourCycle::kH23;
break;
case 'k':
if (!in_quote) return Intl::HourCycle::kH24;
break;
}
}
return Intl::HourCycle::kUndefined;
}
......
// Copyright 2019 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.
assertTrue(new Intl.DateTimeFormat(
"en", { timeZone: 'UTC', hour: 'numeric'}).resolvedOptions().hour12);
assertFalse(new Intl.DateTimeFormat(
"fr", { timeZone: 'UTC', hour: 'numeric'}).resolvedOptions().hour12);
assertFalse(new Intl.DateTimeFormat(
"de", { timeZone: 'UTC', hour: 'numeric'}).resolvedOptions().hour12);
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