diff options
author | Timothy Flynn <trflynn89@pm.me> | 2021-12-01 12:24:35 -0500 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-12-06 15:46:34 +0100 |
commit | 9dc9700e3bdd778d4f02a03ba977c0e775f7e201 (patch) | |
tree | 41da132eeb2ba5471cd37a37366055928deb48ac /Userland | |
parent | dfe8d024829e83a71519919a493e3fe97672aec1 (diff) | |
download | serenity-9dc9700e3bdd778d4f02a03ba977c0e775f7e201.zip |
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.
Diffstat (limited to 'Userland')
-rw-r--r-- | Userland/Libraries/LibJS/Runtime/Intl/DateTimeFormat.cpp | 7 |
1 files changed, 6 insertions, 1 deletions
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<DateTimeFormat*> 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]]. } |