Skip to content

Commit 7cbab8a

Browse files
committed
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.
1 parent 5a3a4c6 commit 7cbab8a

File tree

2 files changed

+47
-28
lines changed

2 files changed

+47
-28
lines changed

functions/time/localtime.c

-28
This file was deleted.
+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/* localtime( const time_t * )
2+
3+
This file is part of the Public Domain C Library (PDCLib).
4+
Permission is granted to use, modify, and / or redistribute at will.
5+
*/
6+
7+
#include <time.h>
8+
#include <timezoneapi.h>
9+
10+
#ifndef REGTEST
11+
12+
struct tm * localtime( const time_t * timer )
13+
{
14+
TIME_ZONE_INFORMATION tzinfo;
15+
DWORD tz = GetTimeZoneInformation( &tzinfo );
16+
17+
if ( tz == TIME_ZONE_ID_INVALID )
18+
{
19+
return NULL;
20+
}
21+
if ( tz == TIME_ZONE_ID_STANDARD )
22+
{
23+
tzinfo.Bias += tzinfo.StandardBias;
24+
}
25+
else if ( tz == TIME_ZONE_ID_DAYLIGHT )
26+
{
27+
tzinfo.Bias += tzinfo.DaylightBias;
28+
}
29+
30+
time_t ltimer = *timer - tzinfo.Bias * 60;
31+
32+
return gmtime( &ltimer );
33+
}
34+
35+
#endif
36+
37+
#ifdef TEST
38+
39+
#include "_PDCLIB_test.h"
40+
41+
int main( void )
42+
{
43+
TESTCASE( NO_TESTDRIVER );
44+
return TEST_RESULTS;
45+
}
46+
47+
#endif

0 commit comments

Comments
 (0)