mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 04:37:44 +00:00
LibTimeZone: Add an API to retrieve a list of all known IANA time zones
This commit is contained in:
parent
0a4430fc41
commit
da27937144
3 changed files with 27 additions and 0 deletions
|
@ -524,6 +524,22 @@ Optional<Offset> get_time_zone_offset(TimeZone time_zone, AK::Time time)
|
||||||
return dst_offset;
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
)~~~");
|
)~~~");
|
||||||
|
|
||||||
|
|
|
@ -31,6 +31,16 @@ StringView current_time_zone()
|
||||||
return canonicalize_time_zone(tzname[0]).value_or("UTC"sv);
|
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)
|
Optional<TimeZone> __attribute__((weak)) time_zone_from_string([[maybe_unused]] StringView time_zone)
|
||||||
{
|
{
|
||||||
#if !ENABLE_TIME_ZONE_DATA
|
#if !ENABLE_TIME_ZONE_DATA
|
||||||
|
|
|
@ -25,6 +25,7 @@ struct Offset {
|
||||||
};
|
};
|
||||||
|
|
||||||
StringView current_time_zone();
|
StringView current_time_zone();
|
||||||
|
Span<StringView const> all_time_zones();
|
||||||
|
|
||||||
Optional<TimeZone> time_zone_from_string(StringView time_zone);
|
Optional<TimeZone> time_zone_from_string(StringView time_zone);
|
||||||
StringView time_zone_to_string(TimeZone time_zone);
|
StringView time_zone_to_string(TimeZone time_zone);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue