mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-05-05 06:32:30 +02:00
LibUnicode: Fall back to GMT offset when a time zone name is unavailable
The following table in TR-35 includes a web of fall back rules when the requested time zone style is unavailable: https://unicode.org/reports/tr35/tr35-dates.html#dfst-zone Conveniently, the subset of styles supported by ECMA-402 (and therefore LibUnicode) all either fall back to GMT offset or to a style that is unsupported but itself falls back to GMT offset.
This commit is contained in:
committed by
Linus Groh
parent
8d35563f28
commit
d50f5e14f8
Notes:
sideshowbarker
2024-07-17 21:09:34 +09:00
Author: https://github.com/trflynn89 Commit: https://github.com/SerenityOS/serenity/commit/d50f5e14f81 Pull-request: https://github.com/SerenityOS/serenity/pull/11813 Reviewed-by: https://github.com/linusg ✅
@@ -262,7 +262,9 @@ String format_time_zone(StringView locale, StringView time_zone, CalendarPattern
|
||||
case CalendarPatternStyle::Long:
|
||||
case CalendarPatternStyle::ShortGeneric:
|
||||
case CalendarPatternStyle::LongGeneric:
|
||||
return get_time_zone_name(locale, time_zone, style).value_or(time_zone);
|
||||
if (auto name = get_time_zone_name(locale, time_zone, style); name.has_value())
|
||||
return *name;
|
||||
break;
|
||||
|
||||
case CalendarPatternStyle::ShortOffset:
|
||||
case CalendarPatternStyle::LongOffset:
|
||||
@@ -271,6 +273,21 @@ String format_time_zone(StringView locale, StringView time_zone, CalendarPattern
|
||||
default:
|
||||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
|
||||
// If more styles are added, consult the following table to ensure always falling back to GMT offset is still correct:
|
||||
// https://unicode.org/reports/tr35/tr35-dates.html#dfst-zone
|
||||
switch (style) {
|
||||
case CalendarPatternStyle::Short:
|
||||
case CalendarPatternStyle::ShortGeneric:
|
||||
return format_time_zone(locale, time_zone, CalendarPatternStyle::ShortOffset, time);
|
||||
|
||||
case CalendarPatternStyle::Long:
|
||||
case CalendarPatternStyle::LongGeneric:
|
||||
return format_time_zone(locale, time_zone, CalendarPatternStyle::LongOffset, time);
|
||||
|
||||
default:
|
||||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user