From 7cbab8a61e6ff858d505cb63c3c7839dbc6df9d4 Mon Sep 17 00:00:00 2001 From: PQCraft <0456523@gmail.com> Date: Mon, 7 Aug 2023 00:58:27 -0400 Subject: [PATCH] Add localtime This makes a call to GetTimeZoneInformation in winapi/timezoneapi.h, offsets the time given by the output of GetTimeZoneInformation, passes it to gmtime, and returns the result from gmtime. --- functions/time/localtime.c | 28 -------------- platform/xbox/functions/time/localtime.c | 47 ++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 28 deletions(-) delete mode 100644 functions/time/localtime.c create mode 100644 platform/xbox/functions/time/localtime.c diff --git a/functions/time/localtime.c b/functions/time/localtime.c deleted file mode 100644 index 91c0618d..00000000 --- a/functions/time/localtime.c +++ /dev/null @@ -1,28 +0,0 @@ -/* localtime( const time_t * ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include - -#ifndef REGTEST - -struct tm * localtime( const time_t * timer ) -{ - return NULL; -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -int main( void ) -{ - TESTCASE( NO_TESTDRIVER ); - return TEST_RESULTS; -} - -#endif diff --git a/platform/xbox/functions/time/localtime.c b/platform/xbox/functions/time/localtime.c new file mode 100644 index 00000000..fc09cf3c --- /dev/null +++ b/platform/xbox/functions/time/localtime.c @@ -0,0 +1,47 @@ +/* localtime( const time_t * ) + + This file is part of the Public Domain C Library (PDCLib). + Permission is granted to use, modify, and / or redistribute at will. +*/ + +#include +#include + +#ifndef REGTEST + +struct tm * localtime( const time_t * timer ) +{ + TIME_ZONE_INFORMATION tzinfo; + DWORD tz = GetTimeZoneInformation( &tzinfo ); + + if ( tz == TIME_ZONE_ID_INVALID ) + { + return NULL; + } + if ( tz == TIME_ZONE_ID_STANDARD ) + { + tzinfo.Bias += tzinfo.StandardBias; + } + else if ( tz == TIME_ZONE_ID_DAYLIGHT ) + { + tzinfo.Bias += tzinfo.DaylightBias; + } + + time_t ltimer = *timer - tzinfo.Bias * 60; + + return gmtime( <imer ); +} + +#endif + +#ifdef TEST + +#include "_PDCLIB_test.h" + +int main( void ) +{ + TESTCASE( NO_TESTDRIVER ); + return TEST_RESULTS; +} + +#endif