1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-28 09:47:34 +00:00

LibTimeZone+Userland: Include Link entries when returning all time zones

We currently only return primary time zones, i.e. time zones that are
not a Link. LibJS will require knowledge of Link entries, and whether
each entry is or is not a Link.
This commit is contained in:
Timothy Flynn 2023-10-03 12:02:53 -04:00 committed by Andreas Kling
parent ddaba88340
commit 0bc401a1d6
6 changed files with 63 additions and 9 deletions

View file

@ -63,7 +63,17 @@ TimeZoneSettingsWidget::TimeZoneSettingsWidget()
{
load_from_gml(time_zone_settings_widget_gml).release_value_but_fixme_should_propagate_errors();
static auto time_zones = TimeZone::all_time_zones();
static auto time_zones = []() {
Vector<StringView> time_zones;
for (auto const& time_zone : TimeZone::all_time_zones()) {
if (time_zone.is_link == TimeZone::IsLink::No)
time_zones.append(time_zone.name);
}
return time_zones;
}();
m_time_zone = TimeZone::system_time_zone();
m_time_zone_combo_box = *find_descendant_of_type_named<GUI::ComboBox>("time_zone_input");

View file

@ -87,10 +87,10 @@ static Vector<StringView> available_canonical_time_zones()
Vector<StringView> result;
// 3. For each element name of names, do
for (auto name : names) {
for (auto const& name : names) {
// a. Assert: IsValidTimeZoneName( name ) is true.
// b. Let canonical be ! CanonicalizeTimeZoneName( name ).
auto canonical = TimeZone::canonicalize_time_zone(name).value();
auto canonical = TimeZone::canonicalize_time_zone(name.name).value();
// c. If result does not contain an element equal to canonical, then
if (!result.contains_slow(canonical)) {

View file

@ -143,10 +143,10 @@ ErrorOr<void> change_time_zone([[maybe_unused]] StringView time_zone)
#endif
}
ReadonlySpan<StringView> __attribute__((weak)) all_time_zones()
ReadonlySpan<TimeZoneIdentifier> __attribute__((weak)) all_time_zones()
{
#if !ENABLE_TIME_ZONE_DATA
static constexpr auto utc = Array { "UTC"sv };
static constexpr auto utc = Array { TimeZoneIdentifier { "UTC"sv, IsLink::No } };
return utc;
#else
return {};

View file

@ -19,6 +19,16 @@
namespace TimeZone {
enum class IsLink {
No,
Yes,
};
struct TimeZoneIdentifier {
StringView name;
IsLink is_link { IsLink::No };
};
enum class InDST {
No,
Yes,
@ -52,7 +62,7 @@ struct Location {
StringView system_time_zone();
StringView current_time_zone();
ErrorOr<void> change_time_zone(StringView time_zone);
ReadonlySpan<StringView> all_time_zones();
ReadonlySpan<TimeZoneIdentifier> all_time_zones();
Optional<TimeZone> time_zone_from_string(StringView time_zone);
StringView time_zone_to_string(TimeZone time_zone);

View file

@ -27,7 +27,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
if (list_time_zones) {
for (auto time_zone : TimeZone::all_time_zones())
outln("{}", time_zone);
outln("{}", time_zone.name);
return 0;
}