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