Skip to content

Commit b840a59

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 b840a59

File tree

2 files changed

+49
-28
lines changed

2 files changed

+49
-28
lines changed

functions/time/localtime.c

-28
This file was deleted.
+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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+
struct tm * ret = gmtime( &ltimer );
33+
34+
return ret;
35+
}
36+
37+
#endif
38+
39+
#ifdef TEST
40+
41+
#include "_PDCLIB_test.h"
42+
43+
int main( void )
44+
{
45+
TESTCASE( NO_TESTDRIVER );
46+
return TEST_RESULTS;
47+
}
48+
49+
#endif

0 commit comments

Comments
 (0)