[Intl] Fix DefaultHourCycle to skip hHkK in literal
Bug: chromium:925216 Change-Id: I29d71df0c4c7850a80a86cd0719dea04fcc61816 Reviewed-on: https://chromium-review.googlesource.com/c/1436597 Reviewed-by: Sathya Gunasekaran <gsathya@chromium.org> Commit-Queue: Frank Tang <ftang@chromium.org> Cr-Commit-Position: refs/heads/master@{#59146}
This commit is contained in:
parent
4bc5932f29
commit
1be577d48f
@ -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;
|
||||
}
|
||||
|
10
test/intl/regress-925216.js
Normal file
10
test/intl/regress-925216.js
Normal file
@ -0,0 +1,10 @@
|
||||
// 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);
|
Loading…
Reference in New Issue
Block a user