mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-05-02 04:27:12 +02:00
LibJS+LibUnicode: Handle flexible day periods on both sides of midnight
Commit ec7d535 only partially handled the case of flexible day periods
rolling over midnight, in that it only worked for hours after midnight.
For example, the en locale defines a day period range of [21:00, 06:00).
The previous method of adding 24 hours to the given hour would change
e.g. 23:00 to 47:00, which isn't valid.
This commit is contained in:
committed by
Linus Groh
parent
fadd69263a
commit
0f26ab89ae
Notes:
sideshowbarker
2024-07-17 08:43:11 +09:00
Author: https://github.com/trflynn89 Commit: https://github.com/SerenityOS/serenity/commit/0f26ab89ae Pull-request: https://github.com/SerenityOS/serenity/pull/14637 Reviewed-by: https://github.com/linusg ✅
@@ -2289,14 +2289,18 @@ Optional<StringView> get_calendar_day_period_symbol_for_hour(StringView locale,
|
||||
|
||||
for (auto day_period_index : day_periods) {
|
||||
auto day_period = s_day_periods[day_period_index];
|
||||
auto h = hour;
|
||||
bool hour_falls_within_day_period = false;
|
||||
|
||||
if (day_period.begin > day_period.end) {
|
||||
day_period.end += 24;
|
||||
h += 24;
|
||||
if (hour >= day_period.begin)
|
||||
hour_falls_within_day_period = true;
|
||||
else if (hour <= day_period.end)
|
||||
hour_falls_within_day_period = true;
|
||||
} else if ((day_period.begin <= hour) && (hour < day_period.end)) {
|
||||
hour_falls_within_day_period = true;
|
||||
}
|
||||
|
||||
if ((day_period.begin <= h) && (h < day_period.end)) {
|
||||
if (hour_falls_within_day_period) {
|
||||
auto period = static_cast<DayPeriod>(day_period.day_period);
|
||||
return get_calendar_day_period_symbol(locale, calendar, style, period);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user