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.
This commit is contained in:
Timothy Flynn 2021-12-01 12:24:35 -05:00 committed by Andreas Kling
commit 9dc9700e3b
Notes: sideshowbarker 2024-07-17 23:07:01 +09:00

View file

@ -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]].
}