diff options
author | Timothy Flynn <trflynn89@pm.me> | 2022-01-19 18:05:31 -0500 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2022-01-23 12:48:26 +0000 |
commit | da27937144f1d23bbca39c4e2f7a7bc1484b2dc1 (patch) | |
tree | 154c2471d8aec6a8e95bdf008e218f0ab56cbfd0 | |
parent | 0a4430fc417d8cd06ffd191eff3464efbf5dd736 (diff) | |
download | serenity-da27937144f1d23bbca39c4e2f7a7bc1484b2dc1.zip |
LibTimeZone: Add an API to retrieve a list of all known IANA time zones
-rw-r--r-- | Meta/Lagom/Tools/CodeGenerators/LibTimeZone/GenerateTimeZoneData.cpp | 16 | ||||
-rw-r--r-- | Userland/Libraries/LibTimeZone/TimeZone.cpp | 10 | ||||
-rw-r--r-- | Userland/Libraries/LibTimeZone/TimeZone.h | 1 |
3 files changed, 27 insertions, 0 deletions
diff --git a/Meta/Lagom/Tools/CodeGenerators/LibTimeZone/GenerateTimeZoneData.cpp b/Meta/Lagom/Tools/CodeGenerators/LibTimeZone/GenerateTimeZoneData.cpp index b83d5312b1..b98dc3574e 100644 --- a/Meta/Lagom/Tools/CodeGenerators/LibTimeZone/GenerateTimeZoneData.cpp +++ b/Meta/Lagom/Tools/CodeGenerators/LibTimeZone/GenerateTimeZoneData.cpp @@ -524,6 +524,22 @@ Optional<Offset> get_time_zone_offset(TimeZone time_zone, AK::Time time) return dst_offset; } +Span<StringView const> all_time_zones() +{ + static constexpr auto all_time_zones = Array { + )~~~"); + + for (auto const& time_zone : time_zone_data.time_zone_names) { + generator.set("time_zone", time_zone); + generator.append("\"@time_zone@\"sv, "); + } + + generator.append(R"~~~( + }; + + return all_time_zones; +} + } )~~~"); diff --git a/Userland/Libraries/LibTimeZone/TimeZone.cpp b/Userland/Libraries/LibTimeZone/TimeZone.cpp index c898ed365a..f9953c53b2 100644 --- a/Userland/Libraries/LibTimeZone/TimeZone.cpp +++ b/Userland/Libraries/LibTimeZone/TimeZone.cpp @@ -31,6 +31,16 @@ StringView current_time_zone() return canonicalize_time_zone(tzname[0]).value_or("UTC"sv); } +Span<StringView const> __attribute__((weak)) all_time_zones() +{ +#if !ENABLE_TIME_ZONE_DATA + static constexpr auto utc = Array { "UTC"sv }; + return utc; +#else + return {}; +#endif +} + Optional<TimeZone> __attribute__((weak)) time_zone_from_string([[maybe_unused]] StringView time_zone) { #if !ENABLE_TIME_ZONE_DATA diff --git a/Userland/Libraries/LibTimeZone/TimeZone.h b/Userland/Libraries/LibTimeZone/TimeZone.h index 6a1e7b2a81..493f89eb4d 100644 --- a/Userland/Libraries/LibTimeZone/TimeZone.h +++ b/Userland/Libraries/LibTimeZone/TimeZone.h @@ -25,6 +25,7 @@ struct Offset { }; StringView current_time_zone(); +Span<StringView const> all_time_zones(); Optional<TimeZone> time_zone_from_string(StringView time_zone); StringView time_zone_to_string(TimeZone time_zone); |