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