mirror of
https://github.com/RGBCube/serenity
synced 2025-05-14 19:04:59 +00:00
LibJS+LibUnicode: Handle flexible day periods that roll over midnight
When searching for the locale-specific flexible day period for a given hour, we were neglecting to handle cases where the period crosses 00:00. For example, the en locale defines a day period range of [21:00, 06:00). When given the hour of 05:00, we were checking if (21 <= 5 && 5 < 6), thus not recognizing that the hour falls in that period.
This commit is contained in:
parent
c8addf1a5e
commit
ec7d5351ed
2 changed files with 16 additions and 2 deletions
|
@ -2043,9 +2043,15 @@ Optional<StringView> get_calendar_day_period_symbol_for_hour(StringView locale,
|
|||
auto day_periods = s_day_period_lists[day_periods_index];
|
||||
|
||||
for (auto day_period_index : day_periods) {
|
||||
auto const& day_period = s_day_periods[day_period_index];
|
||||
auto day_period = s_day_periods[day_period_index];
|
||||
auto h = hour;
|
||||
|
||||
if ((day_period.begin <= hour) && (hour < day_period.end)) {
|
||||
if (day_period.begin > day_period.end) {
|
||||
day_period.end += 24;
|
||||
h += 24;
|
||||
}
|
||||
|
||||
if ((day_period.begin <= h) && (h < day_period.end)) {
|
||||
auto period = static_cast<DayPeriod>(day_period.day_period);
|
||||
return get_calendar_day_period_symbol(locale, calendar, style, period);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue