Sync to trunk r38200
[reactos.git] / reactos / lib / sdk / crt / sys_stat / systime.c
1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS system libraries
4 * FILE: lib/crt/??????
5 * PURPOSE: Unknown
6 * PROGRAMER: Unknown
7 * UPDATE HISTORY:
8 * 25/11/05: Added license header
9 */
10
11 #include <precomp.h>
12
13 int month[12] = { 31,28,31,30,31,30,31,31,30,31,30,31};
14
15 /*
16 * @unimplemented
17 */
18 unsigned int _getsystime(struct tm* tp)
19 {
20 SYSTEMTIME Time;
21 int i;
22 DWORD TimeZoneId;
23 TIME_ZONE_INFORMATION TimeZoneInformation;
24
25 GetLocalTime(&Time);
26
27 tp->tm_year = Time.wYear - 1900;
28 tp->tm_mon = Time.wMonth - 1;
29 tp->tm_wday = Time.wDayOfWeek;
30 tp->tm_mday = Time.wDay;
31 tp->tm_hour = Time.wHour;
32 tp->tm_min = Time.wMinute;
33 tp->tm_sec = Time.wSecond;
34
35 tp->tm_isdst = -1;
36
37 TimeZoneId = GetTimeZoneInformation(&TimeZoneInformation);
38 if (TimeZoneId == TIME_ZONE_ID_DAYLIGHT){
39 tp->tm_isdst = 1;
40 }
41 else
42 tp->tm_isdst = 0;
43
44 if (tp->tm_year % 4 == 0) {
45 if (tp->tm_year % 100 != 0)
46 tp->tm_yday = 1;
47 else if ((tp->tm_year-100) % 1000 == 0)
48 tp->tm_yday = 1;
49 }
50
51 for (i = 0; i <= tp->tm_mon; i++)
52 tp->tm_yday += month[i];
53
54 return Time.wMilliseconds;
55 }
56
57
58 /*
59 * @implemented
60 */
61 unsigned int _setsystime(struct tm* tp, unsigned int ms)
62 {
63 SYSTEMTIME Time;
64
65 Time.wYear = tp->tm_year + 1900;
66 Time.wMonth = tp->tm_mon + 1;
67 Time.wDayOfWeek = tp->tm_wday;
68 Time.wDay = tp->tm_mday;
69 Time.wHour = tp->tm_hour;
70 Time.wMinute = tp->tm_min;
71 Time.wSecond = tp->tm_sec;
72 Time.wMilliseconds = ms;
73
74 if (!SetLocalTime(&Time))
75 return -1;
76
77 return 0;
78 }