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

[intl] Fix space between day and hour in Chinese locale

Make sure there are space between day and hour in the pattern
when we alternate date pattern for the change of hour cycle.

Bug: chromium:1170305
Change-Id: I2714111dcdedeefafdb854d1684f301786273303
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2654002
Commit-Queue: Frank Tang <ftang@chromium.org>
Reviewed-by: 's avatarFrank Tang <ftang@chromium.org>
Reviewed-by: 's avatarJakob Kummerow <jkummerow@chromium.org>
Cr-Commit-Position: refs/heads/master@{#72418}
parent 3e555235
......@@ -1107,6 +1107,7 @@ icu::UnicodeString ReplaceHourCycleInPattern(icu::UnicodeString pattern,
}
bool replace = true;
icu::UnicodeString result;
char16_t last = u'\0';
for (int32_t i = 0; i < pattern.length(); i++) {
char16_t ch = pattern.charAt(i);
switch (ch) {
......@@ -1121,12 +1122,17 @@ icu::UnicodeString ReplaceHourCycleInPattern(icu::UnicodeString pattern,
case 'K':
V8_FALLTHROUGH;
case 'k':
// If the previous field is a day, add a space before the hour.
if (replace && last == u'd') {
result.append(' ');
}
result.append(replace ? replacement : ch);
break;
default:
result.append(ch);
break;
}
last = ch;
}
return result;
}
......
// 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.
// Test in Chinese locale there is space between the day and hour field.
let opt = {year: 'numeric', month: '2-digit', day: '2-digit', hour: '2-digit',
minute: '2-digit', second: '2-digit', hour12: false, timeZone: "UTC"};
let d = new Date("2021-01-27T03:15:04Z");
["zh", "zh-CN", "zh-Hant", "zh-TW", "zh-Hans"].forEach(function(l) {
// Ensure both 27 (day) and 03 (hour) can be found in the string.
assertTrue(d.toLocaleString(l, opt).indexOf("27") >= 0);
assertTrue(d.toLocaleString(l, opt).indexOf("03") >= 0);
// Ensure there is no case that 27 (day) and 03 (hour) concat together.
assertEquals(-1, d.toLocaleString(l, opt).indexOf("2703"));
});
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