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