update for HEAD-2003091401
[reactos.git] / lib / crtdll / sys_stat / systime.c
1 #include <windows.h>
2 #include <msvcrt/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     TIME_ZONE_INFORMATION TimeZoneInformation;
14     DWORD TimeZoneId;
15     int i;
16
17     GetLocalTime(&Time);
18
19     tp->tm_year = Time.wYear - 1900; 
20     tp->tm_mon = Time.wMonth - 1; 
21     tp->tm_wday = Time.wDayOfWeek; 
22     tp->tm_mday = Time.wDay; 
23     tp->tm_hour = Time.wHour; 
24     tp->tm_min = Time.wMinute; 
25     tp->tm_sec = Time.wSecond; 
26
27     tp->tm_isdst = -1;
28
29     //FIXME GetTimeZoneInformation currently not in kernel32
30
31     //TimeZoneId =  GetTimeZoneInformation(&TimeZoneInformation );
32     //if ( TimeZoneId == TIME_ZONE_ID_DAYLIGHT ) {
33     //  tp->tm_isdst = 1;
34     //}
35     //else
36     //  tp->tm_isdst = 0;
37
38     if (tp->tm_year % 4 == 0) {
39         if (tp->tm_year % 100 != 0)
40             tp->tm_yday = 1;
41         else if ((tp->tm_year-100) % 1000 == 0)
42             tp->tm_yday = 1;
43     }
44
45     for (i = 0; i <= tp->tm_mon; i++)
46         tp->tm_yday += month[i];
47     
48     return Time.wMilliseconds;
49 }
50
51
52 /*
53  * @implemented
54  */
55 unsigned int _setsystime(struct tm* tp, unsigned int ms)
56 {
57     SYSTEMTIME Time;
58
59     Time.wYear = tp->tm_year + 1900; 
60     Time.wMonth = tp->tm_mon + 1; 
61     Time.wDayOfWeek = tp->tm_wday; 
62     Time.wDay = tp->tm_mday; 
63     Time.wHour = tp->tm_hour; 
64     Time.wMinute = tp->tm_min; 
65     Time.wSecond = tp->tm_sec; 
66     Time.wMilliseconds = ms;
67
68     if (!SetLocalTime(&Time))
69         return -1;
70
71     return 0;
72 }