From 9dc9700e3bdd778d4f02a03ba977c0e775f7e201 Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Wed, 1 Dec 2021 12:24:35 -0500 Subject: [PATCH] LibJS: Fallback to [[pattern]] when [[pattern12]] is unavailable Other implementations unconditionally initialize [[pattern12]] from [[pattern]] regardless of whether [[pattern]] has an hour pattern of h11 or h12. LibUnicode does not do this. So when InitializeDateTimeFormat defaults the hour cycle to the locale's preferred hour cycle, if the best format didn't have an equivalent hour pattern, [[pattern12]] will be empty. --- Userland/Libraries/LibJS/Runtime/Intl/DateTimeFormat.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Userland/Libraries/LibJS/Runtime/Intl/DateTimeFormat.cpp b/Userland/Libraries/LibJS/Runtime/Intl/DateTimeFormat.cpp index cff3f7cde4..08f77486ea 100644 --- a/Userland/Libraries/LibJS/Runtime/Intl/DateTimeFormat.cpp +++ b/Userland/Libraries/LibJS/Runtime/Intl/DateTimeFormat.cpp @@ -322,8 +322,13 @@ ThrowCompletionOr initialize_date_time_format(GlobalObject& glo // f. If dateTimeformat.[[HourCycle]] is "h11" or "h12", then if ((hour_cycle == Unicode::HourCycle::H11) || (hour_cycle == Unicode::HourCycle::H12)) { // i. Let pattern be bestFormat.[[pattern12]]. - if (best_format->pattern12.has_value()) + if (best_format->pattern12.has_value()) { pattern = best_format->pattern12.release_value(); + } else { + // Non-standard, LibUnicode only provides [[pattern12]] when [[pattern]] has a day + // period. Other implementations provide [[pattern12]] as a copy of [[pattern]]. + pattern = move(best_format->pattern); + } // ii. Let rangePatterns be bestFormat.[[rangePatterns12]]. }