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/rtl/time.c
5*c2c66affSColin Finck * PURPOSE: Conversion between Time and TimeFields
6*c2c66affSColin Finck * PROGRAMMER: Rex Jolliff (rex@lvcablemodem.com)
7*c2c66affSColin Finck */
8*c2c66affSColin Finck
9*c2c66affSColin Finck /* INCLUDES *****************************************************************/
10*c2c66affSColin Finck
11*c2c66affSColin Finck #include <rtl.h>
12*c2c66affSColin Finck
13*c2c66affSColin Finck #define NDEBUG
14*c2c66affSColin Finck #include <debug.h>
15*c2c66affSColin Finck
16*c2c66affSColin Finck #define TICKSPERMIN 600000000
17*c2c66affSColin Finck #define TICKSPERSEC 10000000
18*c2c66affSColin Finck #define TICKSPERMSEC 10000
19*c2c66affSColin Finck #define SECSPERDAY 86400
20*c2c66affSColin Finck #define SECSPERHOUR 3600
21*c2c66affSColin Finck #define SECSPERMIN 60
22*c2c66affSColin Finck #define MINSPERHOUR 60
23*c2c66affSColin Finck #define HOURSPERDAY 24
24*c2c66affSColin Finck #define EPOCHWEEKDAY 1
25*c2c66affSColin Finck #define DAYSPERWEEK 7
26*c2c66affSColin Finck #define EPOCHYEAR 1601
27*c2c66affSColin Finck #define DAYSPERNORMALYEAR 365
28*c2c66affSColin Finck #define DAYSPERLEAPYEAR 366
29*c2c66affSColin Finck #define MONSPERYEAR 12
30*c2c66affSColin Finck
31*c2c66affSColin Finck #if defined(__GNUC__)
32*c2c66affSColin Finck #define TICKSTO1970 0x019db1ded53e8000LL
33*c2c66affSColin Finck #define TICKSTO1980 0x01a8e79fe1d58000LL
34*c2c66affSColin Finck #else
35*c2c66affSColin Finck #define TICKSTO1970 0x019db1ded53e8000i64
36*c2c66affSColin Finck #define TICKSTO1980 0x01a8e79fe1d58000i64
37*c2c66affSColin Finck #endif
38*c2c66affSColin Finck
39*c2c66affSColin Finck
40*c2c66affSColin Finck static const unsigned int YearLengths[2] =
41*c2c66affSColin Finck {
42*c2c66affSColin Finck DAYSPERNORMALYEAR, DAYSPERLEAPYEAR
43*c2c66affSColin Finck };
44*c2c66affSColin Finck static const UCHAR MonthLengths[2][MONSPERYEAR] =
45*c2c66affSColin Finck {
46*c2c66affSColin Finck { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 },
47*c2c66affSColin Finck { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }
48*c2c66affSColin Finck };
49*c2c66affSColin Finck
IsLeapYear(int Year)50*c2c66affSColin Finck static __inline int IsLeapYear(int Year)
51*c2c66affSColin Finck {
52*c2c66affSColin Finck return Year % 4 == 0 && (Year % 100 != 0 || Year % 400 == 0) ? 1 : 0;
53*c2c66affSColin Finck }
54*c2c66affSColin Finck
DaysSinceEpoch(int Year)55*c2c66affSColin Finck static int DaysSinceEpoch(int Year)
56*c2c66affSColin Finck {
57*c2c66affSColin Finck int Days;
58*c2c66affSColin Finck Year--; /* Don't include a leap day from the current year */
59*c2c66affSColin Finck Days = Year * DAYSPERNORMALYEAR + Year / 4 - Year / 100 + Year / 400;
60*c2c66affSColin Finck Days -= (EPOCHYEAR - 1) * DAYSPERNORMALYEAR + (EPOCHYEAR - 1) / 4 - (EPOCHYEAR - 1) / 100 + (EPOCHYEAR - 1) / 400;
61*c2c66affSColin Finck return Days;
62*c2c66affSColin Finck }
63*c2c66affSColin Finck
64*c2c66affSColin Finck /* FUNCTIONS *****************************************************************/
65*c2c66affSColin Finck
66*c2c66affSColin Finck /*
67*c2c66affSColin Finck * @implemented
68*c2c66affSColin Finck */
69*c2c66affSColin Finck BOOLEAN NTAPI
RtlCutoverTimeToSystemTime(IN PTIME_FIELDS CutoverTimeFields,OUT PLARGE_INTEGER SystemTime,IN PLARGE_INTEGER CurrentTime,IN BOOLEAN ThisYearsCutoverOnly)70*c2c66affSColin Finck RtlCutoverTimeToSystemTime(IN PTIME_FIELDS CutoverTimeFields,
71*c2c66affSColin Finck OUT PLARGE_INTEGER SystemTime,
72*c2c66affSColin Finck IN PLARGE_INTEGER CurrentTime,
73*c2c66affSColin Finck IN BOOLEAN ThisYearsCutoverOnly)
74*c2c66affSColin Finck {
75*c2c66affSColin Finck TIME_FIELDS AdjustedTimeFields;
76*c2c66affSColin Finck TIME_FIELDS CurrentTimeFields;
77*c2c66affSColin Finck TIME_FIELDS CutoverSystemTimeFields;
78*c2c66affSColin Finck LARGE_INTEGER CutoverSystemTime;
79*c2c66affSColin Finck UCHAR MonthLength;
80*c2c66affSColin Finck CSHORT Days;
81*c2c66affSColin Finck BOOLEAN NextYearsCutover = FALSE;
82*c2c66affSColin Finck
83*c2c66affSColin Finck /* Check fixed cutover time */
84*c2c66affSColin Finck if (CutoverTimeFields->Year != 0)
85*c2c66affSColin Finck {
86*c2c66affSColin Finck if (!RtlTimeFieldsToTime(CutoverTimeFields, SystemTime))
87*c2c66affSColin Finck return FALSE;
88*c2c66affSColin Finck
89*c2c66affSColin Finck if (SystemTime->QuadPart < CurrentTime->QuadPart)
90*c2c66affSColin Finck return FALSE;
91*c2c66affSColin Finck
92*c2c66affSColin Finck return TRUE;
93*c2c66affSColin Finck }
94*c2c66affSColin Finck
95*c2c66affSColin Finck /*
96*c2c66affSColin Finck * Compute recurring cutover time
97*c2c66affSColin Finck */
98*c2c66affSColin Finck
99*c2c66affSColin Finck /* Day must be between 1(first) and 5(last) */
100*c2c66affSColin Finck if (CutoverTimeFields->Day == 0 || CutoverTimeFields->Day > 5)
101*c2c66affSColin Finck return FALSE;
102*c2c66affSColin Finck
103*c2c66affSColin Finck RtlTimeToTimeFields(CurrentTime, &CurrentTimeFields);
104*c2c66affSColin Finck
105*c2c66affSColin Finck while (TRUE)
106*c2c66affSColin Finck {
107*c2c66affSColin Finck /* Compute the cutover time of the first day of the current month */
108*c2c66affSColin Finck AdjustedTimeFields.Year = CurrentTimeFields.Year;
109*c2c66affSColin Finck if (NextYearsCutover)
110*c2c66affSColin Finck AdjustedTimeFields.Year++;
111*c2c66affSColin Finck
112*c2c66affSColin Finck AdjustedTimeFields.Month = CutoverTimeFields->Month;
113*c2c66affSColin Finck AdjustedTimeFields.Day = 1;
114*c2c66affSColin Finck AdjustedTimeFields.Hour = CutoverTimeFields->Hour;
115*c2c66affSColin Finck AdjustedTimeFields.Minute = CutoverTimeFields->Minute;
116*c2c66affSColin Finck AdjustedTimeFields.Second = CutoverTimeFields->Second;
117*c2c66affSColin Finck AdjustedTimeFields.Milliseconds = CutoverTimeFields->Milliseconds;
118*c2c66affSColin Finck
119*c2c66affSColin Finck if (!RtlTimeFieldsToTime(&AdjustedTimeFields, &CutoverSystemTime))
120*c2c66affSColin Finck return FALSE;
121*c2c66affSColin Finck
122*c2c66affSColin Finck RtlTimeToTimeFields(&CutoverSystemTime, &CutoverSystemTimeFields);
123*c2c66affSColin Finck
124*c2c66affSColin Finck /* Adjust day to first matching weekday */
125*c2c66affSColin Finck if (CutoverSystemTimeFields.Weekday != CutoverTimeFields->Weekday)
126*c2c66affSColin Finck {
127*c2c66affSColin Finck if (CutoverSystemTimeFields.Weekday < CutoverTimeFields->Weekday)
128*c2c66affSColin Finck Days = CutoverTimeFields->Weekday - CutoverSystemTimeFields.Weekday;
129*c2c66affSColin Finck else
130*c2c66affSColin Finck Days = DAYSPERWEEK - (CutoverSystemTimeFields.Weekday - CutoverTimeFields->Weekday);
131*c2c66affSColin Finck
132*c2c66affSColin Finck AdjustedTimeFields.Day += Days;
133*c2c66affSColin Finck }
134*c2c66affSColin Finck
135*c2c66affSColin Finck /* Adjust the number of weeks */
136*c2c66affSColin Finck if (CutoverTimeFields->Day > 1)
137*c2c66affSColin Finck {
138*c2c66affSColin Finck Days = DAYSPERWEEK * (CutoverTimeFields->Day - 1);
139*c2c66affSColin Finck MonthLength = MonthLengths[IsLeapYear(AdjustedTimeFields.Year)][AdjustedTimeFields.Month - 1];
140*c2c66affSColin Finck if ((AdjustedTimeFields.Day + Days) > MonthLength)
141*c2c66affSColin Finck Days -= DAYSPERWEEK;
142*c2c66affSColin Finck
143*c2c66affSColin Finck AdjustedTimeFields.Day += Days;
144*c2c66affSColin Finck }
145*c2c66affSColin Finck
146*c2c66affSColin Finck if (!RtlTimeFieldsToTime(&AdjustedTimeFields, &CutoverSystemTime))
147*c2c66affSColin Finck return FALSE;
148*c2c66affSColin Finck
149*c2c66affSColin Finck if (ThisYearsCutoverOnly ||
150*c2c66affSColin Finck NextYearsCutover ||
151*c2c66affSColin Finck CutoverSystemTime.QuadPart >= CurrentTime->QuadPart)
152*c2c66affSColin Finck {
153*c2c66affSColin Finck break;
154*c2c66affSColin Finck }
155*c2c66affSColin Finck
156*c2c66affSColin Finck NextYearsCutover = TRUE;
157*c2c66affSColin Finck }
158*c2c66affSColin Finck
159*c2c66affSColin Finck SystemTime->QuadPart = CutoverSystemTime.QuadPart;
160*c2c66affSColin Finck
161*c2c66affSColin Finck return TRUE;
162*c2c66affSColin Finck }
163*c2c66affSColin Finck
164*c2c66affSColin Finck
165*c2c66affSColin Finck /*
166*c2c66affSColin Finck * @implemented
167*c2c66affSColin Finck */
168*c2c66affSColin Finck BOOLEAN
169*c2c66affSColin Finck NTAPI
RtlTimeFieldsToTime(IN PTIME_FIELDS TimeFields,OUT PLARGE_INTEGER Time)170*c2c66affSColin Finck RtlTimeFieldsToTime(IN PTIME_FIELDS TimeFields,
171*c2c66affSColin Finck OUT PLARGE_INTEGER Time)
172*c2c66affSColin Finck {
173*c2c66affSColin Finck ULONG CurMonth;
174*c2c66affSColin Finck TIME_FIELDS IntTimeFields;
175*c2c66affSColin Finck
176*c2c66affSColin Finck RtlCopyMemory(&IntTimeFields,
177*c2c66affSColin Finck TimeFields,
178*c2c66affSColin Finck sizeof(TIME_FIELDS));
179*c2c66affSColin Finck
180*c2c66affSColin Finck if (TimeFields->Milliseconds < 0 || TimeFields->Milliseconds > 999 ||
181*c2c66affSColin Finck TimeFields->Second < 0 || TimeFields->Second > 59 ||
182*c2c66affSColin Finck TimeFields->Minute < 0 || TimeFields->Minute > 59 ||
183*c2c66affSColin Finck TimeFields->Hour < 0 || TimeFields->Hour > 23 ||
184*c2c66affSColin Finck TimeFields->Month < 1 || TimeFields->Month > 12 ||
185*c2c66affSColin Finck TimeFields->Day < 1 ||
186*c2c66affSColin Finck TimeFields->Day >
187*c2c66affSColin Finck MonthLengths[IsLeapYear(TimeFields->Year)][TimeFields->Month - 1] ||
188*c2c66affSColin Finck TimeFields->Year < 1601)
189*c2c66affSColin Finck {
190*c2c66affSColin Finck return FALSE;
191*c2c66affSColin Finck }
192*c2c66affSColin Finck
193*c2c66affSColin Finck /* Compute the time */
194*c2c66affSColin Finck Time->QuadPart = DaysSinceEpoch(IntTimeFields.Year);
195*c2c66affSColin Finck for (CurMonth = 1; CurMonth < IntTimeFields.Month; CurMonth++)
196*c2c66affSColin Finck {
197*c2c66affSColin Finck Time->QuadPart += MonthLengths[IsLeapYear(IntTimeFields.Year)][CurMonth - 1];
198*c2c66affSColin Finck }
199*c2c66affSColin Finck Time->QuadPart += IntTimeFields.Day - 1;
200*c2c66affSColin Finck Time->QuadPart *= SECSPERDAY;
201*c2c66affSColin Finck Time->QuadPart += IntTimeFields.Hour * SECSPERHOUR + IntTimeFields.Minute * SECSPERMIN +
202*c2c66affSColin Finck IntTimeFields.Second;
203*c2c66affSColin Finck Time->QuadPart *= TICKSPERSEC;
204*c2c66affSColin Finck Time->QuadPart += IntTimeFields.Milliseconds * TICKSPERMSEC;
205*c2c66affSColin Finck
206*c2c66affSColin Finck return TRUE;
207*c2c66affSColin Finck }
208*c2c66affSColin Finck
209*c2c66affSColin Finck
210*c2c66affSColin Finck /*
211*c2c66affSColin Finck * @implemented
212*c2c66affSColin Finck */
213*c2c66affSColin Finck VOID
214*c2c66affSColin Finck NTAPI
RtlTimeToElapsedTimeFields(IN PLARGE_INTEGER Time,OUT PTIME_FIELDS TimeFields)215*c2c66affSColin Finck RtlTimeToElapsedTimeFields(IN PLARGE_INTEGER Time,
216*c2c66affSColin Finck OUT PTIME_FIELDS TimeFields)
217*c2c66affSColin Finck {
218*c2c66affSColin Finck ULONGLONG ElapsedSeconds;
219*c2c66affSColin Finck ULONG SecondsInDay;
220*c2c66affSColin Finck ULONG SecondsInMinute;
221*c2c66affSColin Finck
222*c2c66affSColin Finck /* Extract millisecond from time */
223*c2c66affSColin Finck TimeFields->Milliseconds = (CSHORT)((Time->QuadPart % TICKSPERSEC) / TICKSPERMSEC);
224*c2c66affSColin Finck
225*c2c66affSColin Finck /* Compute elapsed seconds */
226*c2c66affSColin Finck ElapsedSeconds = (ULONGLONG)Time->QuadPart / TICKSPERSEC;
227*c2c66affSColin Finck
228*c2c66affSColin Finck /* Compute seconds within the day */
229*c2c66affSColin Finck SecondsInDay = ElapsedSeconds % SECSPERDAY;
230*c2c66affSColin Finck
231*c2c66affSColin Finck /* Compute elapsed minutes within the day */
232*c2c66affSColin Finck SecondsInMinute = SecondsInDay % SECSPERHOUR;
233*c2c66affSColin Finck
234*c2c66affSColin Finck /* Compute elapsed time of day */
235*c2c66affSColin Finck TimeFields->Hour = (CSHORT)(SecondsInDay / SECSPERHOUR);
236*c2c66affSColin Finck TimeFields->Minute = (CSHORT)(SecondsInMinute / SECSPERMIN);
237*c2c66affSColin Finck TimeFields->Second = (CSHORT)(SecondsInMinute % SECSPERMIN);
238*c2c66affSColin Finck
239*c2c66affSColin Finck /* Compute elapsed days */
240*c2c66affSColin Finck TimeFields->Day = (CSHORT)(ElapsedSeconds / SECSPERDAY);
241*c2c66affSColin Finck
242*c2c66affSColin Finck /* The elapsed number of months and days cannot be calculated */
243*c2c66affSColin Finck TimeFields->Month = 0;
244*c2c66affSColin Finck TimeFields->Year = 0;
245*c2c66affSColin Finck }
246*c2c66affSColin Finck
247*c2c66affSColin Finck
248*c2c66affSColin Finck /*
249*c2c66affSColin Finck * @implemented
250*c2c66affSColin Finck */
251*c2c66affSColin Finck VOID
252*c2c66affSColin Finck NTAPI
RtlTimeToTimeFields(IN PLARGE_INTEGER Time,OUT PTIME_FIELDS TimeFields)253*c2c66affSColin Finck RtlTimeToTimeFields(IN PLARGE_INTEGER Time,
254*c2c66affSColin Finck OUT PTIME_FIELDS TimeFields)
255*c2c66affSColin Finck {
256*c2c66affSColin Finck const UCHAR *Months;
257*c2c66affSColin Finck ULONG SecondsInDay, CurYear;
258*c2c66affSColin Finck ULONG LeapYear, CurMonth;
259*c2c66affSColin Finck ULONG Days;
260*c2c66affSColin Finck ULONGLONG IntTime = Time->QuadPart;
261*c2c66affSColin Finck
262*c2c66affSColin Finck /* Extract millisecond from time and convert time into seconds */
263*c2c66affSColin Finck TimeFields->Milliseconds = (CSHORT)((IntTime % TICKSPERSEC) / TICKSPERMSEC);
264*c2c66affSColin Finck IntTime = IntTime / TICKSPERSEC;
265*c2c66affSColin Finck
266*c2c66affSColin Finck /* Split the time into days and seconds within the day */
267*c2c66affSColin Finck Days = (ULONG)(IntTime / SECSPERDAY);
268*c2c66affSColin Finck SecondsInDay = IntTime % SECSPERDAY;
269*c2c66affSColin Finck
270*c2c66affSColin Finck /* Compute time of day */
271*c2c66affSColin Finck TimeFields->Hour = (CSHORT)(SecondsInDay / SECSPERHOUR);
272*c2c66affSColin Finck SecondsInDay = SecondsInDay % SECSPERHOUR;
273*c2c66affSColin Finck TimeFields->Minute = (CSHORT)(SecondsInDay / SECSPERMIN);
274*c2c66affSColin Finck TimeFields->Second = (CSHORT)(SecondsInDay % SECSPERMIN);
275*c2c66affSColin Finck
276*c2c66affSColin Finck /* Compute day of week */
277*c2c66affSColin Finck TimeFields->Weekday = (CSHORT)((EPOCHWEEKDAY + Days) % DAYSPERWEEK);
278*c2c66affSColin Finck
279*c2c66affSColin Finck /* Compute year */
280*c2c66affSColin Finck CurYear = EPOCHYEAR;
281*c2c66affSColin Finck CurYear += Days / DAYSPERLEAPYEAR;
282*c2c66affSColin Finck Days -= DaysSinceEpoch(CurYear);
283*c2c66affSColin Finck while (TRUE)
284*c2c66affSColin Finck {
285*c2c66affSColin Finck LeapYear = IsLeapYear(CurYear);
286*c2c66affSColin Finck if (Days < YearLengths[LeapYear])
287*c2c66affSColin Finck {
288*c2c66affSColin Finck break;
289*c2c66affSColin Finck }
290*c2c66affSColin Finck CurYear++;
291*c2c66affSColin Finck Days = Days - YearLengths[LeapYear];
292*c2c66affSColin Finck }
293*c2c66affSColin Finck TimeFields->Year = (CSHORT)CurYear;
294*c2c66affSColin Finck
295*c2c66affSColin Finck /* Compute month of year */
296*c2c66affSColin Finck LeapYear = IsLeapYear(CurYear);
297*c2c66affSColin Finck Months = MonthLengths[LeapYear];
298*c2c66affSColin Finck for (CurMonth = 0; Days >= Months[CurMonth]; CurMonth++)
299*c2c66affSColin Finck {
300*c2c66affSColin Finck Days = Days - Months[CurMonth];
301*c2c66affSColin Finck }
302*c2c66affSColin Finck TimeFields->Month = (CSHORT)(CurMonth + 1);
303*c2c66affSColin Finck TimeFields->Day = (CSHORT)(Days + 1);
304*c2c66affSColin Finck }
305*c2c66affSColin Finck
306*c2c66affSColin Finck
307*c2c66affSColin Finck /*
308*c2c66affSColin Finck * @implemented
309*c2c66affSColin Finck */
310*c2c66affSColin Finck BOOLEAN
311*c2c66affSColin Finck NTAPI
RtlTimeToSecondsSince1970(IN PLARGE_INTEGER Time,OUT PULONG SecondsSince1970)312*c2c66affSColin Finck RtlTimeToSecondsSince1970(IN PLARGE_INTEGER Time,
313*c2c66affSColin Finck OUT PULONG SecondsSince1970)
314*c2c66affSColin Finck {
315*c2c66affSColin Finck LARGE_INTEGER IntTime;
316*c2c66affSColin Finck
317*c2c66affSColin Finck IntTime.QuadPart = Time->QuadPart - TICKSTO1970;
318*c2c66affSColin Finck IntTime.QuadPart = IntTime.QuadPart / TICKSPERSEC;
319*c2c66affSColin Finck
320*c2c66affSColin Finck if (IntTime.u.HighPart != 0)
321*c2c66affSColin Finck return FALSE;
322*c2c66affSColin Finck
323*c2c66affSColin Finck *SecondsSince1970 = IntTime.u.LowPart;
324*c2c66affSColin Finck
325*c2c66affSColin Finck return TRUE;
326*c2c66affSColin Finck }
327*c2c66affSColin Finck
328*c2c66affSColin Finck
329*c2c66affSColin Finck /*
330*c2c66affSColin Finck * @implemented
331*c2c66affSColin Finck */
332*c2c66affSColin Finck BOOLEAN
333*c2c66affSColin Finck NTAPI
RtlTimeToSecondsSince1980(IN PLARGE_INTEGER Time,OUT PULONG SecondsSince1980)334*c2c66affSColin Finck RtlTimeToSecondsSince1980(IN PLARGE_INTEGER Time,
335*c2c66affSColin Finck OUT PULONG SecondsSince1980)
336*c2c66affSColin Finck {
337*c2c66affSColin Finck LARGE_INTEGER IntTime;
338*c2c66affSColin Finck
339*c2c66affSColin Finck IntTime.QuadPart = Time->QuadPart - TICKSTO1980;
340*c2c66affSColin Finck IntTime.QuadPart = IntTime.QuadPart / TICKSPERSEC;
341*c2c66affSColin Finck
342*c2c66affSColin Finck if (IntTime.u.HighPart != 0)
343*c2c66affSColin Finck return FALSE;
344*c2c66affSColin Finck
345*c2c66affSColin Finck *SecondsSince1980 = IntTime.u.LowPart;
346*c2c66affSColin Finck
347*c2c66affSColin Finck return TRUE;
348*c2c66affSColin Finck }
349*c2c66affSColin Finck
350*c2c66affSColin Finck
351*c2c66affSColin Finck /*
352*c2c66affSColin Finck * @implemented
353*c2c66affSColin Finck */
354*c2c66affSColin Finck NTSTATUS
355*c2c66affSColin Finck NTAPI
RtlLocalTimeToSystemTime(IN PLARGE_INTEGER LocalTime,OUT PLARGE_INTEGER SystemTime)356*c2c66affSColin Finck RtlLocalTimeToSystemTime(IN PLARGE_INTEGER LocalTime,
357*c2c66affSColin Finck OUT PLARGE_INTEGER SystemTime)
358*c2c66affSColin Finck {
359*c2c66affSColin Finck SYSTEM_TIMEOFDAY_INFORMATION TimeInformation;
360*c2c66affSColin Finck NTSTATUS Status;
361*c2c66affSColin Finck
362*c2c66affSColin Finck Status = ZwQuerySystemInformation(SystemTimeOfDayInformation,
363*c2c66affSColin Finck &TimeInformation,
364*c2c66affSColin Finck sizeof(TimeInformation),
365*c2c66affSColin Finck NULL);
366*c2c66affSColin Finck if (!NT_SUCCESS(Status))
367*c2c66affSColin Finck return Status;
368*c2c66affSColin Finck
369*c2c66affSColin Finck SystemTime->QuadPart = LocalTime->QuadPart +
370*c2c66affSColin Finck TimeInformation.TimeZoneBias.QuadPart;
371*c2c66affSColin Finck
372*c2c66affSColin Finck return STATUS_SUCCESS;
373*c2c66affSColin Finck }
374*c2c66affSColin Finck
375*c2c66affSColin Finck
376*c2c66affSColin Finck /*
377*c2c66affSColin Finck * @implemented
378*c2c66affSColin Finck */
379*c2c66affSColin Finck NTSTATUS
380*c2c66affSColin Finck NTAPI
RtlSystemTimeToLocalTime(IN PLARGE_INTEGER SystemTime,OUT PLARGE_INTEGER LocalTime)381*c2c66affSColin Finck RtlSystemTimeToLocalTime(IN PLARGE_INTEGER SystemTime,
382*c2c66affSColin Finck OUT PLARGE_INTEGER LocalTime)
383*c2c66affSColin Finck {
384*c2c66affSColin Finck SYSTEM_TIMEOFDAY_INFORMATION TimeInformation;
385*c2c66affSColin Finck NTSTATUS Status;
386*c2c66affSColin Finck
387*c2c66affSColin Finck Status = ZwQuerySystemInformation(SystemTimeOfDayInformation,
388*c2c66affSColin Finck &TimeInformation,
389*c2c66affSColin Finck sizeof(TimeInformation),
390*c2c66affSColin Finck NULL);
391*c2c66affSColin Finck if (!NT_SUCCESS(Status))
392*c2c66affSColin Finck return Status;
393*c2c66affSColin Finck
394*c2c66affSColin Finck LocalTime->QuadPart = SystemTime->QuadPart -
395*c2c66affSColin Finck TimeInformation.TimeZoneBias.QuadPart;
396*c2c66affSColin Finck
397*c2c66affSColin Finck return STATUS_SUCCESS;
398*c2c66affSColin Finck }
399*c2c66affSColin Finck
400*c2c66affSColin Finck
401*c2c66affSColin Finck /*
402*c2c66affSColin Finck * @implemented
403*c2c66affSColin Finck */
404*c2c66affSColin Finck VOID
405*c2c66affSColin Finck NTAPI
RtlSecondsSince1970ToTime(IN ULONG SecondsSince1970,OUT PLARGE_INTEGER Time)406*c2c66affSColin Finck RtlSecondsSince1970ToTime(IN ULONG SecondsSince1970,
407*c2c66affSColin Finck OUT PLARGE_INTEGER Time)
408*c2c66affSColin Finck {
409*c2c66affSColin Finck Time->QuadPart = ((LONGLONG)SecondsSince1970 * TICKSPERSEC) + TICKSTO1970;
410*c2c66affSColin Finck }
411*c2c66affSColin Finck
412*c2c66affSColin Finck
413*c2c66affSColin Finck /*
414*c2c66affSColin Finck * @implemented
415*c2c66affSColin Finck */
416*c2c66affSColin Finck VOID NTAPI
RtlSecondsSince1980ToTime(IN ULONG SecondsSince1980,OUT PLARGE_INTEGER Time)417*c2c66affSColin Finck RtlSecondsSince1980ToTime(IN ULONG SecondsSince1980,
418*c2c66affSColin Finck OUT PLARGE_INTEGER Time)
419*c2c66affSColin Finck {
420*c2c66affSColin Finck Time->QuadPart = ((LONGLONG)SecondsSince1980 * TICKSPERSEC) + TICKSTO1980;
421*c2c66affSColin Finck }
422*c2c66affSColin Finck
423*c2c66affSColin Finck /* EOF */
424