| 1 |
From: =?utf-8?b?Ik1hcmNvIFRyZXZpc2FuIChUcmV2acOxbyki?= <[email protected]> |
| 2 |
Date: Tue, 1 Feb 2022 18:54:29 +0100 |
| 3 |
Subject: =?utf-8?q?DateTimeFormat=3A_Use_normal_parenthesis_instead_of_ICU_?= |
| 4 |
=?utf-8?q?=22=E2=94=9C_=E2=94=A4=22?= |
| 5 |
MIME-Version: 1.0 |
| 6 |
Content-Type: text/plain; charset="utf-8" |
| 7 |
Content-Transfer-Encoding: 8bit |
| 8 |
|
| 9 |
ICU may return pattern data using "├ ┤" parenthesis, to avoid this we |
| 10 |
are replacing them in case this happens. |
| 11 |
|
| 12 |
As per this we can re-enable the day-period-hour cycle for DayPeriod |
| 13 |
|
| 14 |
See: https://unicode-org.atlassian.net/browse/CLDR-13184 |
| 15 |
--- |
| 16 |
js/src/builtin/intl/DateTimeFormat.cpp | 14 ++++++++++++++ |
| 17 |
.../non262/Intl/DateTimeFormat/day-period-hour-cycle.js | 2 -- |
| 18 |
2 files changed, 14 insertions(+), 2 deletions(-) |
| 19 |
|
| 20 |
diff --git a/js/src/builtin/intl/DateTimeFormat.cpp b/js/src/builtin/intl/DateTimeFormat.cpp |
| 21 |
index bd3cebb..cba0e38 100644 |
| 22 |
--- a/js/src/builtin/intl/DateTimeFormat.cpp |
| 23 |
+++ b/js/src/builtin/intl/DateTimeFormat.cpp |
| 24 |
@@ -636,6 +636,18 @@ static void ReplaceHourSymbol(mozilla::Span<char16_t> patternOrSkeleton, |
| 25 |
} |
| 26 |
} |
| 27 |
|
| 28 |
+// Workaround for https://unicode-org.atlassian.net/browse/CLDR-13184 |
| 29 |
+static void ReplaceICUParenthesis(mozilla::Span<char16_t> patternOrSkeleton) { |
| 30 |
+ PatternIterator<char16_t> iter(patternOrSkeleton); |
| 31 |
+ while (auto* ptr = iter.next()) { |
| 32 |
+ if (*ptr == 0x251c) { |
| 33 |
+ *ptr = '('; |
| 34 |
+ } else if (*ptr == 0x2524) { |
| 35 |
+ *ptr = ')'; |
| 36 |
+ } |
| 37 |
+ } |
| 38 |
+} |
| 39 |
+ |
| 40 |
static auto PatternMatchOptions(mozilla::Span<const char16_t> skeleton) { |
| 41 |
// Values for hour, minute, and second are: |
| 42 |
// - absent: 0 |
| 43 |
@@ -744,6 +756,8 @@ bool js::intl_patternForSkeleton(JSContext* cx, unsigned argc, Value* vp) { |
| 44 |
ReplaceHourSymbol(pattern, hourCycle.value()); |
| 45 |
} |
| 46 |
|
| 47 |
+ ReplaceICUParenthesis(pattern); |
| 48 |
+ |
| 49 |
JSString* str = pattern.toString(); |
| 50 |
if (!str) { |
| 51 |
return false; |
| 52 |
diff --git a/js/src/tests/non262/Intl/DateTimeFormat/day-period-hour-cycle.js b/js/src/tests/non262/Intl/DateTimeFormat/day-period-hour-cycle.js |
| 53 |
index 0ad0640..6bfbf94 100644 |
| 54 |
--- a/js/src/tests/non262/Intl/DateTimeFormat/day-period-hour-cycle.js |
| 55 |
+++ b/js/src/tests/non262/Intl/DateTimeFormat/day-period-hour-cycle.js |
| 56 |
@@ -76,7 +76,6 @@ const tests = [ |
| 57 |
}, |
| 58 |
|
| 59 |
// ICU replacement pattern for missing <appendItem> entries in CLDR. |
| 60 |
- /* Currently unsupported by debian system ICU |
| 61 |
{ |
| 62 |
date: new Date("2019-01-01T12:00:00"), |
| 63 |
options: { dayPeriod: "short", minute: "numeric" }, |
| 64 |
@@ -85,7 +84,6 @@ const tests = [ |
| 65 |
de: [Minute("0"), Literal(" (Tageshälfte: "), DayPeriod("mittags"), Literal(")")], |
| 66 |
}, |
| 67 |
}, |
| 68 |
- */ |
| 69 |
]; |
| 70 |
|
| 71 |
for (let {date, options, locales} of tests) { |