c10337a63ec248e32584c13f9b7c77488c91e3ad
[reactos.git] / reactos / lib / sdk / crt / time_new / localtime.c
1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS CRT library
4 * FILE: lib/sdk/crt/time/localtime.c
5 * PURPOSE: Implementation of localtime, localtime_s
6 * PROGRAMERS: Timo Kreuzer
7 */
8 #include <precomp.h>
9 #include <time.h>
10 #include "bitsfixup.h"
11
12 errno_t
13 localtime_s(struct tm* _tm, const time_t *ptime)
14 {
15
16 /* Validate parameters */
17 if (!_tm || !ptime)
18 {
19 _invalid_parameter(NULL,
20 0,//__FUNCTION__,
21 _CRT_WIDE(__FILE__),
22 __LINE__,
23 0);
24 return EINVAL;
25 }
26
27
28 return 0;
29 }
30
31 extern char _tz_is_set;
32
33 struct tm *
34 localtime(const time_t *ptime)
35 {
36 time_t time = *ptime;
37 struct tm * ptm;
38
39 /* Check for invalid time value */
40 if (time < 0)
41 {
42 return 0;
43 }
44
45 /* Never without */
46 if (!_tz_is_set)
47 _tzset();
48
49 /* Check for overflow */
50
51 /* Correct for timezone */
52 time -= _timezone;
53 #if 0
54 /* Correct for daylight saving */
55 if (_isdstime(time))
56 {
57 ptm->tm_isdst = 1;
58 time -= _dstbias;
59 }
60 #endif
61 ptm = gmtime(&time);
62
63 return ptm;
64 }
65