summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTimothy Flynn <trflynn89@pm.me>2022-01-24 19:55:19 -0500
committerLinus Groh <mail@linusgroh.de>2022-01-25 18:39:36 +0000
commita027ccad75193b27db07390045d784e40019ea01 (patch)
tree0b70bebd729f6960d70ca9ac3fb1cdacd1d98dd2
parentede5c9548e55d8216dba21ed431b9e53d085a248 (diff)
downloadserenity-a027ccad75193b27db07390045d784e40019ea01.zip
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.
-rw-r--r--Userland/Applications/ClockSettings/ClockSettingsWidget.cpp2
-rw-r--r--Userland/Libraries/LibC/time.cpp2
-rw-r--r--Userland/Libraries/LibTimeZone/TimeZone.cpp8
-rw-r--r--Userland/Libraries/LibTimeZone/TimeZone.h1
-rw-r--r--Userland/Utilities/timezone.cpp2
5 files changed, 11 insertions, 4 deletions
diff --git a/Userland/Applications/ClockSettings/ClockSettingsWidget.cpp b/Userland/Applications/ClockSettings/ClockSettingsWidget.cpp
index b851bcd906..4f3c9dfeab 100644
--- a/Userland/Applications/ClockSettings/ClockSettingsWidget.cpp
+++ b/Userland/Applications/ClockSettings/ClockSettingsWidget.cpp
@@ -20,7 +20,7 @@ ClockSettingsWidget::ClockSettingsWidget()
load_from_gml(clock_settings_widget_gml);
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->set_only_allow_values_from_model(true);
diff --git a/Userland/Libraries/LibC/time.cpp b/Userland/Libraries/LibC/time.cpp
index 4d68119555..0390d2cbd7 100644
--- a/Userland/Libraries/LibC/time.cpp
+++ b/Userland/Libraries/LibC/time.cpp
@@ -372,7 +372,7 @@ void tzset()
if (char* tz = getenv("TZ"); tz != nullptr)
time_zone = tz;
else
- time_zone = TimeZone::current_time_zone();
+ time_zone = TimeZone::system_time_zone();
auto set_default_values = []() {
timezone = 0;
diff --git a/Userland/Libraries/LibTimeZone/TimeZone.cpp b/Userland/Libraries/LibTimeZone/TimeZone.cpp
index af9b739b1e..2ab7eb7e2a 100644
--- a/Userland/Libraries/LibTimeZone/TimeZone.cpp
+++ b/Userland/Libraries/LibTimeZone/TimeZone.cpp
@@ -7,6 +7,7 @@
#include <AK/String.h>
#include <LibTimeZone/TimeZone.h>
#include <stdio.h>
+#include <time.h>
namespace TimeZone {
@@ -68,7 +69,7 @@ private:
FILE* m_file { nullptr };
};
-StringView current_time_zone()
+StringView system_time_zone()
{
TimeZoneFile time_zone_file("r");
@@ -79,6 +80,11 @@ StringView current_time_zone()
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)
{
#ifdef __serenity__
diff --git a/Userland/Libraries/LibTimeZone/TimeZone.h b/Userland/Libraries/LibTimeZone/TimeZone.h
index 710461f86c..cbb7830ac2 100644
--- a/Userland/Libraries/LibTimeZone/TimeZone.h
+++ b/Userland/Libraries/LibTimeZone/TimeZone.h
@@ -31,6 +31,7 @@ struct NamedOffset : public Offset {
String name;
};
+StringView system_time_zone();
StringView current_time_zone();
ErrorOr<void> change_time_zone(StringView time_zone);
Span<StringView const> all_time_zones();
diff --git a/Userland/Utilities/timezone.cpp b/Userland/Utilities/timezone.cpp
index 641d8ef548..2d4cdaf8f7 100644
--- a/Userland/Utilities/timezone.cpp
+++ b/Userland/Utilities/timezone.cpp
@@ -32,7 +32,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
}
if (time_zone.is_empty()) {
- outln("{}", TimeZone::current_time_zone());
+ outln("{}", TimeZone::system_time_zone());
return 0;
}