Fixed time zone calculation.
[wine.git] / dlls / kernel / time.c
blob7b1e5640e7007c82e582db96a89942ae4ea8131e
1 /*
2 * Win32 kernel time functions
4 * Copyright 1995 Martin von Loewis and Cameron Heide
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.
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.
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
21 #include "config.h"
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
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"
44 WINE_DEFAULT_DEBUG_CHANNEL(win32);
46 /* maximum time adjustment in seconds for SetLocalTime and SetSystemTime */
47 #define SETTIME_MAX_ADJUST 120
48 #define CALINFO_MAX_YEAR 2029
51 /***********************************************************************
52 * SetLocalTime (KERNEL32.@)
54 * Sets the local time using current time zone and daylight
55 * savings settings.
57 * RETURNS
59 * True if the time was set, false if the time was invalid or the
60 * necessary permissions were not held.
62 BOOL WINAPI SetLocalTime(
63 const SYSTEMTIME *systime) /* [in] The desired local time. */
65 FILETIME ft;
66 LARGE_INTEGER st, st2;
67 NTSTATUS status;
69 SystemTimeToFileTime( systime, &ft );
70 st.s.LowPart = ft.dwLowDateTime;
71 st.s.HighPart = ft.dwHighDateTime;
72 RtlLocalTimeToSystemTime( &st, &st2 );
74 if ((status = NtSetSystemTime(&st2, NULL)))
75 SetLastError( RtlNtStatusToDosError(status) );
76 return !status;
80 /***********************************************************************
81 * GetSystemTimeAdjustment (KERNEL32.@)
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.
86 * RETURNS
88 * Always returns true.
90 * BUGS
92 * Only the special case of disabled time adjustments is supported.
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. */
99 *lpTimeAdjustment = 0;
100 *lpTimeIncrement = 0;
101 *lpTimeAdjustmentDisabled = TRUE;
102 return TRUE;
106 /***********************************************************************
107 * SetSystemTime (KERNEL32.@)
109 * Sets the system time (utc).
111 * RETURNS
113 * True if the time was set, false if the time was invalid or the
114 * necessary permissions were not held.
116 BOOL WINAPI SetSystemTime(
117 const SYSTEMTIME *systime) /* [in] The desired system time. */
119 FILETIME ft;
120 LARGE_INTEGER t;
121 NTSTATUS status;
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;
132 /***********************************************************************
133 * GetTimeZoneInformation (KERNEL32.@)
135 * Fills in the a time zone information structure with values based on
136 * the current local time.
138 * RETURNS
140 * The daylight savings time standard or TIME_ZONE_ID_INVALID if the call failed.
142 DWORD WINAPI GetTimeZoneInformation(
143 LPTIME_ZONE_INFORMATION tzinfo) /* [out] The time zone structure to be filled in. */
145 NTSTATUS status;
146 if ((status = RtlQueryTimeZoneInformation(tzinfo)))
147 SetLastError( RtlNtStatusToDosError(status) );
148 return TIME_ZONE_ID_STANDARD;
152 /***********************************************************************
153 * SetTimeZoneInformation (KERNEL32.@)
155 * Set the local time zone with values based on the time zone structure.
157 * RETURNS
159 * True on successful setting of the time zone.
161 BOOL WINAPI SetTimeZoneInformation(
162 const LPTIME_ZONE_INFORMATION tzinfo) /* [in] The new time zone. */
164 NTSTATUS status;
165 if ((status = RtlSetTimeZoneInformation(tzinfo)))
166 SetLastError( RtlNtStatusToDosError(status) );
167 return !status;
171 /***********************************************************************
172 * _DayLightCompareDate
174 * Compares two dates without looking at the year
176 * RETURNS
178 * -1 if date < compareDate
179 * 0 if date == compareDate
180 * 1 if date > compareDate
181 * -2 if an error occures
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 */
188 int limit_day;
190 if (compareDate->wYear != 0)
192 if (date->wMonth < compareDate->wMonth)
193 return -1; /* We are in a year before the date limit. */
195 if (date->wMonth > compareDate->wMonth)
196 return 1; /* We are in a year after the date limit. */
199 if (date->wMonth < compareDate->wMonth)
200 return -1; /* We are in a month before the date limit. */
202 if (date->wMonth > compareDate->wMonth)
203 return 1; /* We are in a month after the date limit. */
205 if (compareDate->wDayOfWeek <= 6)
207 SYSTEMTIME tmp;
208 FILETIME tmp_ft;
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;
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;
219 if (weekofmonth == 5)
221 /* Go to the beginning of the next month. */
222 if (++tmp.wMonth > 12)
224 tmp.wMonth = 1;
225 ++tmp.wYear;
229 if (!SystemTimeToFileTime(&tmp, &tmp_ft))
230 return -2;
232 if (weekofmonth == 5)
234 LONGLONG t, one_day;
236 t = tmp_ft.dwHighDateTime;
237 t <<= 32;
238 t += (UINT)tmp_ft.dwLowDateTime;
240 /* substract one day */
241 one_day = 24*60*60;
242 one_day *= 10000000;
243 t -= one_day;
245 tmp_ft.dwLowDateTime = (UINT)t;
246 tmp_ft.dwHighDateTime = (UINT)(t >> 32);
249 if (!FileTimeToSystemTime(&tmp_ft, &tmp))
250 return -2;
252 if (weekofmonth == 5)
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;
259 limit_day = tmp.wDay - dif;
261 else
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;
268 limit_day = tmp.wDay + 7*(weekofmonth-1) + dif;
271 else
273 limit_day = compareDate->wDay;
276 if (date->wDay < limit_day)
277 return -1;
279 if (date->wDay > limit_day)
280 return 1;
282 return 0; /* date is equal to the date limit. */
286 /***********************************************************************
287 * _GetTimezoneBias
289 * Calculates the local time bias for a given time zone
291 * RETURNS
293 * Returns TRUE when the time zone bias was calculated.
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 */
301 int ret;
302 BOOL beforedaylightsaving, afterdaylightsaving;
303 BOOL daylightsaving = FALSE;
304 LONG bias = lpTimeZoneInformation->Bias;
306 if (lpTimeZoneInformation->DaylightDate.wMonth != 0)
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)
314 SetLastError(ERROR_INVALID_PARAMETER);
315 return FALSE;
318 /* check for daylight saving */
319 ret = _DayLightCompareDate(lpSystemTime, &lpTimeZoneInformation->StandardDate);
320 if (ret == -2)
321 return FALSE;
323 beforedaylightsaving = ret < 0;
325 _DayLightCompareDate(lpSystemTime, &lpTimeZoneInformation->DaylightDate);
326 if (ret == -2)
327 return FALSE;
329 afterdaylightsaving = ret >= 0;
331 if (!beforedaylightsaving && !afterdaylightsaving)
332 daylightsaving = TRUE;
335 if (daylightsaving)
336 bias += lpTimeZoneInformation->DaylightBias;
337 else if (lpTimeZoneInformation->StandardDate.wMonth != 0)
338 bias += lpTimeZoneInformation->StandardBias;
340 *pBias = bias;
342 return TRUE;
346 /***********************************************************************
347 * SystemTimeToTzSpecificLocalTime (KERNEL32.@)
349 * Converts the system time (utc) to the local time in the specified time zone.
351 * RETURNS
353 * Returns TRUE when the local time was calculated.
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. */
362 FILETIME ft;
363 LONG lBias;
364 LONGLONG t, bias;
365 TIME_ZONE_INFORMATION tzinfo;
367 if (lpTimeZoneInformation != NULL)
369 memcpy(&tzinfo, lpTimeZoneInformation, sizeof(TIME_ZONE_INFORMATION));
371 else
373 if (GetTimeZoneInformation(&tzinfo) == TIME_ZONE_ID_INVALID)
374 return FALSE;
377 if (!SystemTimeToFileTime(lpUniversalTime, &ft))
378 return FALSE;
380 t = ft.dwHighDateTime;
381 t <<= 32;
382 t += (UINT)ft.dwLowDateTime;
384 if (!_GetTimezoneBias(&tzinfo, lpUniversalTime, &lBias))
385 return FALSE;
387 bias = (LONGLONG)lBias * 600000000; /* 60 seconds per minute, 100000 [100-nanoseconds-ticks] per second */
388 t -= bias;
390 ft.dwLowDateTime = (UINT)t;
391 ft.dwHighDateTime = (UINT)(t >> 32);
393 return FileTimeToSystemTime(&ft, lpLocalTime);
397 /***********************************************************************
398 * TzSpecificLocalTimeToSystemTime (KERNEL32.@)
400 * Converts a local time to a time in Coordinated Universal Time (UTC).
402 * RETURNS
404 * Returns TRUE when the utc time was calculated.
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. */
412 FILETIME ft;
413 LONG lBias;
414 LONGLONG t, bias;
415 TIME_ZONE_INFORMATION tzinfo;
417 if (lpTimeZoneInformation != NULL)
419 memcpy(&tzinfo, lpTimeZoneInformation, sizeof(TIME_ZONE_INFORMATION));
421 else
423 if (GetTimeZoneInformation(&tzinfo) == TIME_ZONE_ID_INVALID)
424 return FALSE;
427 if (!SystemTimeToFileTime(lpLocalTime, &ft))
428 return FALSE;
430 t = ft.dwHighDateTime;
431 t <<= 32;
432 t += (UINT)ft.dwLowDateTime;
434 if (!_GetTimezoneBias(&tzinfo, lpUniversalTime, &lBias))
435 return FALSE;
437 bias = (LONGLONG)lBias * 600000000; /* 60 seconds per minute, 100000 [100-nanoseconds-ticks] per second */
438 t += bias;
440 ft.dwLowDateTime = (UINT)t;
441 ft.dwHighDateTime = (UINT)(t >> 32);
443 return FileTimeToSystemTime(&ft, lpUniversalTime);
449 /***********************************************************************
450 * GetSystemTimeAsFileTime (KERNEL32.@)
452 * Fills in a file time structure with the current time in UTC format.
454 VOID WINAPI GetSystemTimeAsFileTime(
455 LPFILETIME time) /* [out] The file time struct to be filled with the system time. */
457 LARGE_INTEGER t;
458 NtQuerySystemTime( &t );
459 time->dwLowDateTime = t.s.LowPart;
460 time->dwHighDateTime = t.s.HighPart;
464 /*********************************************************************
465 * TIME_ClockTimeToFileTime (olorin@fandra.org, 20-Sep-1998)
467 * Used by GetProcessTimes to convert clock_t into FILETIME.
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
474 static void TIME_ClockTimeToFileTime(clock_t unix_time, LPFILETIME filetime)
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);
482 /*********************************************************************
483 * GetProcessTimes (KERNEL32.@)
485 * Returns the user and kernel execution times of a process,
486 * along with the creation and exit times if known.
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.
492 * RETURNS
494 * Always returns true.
496 * BUGS
498 * lpCreationTime, lpExitTime are NOT INITIALIZED.
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. */
507 struct tms tms;
509 times(&tms);
510 TIME_ClockTimeToFileTime(tms.tms_utime,lpUserTime);
511 TIME_ClockTimeToFileTime(tms.tms_stime,lpKernelTime);
512 return TRUE;
515 /*********************************************************************
516 * GetCalendarInfoA (KERNEL32.@)
519 int WINAPI GetCalendarInfoA(LCID Locale, CALID Calendar, CALTYPE CalType,
520 LPSTR lpCalData, int cchData, LPDWORD lpValue)
522 int ret;
523 LPWSTR lpCalDataW = NULL;
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 */
529 if(cchData)
530 if(!(lpCalDataW = HeapAlloc(GetProcessHeap(), 0, cchData*sizeof(WCHAR)))) return 0;
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);
538 return ret;
541 /*********************************************************************
542 * GetCalendarInfoW (KERNEL32.@)
545 int WINAPI GetCalendarInfoW(LCID Locale, CALID Calendar, CALTYPE CalType,
546 LPWSTR lpCalData, int cchData, LPDWORD lpValue)
548 FIXME("(%08lx,%08lx,%08lx,%p,%d,%p): quarter-stub\n",
549 Locale, Calendar, CalType, lpCalData, cchData, lpValue);
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");
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);
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;
673 return 0;
676 /*********************************************************************
677 * SetCalendarInfoA (KERNEL32.@)
680 int WINAPI SetCalendarInfoA(LCID Locale, CALID Calendar, CALTYPE CalType, LPCSTR lpCalData)
682 FIXME("(%08lx,%08lx,%08lx,%s): stub\n",
683 Locale, Calendar, CalType, debugstr_a(lpCalData));
684 return 0;
687 /*********************************************************************
688 * SetCalendarInfoW (KERNEL32.@)
691 int WINAPI SetCalendarInfoW(LCID Locale, CALID Calendar, CALTYPE CalType, LPCWSTR lpCalData)
693 FIXME("(%08lx,%08lx,%08lx,%s): stub\n",
694 Locale, Calendar, CalType, debugstr_w(lpCalData));
695 return 0;
698 /*********************************************************************
699 * LocalFileTimeToFileTime (KERNEL32.@)
701 BOOL WINAPI LocalFileTimeToFileTime( const FILETIME *localft, LPFILETIME utcft )
703 NTSTATUS status;
704 LARGE_INTEGER local, utc;
706 local.s.LowPart = localft->dwLowDateTime;
707 local.s.HighPart = localft->dwHighDateTime;
708 if (!(status = RtlLocalTimeToSystemTime( &local, &utc )))
710 utcft->dwLowDateTime = utc.s.LowPart;
711 utcft->dwHighDateTime = utc.s.HighPart;
713 else SetLastError( RtlNtStatusToDosError(status) );
715 return !status;
718 /*********************************************************************
719 * FileTimeToLocalFileTime (KERNEL32.@)
721 BOOL WINAPI FileTimeToLocalFileTime( const FILETIME *utcft, LPFILETIME localft )
723 NTSTATUS status;
724 LARGE_INTEGER local, utc;
726 utc.s.LowPart = utcft->dwLowDateTime;
727 utc.s.HighPart = utcft->dwHighDateTime;
728 if (!(status = RtlSystemTimeToLocalTime( &utc, &local )))
730 localft->dwLowDateTime = local.s.LowPart;
731 localft->dwHighDateTime = local.s.HighPart;
733 else SetLastError( RtlNtStatusToDosError(status) );
735 return !status;
738 /*********************************************************************
739 * FileTimeToSystemTime (KERNEL32.@)
741 BOOL WINAPI FileTimeToSystemTime( const FILETIME *ft, LPSYSTEMTIME syst )
743 TIME_FIELDS tf;
744 LARGE_INTEGER t;
746 t.s.LowPart = ft->dwLowDateTime;
747 t.s.HighPart = ft->dwHighDateTime;
748 RtlTimeToTimeFields(&t, &tf);
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;
761 /*********************************************************************
762 * SystemTimeToFileTime (KERNEL32.@)
764 BOOL WINAPI SystemTimeToFileTime( const SYSTEMTIME *syst, LPFILETIME ft )
766 TIME_FIELDS tf;
767 LARGE_INTEGER t;
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;
777 RtlTimeFieldsToTime(&tf, &t);
778 ft->dwLowDateTime = t.s.LowPart;
779 ft->dwHighDateTime = t.s.HighPart;
780 return TRUE;
783 /*********************************************************************
784 * CompareFileTime (KERNEL32.@)
786 INT WINAPI CompareFileTime( const FILETIME *x, const FILETIME *y )
788 if (!x || !y) return -1;
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;
801 /*********************************************************************
802 * GetLocalTime (KERNEL32.@)
804 VOID WINAPI GetLocalTime(LPSYSTEMTIME systime)
806 FILETIME lft;
807 LARGE_INTEGER ft, ft2;
809 NtQuerySystemTime(&ft);
810 RtlSystemTimeToLocalTime(&ft, &ft2);
811 lft.dwLowDateTime = ft2.s.LowPart;
812 lft.dwHighDateTime = ft2.s.HighPart;
813 FileTimeToSystemTime(&lft, systime);
816 /*********************************************************************
817 * GetSystemTime (KERNEL32.@)
819 VOID WINAPI GetSystemTime(LPSYSTEMTIME systime)
821 FILETIME ft;
822 LARGE_INTEGER t;
824 NtQuerySystemTime(&t);
825 ft.dwLowDateTime = t.s.LowPart;
826 ft.dwHighDateTime = t.s.HighPart;
827 FileTimeToSystemTime(&ft, systime);