1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 12:38:12 +00:00

LibTimeZone+Userland: Rename current_time_zone to system_time_zone

This renames the current implementation of current_time_zone to
system_time_zone to more clearly indicate what it is. Then reimplements
current_time_zone to return whatever was set up by tzset, falling back
to UTC if something went awry, for convenience.
This commit is contained in:
Timothy Flynn 2022-01-24 19:55:19 -05:00 committed by Linus Groh
parent ede5c9548e
commit a027ccad75
5 changed files with 11 additions and 4 deletions

View file

@ -20,7 +20,7 @@ ClockSettingsWidget::ClockSettingsWidget()
load_from_gml(clock_settings_widget_gml); load_from_gml(clock_settings_widget_gml);
static auto time_zones = TimeZone::all_time_zones(); static auto time_zones = TimeZone::all_time_zones();
m_time_zone = TimeZone::current_time_zone(); m_time_zone = TimeZone::system_time_zone();
m_time_zone_combo_box = *find_descendant_of_type_named<GUI::ComboBox>("time_zone_input"); m_time_zone_combo_box = *find_descendant_of_type_named<GUI::ComboBox>("time_zone_input");
m_time_zone_combo_box->set_only_allow_values_from_model(true); m_time_zone_combo_box->set_only_allow_values_from_model(true);

View file

@ -372,7 +372,7 @@ void tzset()
if (char* tz = getenv("TZ"); tz != nullptr) if (char* tz = getenv("TZ"); tz != nullptr)
time_zone = tz; time_zone = tz;
else else
time_zone = TimeZone::current_time_zone(); time_zone = TimeZone::system_time_zone();
auto set_default_values = []() { auto set_default_values = []() {
timezone = 0; timezone = 0;

View file

@ -7,6 +7,7 @@
#include <AK/String.h> #include <AK/String.h>
#include <LibTimeZone/TimeZone.h> #include <LibTimeZone/TimeZone.h>
#include <stdio.h> #include <stdio.h>
#include <time.h>
namespace TimeZone { namespace TimeZone {
@ -68,7 +69,7 @@ private:
FILE* m_file { nullptr }; FILE* m_file { nullptr };
}; };
StringView current_time_zone() StringView system_time_zone()
{ {
TimeZoneFile time_zone_file("r"); TimeZoneFile time_zone_file("r");
@ -79,6 +80,11 @@ StringView current_time_zone()
return "UTC"sv; return "UTC"sv;
} }
StringView current_time_zone()
{
return canonicalize_time_zone(tzname[0]).value_or("UTC"sv);
}
ErrorOr<void> change_time_zone([[maybe_unused]] StringView time_zone) ErrorOr<void> change_time_zone([[maybe_unused]] StringView time_zone)
{ {
#ifdef __serenity__ #ifdef __serenity__

View file

@ -31,6 +31,7 @@ struct NamedOffset : public Offset {
String name; String name;
}; };
StringView system_time_zone();
StringView current_time_zone(); StringView current_time_zone();
ErrorOr<void> change_time_zone(StringView time_zone); ErrorOr<void> change_time_zone(StringView time_zone);
Span<StringView const> all_time_zones(); Span<StringView const> all_time_zones();

View file

@ -32,7 +32,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
} }
if (time_zone.is_empty()) { if (time_zone.is_empty()) {
outln("{}", TimeZone::current_time_zone()); outln("{}", TimeZone::system_time_zone());
return 0; return 0;
} }