Fixed some issues found by winapi_check.
[wine] / dlls / kernel / time.c
1 /*
2  * Win32 kernel time functions
3  *
4  * Copyright 1995 Martin von Loewis and Cameron Heide
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  */
20
21 #include "config.h"
22
23 #include <string.h>
24 #ifdef HAVE_UNISTD_H
25 # include <unistd.h>
26 #endif
27 #include <stdlib.h>
28 #ifdef HAVE_SYS_TIME_H
29 # include <sys/time.h>
30 #endif
31 #ifdef HAVE_SYS_TIMES_H
32 # include <sys/times.h>
33 #endif
34 #include "file.h"
35 #include "winternl.h"
36 #include "winerror.h"
37 #include "winnls.h"
38 #include "wine/unicode.h"
39 #include "wine/debug.h"
40
41 WINE_DEFAULT_DEBUG_CHANNEL(win32);
42
43 /* maximum time adjustment in seconds for SetLocalTime and SetSystemTime */
44 #define SETTIME_MAX_ADJUST 120
45 #define CALINFO_MAX_YEAR 2029
46
47
48 /***********************************************************************
49  *              SetLocalTime            (KERNEL32.@)
50  *
51  *  Sets the local time using current time zone and daylight
52  *  savings settings.
53  *
54  * RETURNS
55  *
56  *  True if the time was set, false if the time was invalid or the
57  *  necessary permissions were not held.
58  */
59 BOOL WINAPI SetLocalTime(
60     const SYSTEMTIME *systime) /* [in] The desired local time. */
61 {
62     FILETIME ft;
63     LARGE_INTEGER st, st2;
64     NTSTATUS status;
65
66     SystemTimeToFileTime( systime, &ft );
67     st.s.LowPart = ft.dwLowDateTime;
68     st.s.HighPart = ft.dwHighDateTime;
69     RtlLocalTimeToSystemTime( &st, &st2 );
70
71     if ((status = NtSetSystemTime(&st2, NULL)))
72         SetLastError( RtlNtStatusToDosError(status) );
73     return !status;
74 }
75
76
77 /***********************************************************************
78  *           GetSystemTimeAdjustment     (KERNEL32.@)
79  *
80  *  Indicates the period between clock interrupt and the amount the clock
81  *  is adjusted each interrupt so as to keep it insync with an external source.
82  *
83  * RETURNS
84  *
85  *  Always returns true.
86  *
87  * BUGS
88  *
89  *  Only the special case of disabled time adjustments is supported.
90  */
91 BOOL WINAPI GetSystemTimeAdjustment(
92     PDWORD lpTimeAdjustment,         /* [out] The clock adjustment per interupt in 100's of nanoseconds. */
93     PDWORD lpTimeIncrement,          /* [out] The time between clock interupts in 100's of nanoseconds. */
94     PBOOL  lpTimeAdjustmentDisabled) /* [out] The clock synchonisation has been disabled. */
95 {
96     *lpTimeAdjustment = 0;
97     *lpTimeIncrement = 0;
98     *lpTimeAdjustmentDisabled = TRUE;
99     return TRUE;
100 }
101
102
103 /***********************************************************************
104  *              SetSystemTime            (KERNEL32.@)
105  *
106  *  Sets the system time (utc).
107  *
108  * RETURNS
109  *
110  *  True if the time was set, false if the time was invalid or the
111  *  necessary permissions were not held.
112  */
113 BOOL WINAPI SetSystemTime(
114     const SYSTEMTIME *systime) /* [in] The desired system time. */
115 {
116     FILETIME ft;
117     LARGE_INTEGER t;
118     NTSTATUS status;
119
120     SystemTimeToFileTime( systime, &ft );
121     t.s.LowPart = ft.dwLowDateTime;
122     t.s.HighPart = ft.dwHighDateTime;
123     if ((status = NtSetSystemTime(&t, NULL)))
124         SetLastError( RtlNtStatusToDosError(status) );
125     return !status;
126 }
127
128
129 /***********************************************************************
130  *              GetTimeZoneInformation  (KERNEL32.@)
131  *
132  *  Fills in the a time zone information structure with values based on
133  *  the current local time.
134  *
135  * RETURNS
136  *
137  *  The daylight savings time standard or TIME_ZONE_ID_INVALID if the call failed.
138  */
139 DWORD WINAPI GetTimeZoneInformation(
140     LPTIME_ZONE_INFORMATION tzinfo) /* [out] The time zone structure to be filled in. */
141 {
142     NTSTATUS status;
143     if ((status = RtlQueryTimeZoneInformation(tzinfo)))
144         SetLastError( RtlNtStatusToDosError(status) );
145     return TIME_ZONE_ID_STANDARD;
146 }
147
148
149 /***********************************************************************
150  *              SetTimeZoneInformation  (KERNEL32.@)
151  *
152  *  Set the local time zone with values based on the time zone structure.
153  *
154  * RETURNS
155  *
156  *  True on successful setting of the time zone.
157  */
158 BOOL WINAPI SetTimeZoneInformation(
159     const LPTIME_ZONE_INFORMATION tzinfo) /* [in] The new time zone. */
160 {
161     NTSTATUS status;
162     if ((status = RtlSetTimeZoneInformation(tzinfo)))
163         SetLastError( RtlNtStatusToDosError(status) );
164     return !status;
165 }
166
167
168 /***********************************************************************
169  *  _DayLightCompareDate
170  *
171  *  Compares two dates without looking at the year
172  *
173  * RETURNS
174  *
175  *  -1 if date < compareDate
176  *   0 if date == compareDate
177  *   1 if date > compareDate
178  *  -2 if an error occures
179  */
180
181 static int _DayLightCompareDate(
182     const LPSYSTEMTIME date,                       /* [in] The date to compare. */
183     const LPSYSTEMTIME compareDate)                /* [in] The daylight saving begin or end date */
184 {
185     int limit_day;
186
187     if (compareDate->wYear != 0)
188     {
189         if (date->wMonth < compareDate->wMonth)
190             return -1; /* We are in a year before the date limit. */
191
192         if (date->wMonth > compareDate->wMonth)
193             return 1; /* We are in a year after the date limit. */
194     }
195
196     if (date->wMonth < compareDate->wMonth)
197         return -1; /* We are in a month before the date limit. */
198
199     if (date->wMonth > compareDate->wMonth)
200         return 1; /* We are in a month after the date limit. */
201
202     if (compareDate->wDayOfWeek <= 6)
203     {
204        SYSTEMTIME tmp;
205        FILETIME tmp_ft;
206
207        /* compareDate->wDay is interpreted as number of the week in the month. */
208        /* 5 means: the last week in the month */
209        int weekofmonth = compareDate->wDay;
210
211          /* calculate day of week for the first day in the month */
212         memcpy(&tmp, date, sizeof(SYSTEMTIME));
213         tmp.wDay = 1;
214         tmp.wDayOfWeek = -1;
215
216         if (weekofmonth == 5)
217         {
218              /* Go to the beginning of the next month. */
219             if (++tmp.wMonth > 12)
220             {
221                 tmp.wMonth = 1;
222                 ++tmp.wYear;
223             }
224         }
225
226         if (!SystemTimeToFileTime(&tmp, &tmp_ft))
227             return -2;
228
229         if (weekofmonth == 5)
230         {
231           LONGLONG t, one_day;
232
233           t = tmp_ft.dwHighDateTime;
234           t <<= 32;
235           t += (UINT)tmp_ft.dwLowDateTime;
236
237           /* substract one day */
238           one_day = 24*60*60;
239           one_day *= 10000000;
240           t -= one_day;
241
242           tmp_ft.dwLowDateTime  = (UINT)t;
243           tmp_ft.dwHighDateTime = (UINT)(t >> 32);
244         }
245
246         if (!FileTimeToSystemTime(&tmp_ft, &tmp))
247             return -2;
248
249        if (weekofmonth == 5)
250        {
251           /* calculate the last matching day of the week in this month */
252           int dif = tmp.wDayOfWeek - compareDate->wDayOfWeek;
253           if (dif < 0)
254              dif += 7;
255
256           limit_day = tmp.wDay - dif;
257        }
258        else
259        {
260           /* calulcate the matching day of the week in the given week */
261           int dif = compareDate->wDayOfWeek - tmp.wDayOfWeek;
262           if (dif < 0)
263              dif += 7;
264
265           limit_day = tmp.wDay + 7*(weekofmonth-1) + dif;
266        }
267     }
268     else
269     {
270        limit_day = compareDate->wDay;
271     }
272
273     if (date->wDay < limit_day)
274         return -1;
275
276     if (date->wDay > limit_day)
277         return 1;
278
279     return 0;   /* date is equal to the date limit. */
280 }
281
282
283 /***********************************************************************
284  *  _GetTimezoneBias
285  *
286  *  Calculates the local time bias for a given time zone
287  *
288  * RETURNS
289  *
290  *  Returns TRUE when the time zone bias was calculated.
291  */
292
293 static BOOL _GetTimezoneBias(
294     const LPTIME_ZONE_INFORMATION lpTimeZoneInformation, /* [in] The time zone data.            */
295     LPSYSTEMTIME                  lpSystemTime,          /* [in] The system time.               */
296     LONG*                         pBias)                 /* [out] The calulated bias in minutes */
297 {
298     int ret;
299     BOOL beforedaylightsaving, afterdaylightsaving;
300     BOOL daylightsaving = FALSE;
301     LONG bias = lpTimeZoneInformation->Bias;
302
303     if (lpTimeZoneInformation->DaylightDate.wMonth != 0)
304     {
305         if (lpTimeZoneInformation->StandardDate.wMonth == 0 ||
306             lpTimeZoneInformation->StandardDate.wDay<1 ||
307             lpTimeZoneInformation->StandardDate.wDay>5 ||
308             lpTimeZoneInformation->DaylightDate.wDay<1 ||
309             lpTimeZoneInformation->DaylightDate.wDay>5)
310         {
311             SetLastError(ERROR_INVALID_PARAMETER);
312             return FALSE;
313         }
314
315          /* check for daylight saving */
316        ret = _DayLightCompareDate(lpSystemTime, &lpTimeZoneInformation->StandardDate);
317        if (ret == -2)
318           return FALSE;
319
320         beforedaylightsaving = ret < 0;
321
322        _DayLightCompareDate(lpSystemTime, &lpTimeZoneInformation->DaylightDate);
323        if (ret == -2)
324           return FALSE;
325
326         afterdaylightsaving = ret >= 0;
327
328         if (!beforedaylightsaving && !afterdaylightsaving)
329             daylightsaving = TRUE;
330     }
331
332     if (daylightsaving)
333         bias += lpTimeZoneInformation->DaylightBias;
334     else if (lpTimeZoneInformation->StandardDate.wMonth != 0)
335         bias += lpTimeZoneInformation->StandardBias;
336
337     *pBias = bias;
338
339     return TRUE;
340 }
341
342
343 /***********************************************************************
344  *              SystemTimeToTzSpecificLocalTime  (KERNEL32.@)
345  *
346  *  Converts the system time (utc) to the local time in the specified time zone.
347  *
348  * RETURNS
349  *
350  *  Returns true when the local time was calculated.
351  *  Returns TRUE when the local time was calculated.
352  *
353  */
354
355 BOOL WINAPI SystemTimeToTzSpecificLocalTime(
356     LPTIME_ZONE_INFORMATION lpTimeZoneInformation, /* [in] The desired time zone. */
357     LPSYSTEMTIME            lpUniversalTime,       /* [in] The utc time to base local time on. */
358     LPSYSTEMTIME            lpLocalTime)           /* [out] The local time in the time zone. */
359 {
360     FILETIME ft;
361     LONG lBias;
362     LONGLONG t, bias;
363     TIME_ZONE_INFORMATION tzinfo;
364
365     if (lpTimeZoneInformation != NULL)
366     {
367         memcpy(&tzinfo, lpTimeZoneInformation, sizeof(TIME_ZONE_INFORMATION));
368     }
369     else
370     {
371         if (GetTimeZoneInformation(&tzinfo) == TIME_ZONE_ID_INVALID)
372             return FALSE;
373     }
374
375     if (!SystemTimeToFileTime(lpUniversalTime, &ft))
376         return FALSE;
377
378     t = ft.dwHighDateTime;
379     t <<= 32;
380     t += (UINT)ft.dwLowDateTime;
381
382     if (!_GetTimezoneBias(&tzinfo, lpUniversalTime, &lBias))
383         return FALSE;
384
385     bias = lBias * 600000000; /* 60 seconds per minute, 100000 [100-nanoseconds-ticks] per second */
386     t += bias;
387
388     ft.dwLowDateTime  = (UINT)t;
389     ft.dwHighDateTime = (UINT)(t >> 32);
390
391     return FileTimeToSystemTime(&ft, lpLocalTime);
392 }
393
394
395 /***********************************************************************
396  *              TzSpecificLocalTimeToSystemTime  (KERNEL32.@)
397  *
398  *  Converts a local time to a time in Coordinated Universal Time (UTC).
399  *
400  * RETURNS
401  *
402  *  Returns TRUE when the utc time was calculated.
403  */
404
405 BOOL WINAPI TzSpecificLocalTimeToSystemTime(
406     LPTIME_ZONE_INFORMATION lpTimeZoneInformation, /* [in] The desired time zone. */
407     LPSYSTEMTIME            lpLocalTime,           /* [in] The local time. */
408     LPSYSTEMTIME            lpUniversalTime)       /* [out] The calculated utc time. */
409 {
410     FILETIME ft;
411     LONG lBias;
412     LONGLONG t, bias;
413     TIME_ZONE_INFORMATION tzinfo;
414
415     if (lpTimeZoneInformation != NULL)
416     {
417         memcpy(&tzinfo, lpTimeZoneInformation, sizeof(TIME_ZONE_INFORMATION));
418     }
419     else
420     {
421         if (GetTimeZoneInformation(&tzinfo) == TIME_ZONE_ID_INVALID)
422             return FALSE;
423     }
424
425     if (!SystemTimeToFileTime(lpLocalTime, &ft))
426         return FALSE;
427
428     t = ft.dwHighDateTime;
429     t <<= 32;
430     t += (UINT)ft.dwLowDateTime;
431
432     if (!_GetTimezoneBias(&tzinfo, lpUniversalTime, &lBias))
433         return FALSE;
434
435     bias = lBias * 600000000; /* 60 seconds per minute, 100000 [100-nanoseconds-ticks] per second */
436     t -= bias;
437
438     ft.dwLowDateTime  = (UINT)t;
439     ft.dwHighDateTime = (UINT)(t >> 32);
440
441     return FileTimeToSystemTime(&ft, lpUniversalTime);
442 }
443
444
445
446
447 /***********************************************************************
448  *              GetSystemTimeAsFileTime  (KERNEL32.@)
449  *
450  *  Fills in a file time structure with the current time in UTC format.
451  */
452 VOID WINAPI GetSystemTimeAsFileTime(
453     LPFILETIME time) /* [out] The file time struct to be filled with the system time. */
454 {
455     LARGE_INTEGER t;
456     NtQuerySystemTime( &t );
457     time->dwLowDateTime = t.s.LowPart;
458     time->dwHighDateTime = t.s.HighPart;
459 }
460
461
462 /*********************************************************************
463  *      TIME_ClockTimeToFileTime    (olorin@fandra.org, 20-Sep-1998)
464  *
465  *  Used by GetProcessTimes to convert clock_t into FILETIME.
466  *
467  *      Differences to UnixTimeToFileTime:
468  *          1) Divided by CLK_TCK
469  *          2) Time is relative. There is no 'starting date', so there is
470  *             no need in offset correction, like in UnixTimeToFileTime
471  */
472 static void TIME_ClockTimeToFileTime(clock_t unix_time, LPFILETIME filetime)
473 {
474     ULONGLONG secs = RtlEnlargedUnsignedMultiply( unix_time, 10000000 );
475     secs = RtlExtendedLargeIntegerDivide( secs, CLK_TCK, NULL );
476     filetime->dwLowDateTime  = (DWORD)secs;
477     filetime->dwHighDateTime = (DWORD)(secs >> 32);
478 }
479
480 /*********************************************************************
481  *      GetProcessTimes                         (KERNEL32.@)
482  *
483  *  Returns the user and kernel execution times of a process,
484  *  along with the creation and exit times if known.
485  *
486  *  olorin@fandra.org:
487  *  Would be nice to subtract the cpu time, used by Wine at startup.
488  *  Also, there is a need to separate times used by different applications.
489  *
490  * RETURNS
491  *
492  *  Always returns true.
493  *
494  * BUGS
495  *
496  *  lpCreationTime, lpExitTime are NOT INITIALIZED.
497  */
498 BOOL WINAPI GetProcessTimes(
499     HANDLE     hprocess,       /* [in] The process to be queried (obtained from PROCESS_QUERY_INFORMATION). */
500     LPFILETIME lpCreationTime, /* [out] The creation time of the process. */
501     LPFILETIME lpExitTime,     /* [out] The exit time of the process if exited. */
502     LPFILETIME lpKernelTime,   /* [out] The time spent in kernal routines in 100's of nanoseconds. */
503     LPFILETIME lpUserTime)     /* [out] The time spent in user routines in 100's of nanoseconds. */
504 {
505     struct tms tms;
506
507     times(&tms);
508     TIME_ClockTimeToFileTime(tms.tms_utime,lpUserTime);
509     TIME_ClockTimeToFileTime(tms.tms_stime,lpKernelTime);
510     return TRUE;
511 }
512
513 /*********************************************************************
514  *      GetCalendarInfoA                                (KERNEL32.@)
515  *
516  */
517 int WINAPI GetCalendarInfoA(LCID Locale, CALID Calendar, CALTYPE CalType,
518                             LPSTR lpCalData, int cchData, LPDWORD lpValue)
519 {
520     int ret;
521     LPWSTR lpCalDataW = NULL;
522
523     FIXME("(%08lx,%08lx,%08lx,%p,%d,%p): quarter-stub\n",
524           Locale, Calendar, CalType, lpCalData, cchData, lpValue);
525     /* FIXME: Should verify if Locale is allowable in ANSI, as per MSDN */
526
527     if(cchData)
528       if(!(lpCalDataW = HeapAlloc(GetProcessHeap(), 0, cchData*sizeof(WCHAR)))) return 0;
529
530     ret = GetCalendarInfoW(Locale, Calendar, CalType, lpCalDataW, cchData, lpValue);
531     if(ret && lpCalDataW && lpCalData)
532       WideCharToMultiByte(CP_ACP, 0, lpCalDataW, cchData, lpCalData, cchData, NULL, NULL);
533     if(lpCalDataW)
534       HeapFree(GetProcessHeap(), 0, lpCalDataW);
535
536     return ret;
537 }
538
539 /*********************************************************************
540  *      GetCalendarInfoW                                (KERNEL32.@)
541  *
542  */
543 int WINAPI GetCalendarInfoW(LCID Locale, CALID Calendar, CALTYPE CalType,
544                             LPWSTR lpCalData, int cchData, LPDWORD lpValue)
545 {
546     FIXME("(%08lx,%08lx,%08lx,%p,%d,%p): quarter-stub\n",
547           Locale, Calendar, CalType, lpCalData, cchData, lpValue);
548
549     if (CalType & CAL_NOUSEROVERRIDE)
550         FIXME("flag CAL_NOUSEROVERRIDE used, not fully implemented\n");
551     if (CalType & CAL_USE_CP_ACP)
552         FIXME("flag CAL_USE_CP_ACP used, not fully implemented\n");
553
554     if (CalType & CAL_RETURN_NUMBER) {
555         if (lpCalData != NULL)
556             WARN("lpCalData not NULL (%p) when it should!\n", lpCalData);
557         if (cchData != 0)
558             WARN("cchData not 0 (%d) when it should!\n", cchData);
559     } else {
560         if (lpValue != NULL)
561             WARN("lpValue not NULL (%p) when it should!\n", lpValue);
562     }
563
564     /* FIXME: No verification is made yet wrt Locale
565      * for the CALTYPES not requiring GetLocaleInfoA */
566     switch (CalType & ~(CAL_NOUSEROVERRIDE|CAL_RETURN_NUMBER|CAL_USE_CP_ACP)) {
567         case CAL_ICALINTVALUE:
568             FIXME("Unimplemented caltype %ld\n", CalType & 0xffff);
569             return E_FAIL;
570         case CAL_SCALNAME:
571             FIXME("Unimplemented caltype %ld\n", CalType & 0xffff);
572             return E_FAIL;
573         case CAL_IYEAROFFSETRANGE:
574             FIXME("Unimplemented caltype %ld\n", CalType & 0xffff);
575             return E_FAIL;
576         case CAL_SERASTRING:
577             FIXME("Unimplemented caltype %ld\n", CalType & 0xffff);
578             return E_FAIL;
579         case CAL_SSHORTDATE:
580             return GetLocaleInfoW(Locale, LOCALE_SSHORTDATE, lpCalData, cchData);
581         case CAL_SLONGDATE:
582             return GetLocaleInfoW(Locale, LOCALE_SLONGDATE, lpCalData, cchData);
583         case CAL_SDAYNAME1:
584             return GetLocaleInfoW(Locale, LOCALE_SDAYNAME1, lpCalData, cchData);
585         case CAL_SDAYNAME2:
586             return GetLocaleInfoW(Locale, LOCALE_SDAYNAME2, lpCalData, cchData);
587         case CAL_SDAYNAME3:
588             return GetLocaleInfoW(Locale, LOCALE_SDAYNAME3, lpCalData, cchData);
589         case CAL_SDAYNAME4:
590             return GetLocaleInfoW(Locale, LOCALE_SDAYNAME4, lpCalData, cchData);
591         case CAL_SDAYNAME5:
592             return GetLocaleInfoW(Locale, LOCALE_SDAYNAME5, lpCalData, cchData);
593         case CAL_SDAYNAME6:
594             return GetLocaleInfoW(Locale, LOCALE_SDAYNAME6, lpCalData, cchData);
595         case CAL_SDAYNAME7:
596             return GetLocaleInfoW(Locale, LOCALE_SDAYNAME7, lpCalData, cchData);
597         case CAL_SABBREVDAYNAME1:
598             return GetLocaleInfoW(Locale, LOCALE_SABBREVDAYNAME1, lpCalData, cchData);
599         case CAL_SABBREVDAYNAME2:
600             return GetLocaleInfoW(Locale, LOCALE_SABBREVDAYNAME2, lpCalData, cchData);
601         case CAL_SABBREVDAYNAME3:
602             return GetLocaleInfoW(Locale, LOCALE_SABBREVDAYNAME3, lpCalData, cchData);
603         case CAL_SABBREVDAYNAME4:
604             return GetLocaleInfoW(Locale, LOCALE_SABBREVDAYNAME4, lpCalData, cchData);
605         case CAL_SABBREVDAYNAME5:
606             return GetLocaleInfoW(Locale, LOCALE_SABBREVDAYNAME5, lpCalData, cchData);
607         case CAL_SABBREVDAYNAME6:
608             return GetLocaleInfoW(Locale, LOCALE_SABBREVDAYNAME6, lpCalData, cchData);
609         case CAL_SABBREVDAYNAME7:
610             return GetLocaleInfoW(Locale, LOCALE_SABBREVDAYNAME7, lpCalData, cchData);
611         case CAL_SMONTHNAME1:
612             return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME1, lpCalData, cchData);
613         case CAL_SMONTHNAME2:
614             return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME2, lpCalData, cchData);
615         case CAL_SMONTHNAME3:
616             return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME3, lpCalData, cchData);
617         case CAL_SMONTHNAME4:
618             return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME4, lpCalData, cchData);
619         case CAL_SMONTHNAME5:
620             return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME5, lpCalData, cchData);
621         case CAL_SMONTHNAME6:
622             return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME6, lpCalData, cchData);
623         case CAL_SMONTHNAME7:
624             return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME7, lpCalData, cchData);
625         case CAL_SMONTHNAME8:
626             return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME8, lpCalData, cchData);
627         case CAL_SMONTHNAME9:
628             return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME9, lpCalData, cchData);
629         case CAL_SMONTHNAME10:
630             return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME10, lpCalData, cchData);
631         case CAL_SMONTHNAME11:
632             return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME11, lpCalData, cchData);
633         case CAL_SMONTHNAME12:
634             return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME12, lpCalData, cchData);
635         case CAL_SMONTHNAME13:
636             return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME13, lpCalData, cchData);
637         case CAL_SABBREVMONTHNAME1:
638             return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME1, lpCalData, cchData);
639         case CAL_SABBREVMONTHNAME2:
640             return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME2, lpCalData, cchData);
641         case CAL_SABBREVMONTHNAME3:
642             return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME3, lpCalData, cchData);
643         case CAL_SABBREVMONTHNAME4:
644             return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME4, lpCalData, cchData);
645         case CAL_SABBREVMONTHNAME5:
646             return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME5, lpCalData, cchData);
647         case CAL_SABBREVMONTHNAME6:
648             return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME6, lpCalData, cchData);
649         case CAL_SABBREVMONTHNAME7:
650             return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME7, lpCalData, cchData);
651         case CAL_SABBREVMONTHNAME8:
652             return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME8, lpCalData, cchData);
653         case CAL_SABBREVMONTHNAME9:
654             return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME9, lpCalData, cchData);
655         case CAL_SABBREVMONTHNAME10:
656             return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME10, lpCalData, cchData);
657         case CAL_SABBREVMONTHNAME11:
658             return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME11, lpCalData, cchData);
659         case CAL_SABBREVMONTHNAME12:
660             return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME12, lpCalData, cchData);
661         case CAL_SABBREVMONTHNAME13:
662             return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME13, lpCalData, cchData);
663         case CAL_SYEARMONTH:
664             return GetLocaleInfoW(Locale, LOCALE_SYEARMONTH, lpCalData, cchData);
665         case CAL_ITWODIGITYEARMAX:
666             if (lpValue) *lpValue = CALINFO_MAX_YEAR;
667             break;
668         default: MESSAGE("Unknown caltype %ld\n",CalType & 0xffff);
669                  return E_FAIL;
670     }
671     return 0;
672 }
673
674 /*********************************************************************
675  *      SetCalendarInfoA                                (KERNEL32.@)
676  *
677  */
678 int WINAPI      SetCalendarInfoA(LCID Locale, CALID Calendar, CALTYPE CalType, LPCSTR lpCalData)
679 {
680     FIXME("(%08lx,%08lx,%08lx,%s): stub\n",
681           Locale, Calendar, CalType, debugstr_a(lpCalData));
682     return 0;
683 }
684
685 /*********************************************************************
686  *      SetCalendarInfoW                                (KERNEL32.@)
687  *
688  */
689 int WINAPI      SetCalendarInfoW(LCID Locale, CALID Calendar, CALTYPE CalType, LPCWSTR lpCalData)
690 {
691     FIXME("(%08lx,%08lx,%08lx,%s): stub\n",
692           Locale, Calendar, CalType, debugstr_w(lpCalData));
693     return 0;
694 }
695
696 /*********************************************************************
697  *      LocalFileTimeToFileTime                         (KERNEL32.@)
698  */
699 BOOL WINAPI LocalFileTimeToFileTime( const FILETIME *localft, LPFILETIME utcft )
700 {
701     NTSTATUS status;
702     LARGE_INTEGER local, utc;
703
704     local.s.LowPart = localft->dwLowDateTime;
705     local.s.HighPart = localft->dwHighDateTime;
706     if (!(status = RtlLocalTimeToSystemTime( &local, &utc )))
707     {
708         utcft->dwLowDateTime = utc.s.LowPart;
709         utcft->dwHighDateTime = utc.s.HighPart;
710     }
711     else SetLastError( RtlNtStatusToDosError(status) );
712
713     return !status;
714 }
715
716 /*********************************************************************
717  *      FileTimeToLocalFileTime                         (KERNEL32.@)
718  */
719 BOOL WINAPI FileTimeToLocalFileTime( const FILETIME *utcft, LPFILETIME localft )
720 {
721     NTSTATUS status;
722     LARGE_INTEGER local, utc;
723
724     utc.s.LowPart = utcft->dwLowDateTime;
725     utc.s.HighPart = utcft->dwHighDateTime;
726     if (!(status = RtlSystemTimeToLocalTime( &utc, &local )))
727     {
728         localft->dwLowDateTime = local.s.LowPart;
729         localft->dwHighDateTime = local.s.HighPart;
730     }
731     else SetLastError( RtlNtStatusToDosError(status) );
732
733     return !status;
734 }
735
736 /*********************************************************************
737  *      FileTimeToSystemTime                            (KERNEL32.@)
738  */
739 BOOL WINAPI FileTimeToSystemTime( const FILETIME *ft, LPSYSTEMTIME syst )
740 {
741     TIME_FIELDS tf;
742     LARGE_INTEGER t;
743
744     t.s.LowPart = ft->dwLowDateTime;
745     t.s.HighPart = ft->dwHighDateTime;
746     RtlTimeToTimeFields(&t, &tf);
747
748     syst->wYear = tf.Year;
749     syst->wMonth = tf.Month;
750     syst->wDay = tf.Day;
751     syst->wHour = tf.Hour;
752     syst->wMinute = tf.Minute;
753     syst->wSecond = tf.Second;
754     syst->wMilliseconds = tf.Milliseconds;
755     syst->wDayOfWeek = tf.Weekday;
756     return TRUE;
757 }
758
759 /*********************************************************************
760  *      SystemTimeToFileTime                            (KERNEL32.@)
761  */
762 BOOL WINAPI SystemTimeToFileTime( const SYSTEMTIME *syst, LPFILETIME ft )
763 {
764     TIME_FIELDS tf;
765     LARGE_INTEGER t;
766
767     tf.Year = syst->wYear;
768     tf.Month = syst->wMonth;
769     tf.Day = syst->wDay;
770     tf.Hour = syst->wHour;
771     tf.Minute = syst->wMinute;
772     tf.Second = syst->wSecond;
773     tf.Milliseconds = syst->wMilliseconds;
774
775     RtlTimeFieldsToTime(&tf, &t);
776     ft->dwLowDateTime = t.s.LowPart;
777     ft->dwHighDateTime = t.s.HighPart;
778     return TRUE;
779 }
780
781 /*********************************************************************
782  *      CompareFileTime                                 (KERNEL32.@)
783  */
784 INT WINAPI CompareFileTime( const FILETIME *x, const FILETIME *y )
785 {
786     if (!x || !y) return -1;
787
788     if (x->dwHighDateTime > y->dwHighDateTime)
789         return 1;
790     if (x->dwHighDateTime < y->dwHighDateTime)
791         return -1;
792     if (x->dwLowDateTime > y->dwLowDateTime)
793         return 1;
794     if (x->dwLowDateTime < y->dwLowDateTime)
795         return -1;
796     return 0;
797 }
798
799 /*********************************************************************
800  *      GetLocalTime                                    (KERNEL32.@)
801  */
802 VOID WINAPI GetLocalTime(LPSYSTEMTIME systime)
803 {
804     FILETIME lft;
805     LARGE_INTEGER ft, ft2;
806
807     NtQuerySystemTime(&ft);
808     RtlSystemTimeToLocalTime(&ft, &ft2);
809     lft.dwLowDateTime = ft2.s.LowPart;
810     lft.dwHighDateTime = ft2.s.HighPart;
811     FileTimeToSystemTime(&lft, systime);
812 }
813
814 /*********************************************************************
815  *      GetSystemTime                                   (KERNEL32.@)
816  */
817 VOID WINAPI GetSystemTime(LPSYSTEMTIME systime)
818 {
819     FILETIME ft;
820     LARGE_INTEGER t;
821
822     NtQuerySystemTime(&t);
823     ft.dwLowDateTime = t.s.LowPart;
824     ft.dwHighDateTime = t.s.HighPart;
825     FileTimeToSystemTime(&ft, systime);
826 }