set svn:eol-style to native
[reactos.git] / reactos / lib / crt / sys_stat / systime.c
1 #include "precomp.h"
2 #include <sys/time.h>
3
4
5 int month[12] = { 31,28,31,30,31,30,31,31,30,31,30,31};
6
7 /*
8 * @unimplemented
9 */
10 unsigned int _getsystime(struct tm* tp)
11 {
12 SYSTEMTIME Time;
13 int i;
14
15 GetLocalTime(&Time);
16
17 tp->tm_year = Time.wYear - 1900;
18 tp->tm_mon = Time.wMonth - 1;
19 tp->tm_wday = Time.wDayOfWeek;
20 tp->tm_mday = Time.wDay;
21 tp->tm_hour = Time.wHour;
22 tp->tm_min = Time.wMinute;
23 tp->tm_sec = Time.wSecond;
24
25 tp->tm_isdst = -1;
26
27 //FIXME GetTimeZoneInformation currently not in kernel32
28
29 //TimeZoneId = GetTimeZoneInformation(&TimeZoneInformation );
30 //if ( TimeZoneId == TIME_ZONE_ID_DAYLIGHT ) {
31 // tp->tm_isdst = 1;
32 //}
33 //else
34 // tp->tm_isdst = 0;
35
36 if (tp->tm_year % 4 == 0) {
37 if (tp->tm_year % 100 != 0)
38 tp->tm_yday = 1;
39 else if ((tp->tm_year-100) % 1000 == 0)
40 tp->tm_yday = 1;
41 }
42
43 for (i = 0; i <= tp->tm_mon; i++)
44 tp->tm_yday += month[i];
45
46 return Time.wMilliseconds;
47 }
48
49
50 /*
51 * @implemented
52 */
53 unsigned int _setsystime(struct tm* tp, unsigned int ms)
54 {
55 SYSTEMTIME Time;
56
57 Time.wYear = tp->tm_year + 1900;
58 Time.wMonth = tp->tm_mon + 1;
59 Time.wDayOfWeek = tp->tm_wday;
60 Time.wDay = tp->tm_mday;
61 Time.wHour = tp->tm_hour;
62 Time.wMinute = tp->tm_min;
63 Time.wSecond = tp->tm_sec;
64 Time.wMilliseconds = ms;
65
66 if (!SetLocalTime(&Time))
67 return -1;
68
69 return 0;
70 }