summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibC
diff options
context:
space:
mode:
authorTimothy Flynn <trflynn89@pm.me>2022-01-20 12:34:26 -0500
committerLinus Groh <mail@linusgroh.de>2022-01-23 12:48:26 +0000
commit2bdc3aec4222218a4058aaa7d93e04e5e635cbbd (patch)
treec848a12306244c59ae04b16825caa6e85a5962a5 /Userland/Libraries/LibC
parent7f1404b870ab7c721a7add2331bf9422993ff840 (diff)
downloadserenity-2bdc3aec4222218a4058aaa7d93e04e5e635cbbd.zip
LibC: Use LibTimeZone to offset localtime() for the system time zone
Diffstat (limited to 'Userland/Libraries/LibC')
-rw-r--r--Userland/Libraries/LibC/time.cpp12
1 files changed, 10 insertions, 2 deletions
diff --git a/Userland/Libraries/LibC/time.cpp b/Userland/Libraries/LibC/time.cpp
index 3cf77b7889..83f8f89156 100644
--- a/Userland/Libraries/LibC/time.cpp
+++ b/Userland/Libraries/LibC/time.cpp
@@ -8,6 +8,7 @@
#include <AK/StringBuilder.h>
#include <AK/Time.h>
#include <Kernel/API/TimePage.h>
+#include <LibTimeZone/TimeZone.h>
#include <assert.h>
#include <errno.h>
#include <stdio.h>
@@ -155,7 +156,14 @@ struct tm* localtime_r(const time_t* t, struct tm* tm)
{
if (!t)
return nullptr;
- time_to_tm(tm, (*t) - timezone);
+
+ auto time_zone = TimeZone::current_time_zone();
+ auto time = AK::Time::from_seconds(*t);
+
+ if (auto offset = TimeZone::get_time_zone_offset(time_zone, time); offset.has_value())
+ time += AK::Time::from_seconds(offset->seconds);
+
+ time_to_tm(tm, time.to_seconds());
return tm;
}
@@ -196,7 +204,7 @@ char* asctime_r(const struct tm* tm, char* buffer)
return buffer;
}
-//FIXME: Some formats are not supported.
+// FIXME: Some formats are not supported.
size_t strftime(char* destination, size_t max_size, const char* format, const struct tm* tm)
{
const char wday_short_names[7][4] = {