summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authorTimothy Flynn <trflynn89@pm.me>2022-01-20 08:15:19 -0500
committerLinus Groh <mail@linusgroh.de>2022-01-23 12:48:26 +0000
commit6057a2ca30a2a94c7ff924cbdde6ac922d537fed (patch)
treef155ed57e7496d761a107c2c1babef2e99d51937 /Userland
parent2bdc3aec4222218a4058aaa7d93e04e5e635cbbd (diff)
downloadserenity-6057a2ca30a2a94c7ff924cbdde6ac922d537fed.zip
timezone: Add a command line utility to set the system time zone
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Utilities/CMakeLists.txt1
-rw-r--r--Userland/Utilities/timezone.cpp33
2 files changed, 34 insertions, 0 deletions
diff --git a/Userland/Utilities/CMakeLists.txt b/Userland/Utilities/CMakeLists.txt
index 5c106a8f14..0dd3e06f47 100644
--- a/Userland/Utilities/CMakeLists.txt
+++ b/Userland/Utilities/CMakeLists.txt
@@ -156,6 +156,7 @@ target_link_libraries(telws LibProtocol LibLine)
target_link_libraries(test-fuzz LibCore LibGemini LibGfx LibHTTP LibIPC LibJS LibMarkdown LibShell)
target_link_libraries(test-imap LibIMAP LibMain)
target_link_libraries(test-pthread LibThreading)
+target_link_libraries(timezone LibMain)
target_link_libraries(top LibMain)
target_link_libraries(touch LibMain)
target_link_libraries(truncate LibMain)
diff --git a/Userland/Utilities/timezone.cpp b/Userland/Utilities/timezone.cpp
new file mode 100644
index 0000000000..3c2c008c26
--- /dev/null
+++ b/Userland/Utilities/timezone.cpp
@@ -0,0 +1,33 @@
+/*
+ * Copyright (c) 2022, Tim Flynn <trflynn89@pm.me>
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#include <AK/StringView.h>
+#include <AK/Try.h>
+#include <LibCore/ArgsParser.h>
+#include <LibCore/System.h>
+#include <LibMain/Main.h>
+#include <LibTimeZone/TimeZone.h>
+
+ErrorOr<int> serenity_main(Main::Arguments arguments)
+{
+ TRY(Core::System::pledge("stdio rpath wpath cpath"));
+ TRY(Core::System::unveil("/etc/timezone", "rwc"));
+ TRY(Core::System::unveil(nullptr, nullptr));
+
+ StringView time_zone;
+
+ Core::ArgsParser args_parser;
+ args_parser.add_positional_argument(time_zone, "The time zone to set", "time-zone", Core::ArgsParser::Required::No);
+ args_parser.parse(arguments);
+
+ if (time_zone.is_empty()) {
+ outln("{}", TimeZone::current_time_zone());
+ return 0;
+ }
+
+ TRY(TimeZone::change_time_zone(time_zone));
+ return 0;
+}