:pserver:cvsanon@mok.lvcm.com:/CVS/ReactOS reactos
[reactos.git] / lib / crtdll / sys_stat / systime.c
1 #include <windows.h>
2 #include <crtdll/sys/time.h>
3
4
5 int month[12] = { 31,28,31,30,31,30,31,31,30,31,30,31};
6 unsigned int _getsystime(struct tm *tp)
7 {
8         SYSTEMTIME Time;
9         TIME_ZONE_INFORMATION  TimeZoneInformation;
10         DWORD TimeZoneId;
11         int i;
12
13         GetLocalTime(&Time);
14
15         tp->tm_year = Time.wYear - 1900; 
16         tp->tm_mon = Time.wMonth - 1; 
17         tp->tm_wday = Time.wDayOfWeek; 
18         tp->tm_mday = Time.wDay; 
19         tp->tm_hour = Time.wHour; 
20         tp->tm_min = Time.wMinute; 
21         tp->tm_sec = Time.wSecond; 
22
23         tp->tm_isdst = -1;
24
25         //FIXME GetTimeZoneInformation currently not in kernel32
26
27         //TimeZoneId =  GetTimeZoneInformation(&TimeZoneInformation );
28         //if ( TimeZoneId == TIME_ZONE_ID_DAYLIGHT ) {
29         //      tp->tm_isdst = 1;
30         //}
31         //else
32         //      tp->tm_isdst = 0;
33                 
34                         
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 unsigned int _setsystime(struct tm *tp, unsigned int ms)
51 {
52         SYSTEMTIME Time;
53
54         Time.wYear = tp->tm_year + 1900; 
55         Time.wMonth = tp->tm_mon + 1; 
56         Time.wDayOfWeek = tp->tm_wday; 
57         Time.wDay = tp->tm_mday; 
58         Time.wHour = tp->tm_hour; 
59         Time.wMinute = tp->tm_min; 
60         Time.wSecond = tp->tm_sec; 
61         Time.wMilliseconds = ms;
62
63         if ( !SetLocalTime(&Time))
64                 return -1;
65
66         return 0;
67 }