mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 06:17:35 +00:00
LibC: Use LibTimeZone to offset localtime() for the system time zone
This commit is contained in:
parent
7f1404b870
commit
2bdc3aec42
1 changed files with 10 additions and 2 deletions
|
@ -8,6 +8,7 @@
|
||||||
#include <AK/StringBuilder.h>
|
#include <AK/StringBuilder.h>
|
||||||
#include <AK/Time.h>
|
#include <AK/Time.h>
|
||||||
#include <Kernel/API/TimePage.h>
|
#include <Kernel/API/TimePage.h>
|
||||||
|
#include <LibTimeZone/TimeZone.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
@ -155,7 +156,14 @@ struct tm* localtime_r(const time_t* t, struct tm* tm)
|
||||||
{
|
{
|
||||||
if (!t)
|
if (!t)
|
||||||
return nullptr;
|
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;
|
return tm;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue