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
28 #ifdef HAVE_SYS_TIME_H
29 # include <sys/time.h>
31 #ifdef HAVE_SYS_TIMES_H
32 # include <sys/times.h>
35 #define NONAMELESSUNION
36 #define NONAMELESSSTRUCT
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 * Set the local time using current time zone and daylight
58 * Success: TRUE. The time was set
59 * Failure: FALSE, if the time was invalid or caller does not have
60 * permission to change the time.
62 BOOL WINAPI SetLocalTime(
63 const SYSTEMTIME *systime) /* [in] The desired local time. */
66 LARGE_INTEGER st, st2;
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) );
80 /***********************************************************************
81 * GetSystemTimeAdjustment (KERNEL32.@)
83 * Get the period between clock interrupts and the amount the clock
84 * is adjusted each interrupt so as to keep it in sync with an external source.
90 * Only the special case of disabled time adjustments is supported.
92 BOOL WINAPI GetSystemTimeAdjustment(
93 PDWORD lpTimeAdjustment, /* [out] The clock adjustment per interupt in 100's of nanoseconds. */
94 PDWORD lpTimeIncrement, /* [out] The time between clock interupts in 100's of nanoseconds. */
95 PBOOL lpTimeAdjustmentDisabled) /* [out] The clock synchonisation has been disabled. */
97 *lpTimeAdjustment = 0;
99 *lpTimeAdjustmentDisabled = TRUE;
104 /***********************************************************************
105 * SetSystemTime (KERNEL32.@)
107 * Set the system time in utc.
110 * Success: TRUE. The time was set
111 * Failure: FALSE, if the time was invalid or caller does not have
112 * permission to change the time.
114 BOOL WINAPI SetSystemTime(
115 const SYSTEMTIME *systime) /* [in] The desired system time. */
121 SystemTimeToFileTime( systime, &ft );
122 t.s.LowPart = ft.dwLowDateTime;
123 t.s.HighPart = ft.dwHighDateTime;
124 if ((status = NtSetSystemTime(&t, NULL)))
125 SetLastError( RtlNtStatusToDosError(status) );
129 /***********************************************************************
130 * SetSystemTimeAdjustment (KERNEL32.@)
132 * Enables or disables the timing adjustments to the system's clock.
138 BOOL WINAPI SetSystemTimeAdjustment(
139 DWORD dwTimeAdjustment,
140 BOOL bTimeAdjustmentDisabled)
142 /* Fake function for now... */
143 FIXME("(%08lx,%d): stub !\n", dwTimeAdjustment, bTimeAdjustmentDisabled);
148 /***********************************************************************
149 * GetTimeZoneInformation (KERNEL32.@)
151 * Get information about the current local time zone.
154 * Success: TIME_ZONE_ID_STANDARD. tzinfo contains the time zone info.
155 * Failure: TIME_ZONE_ID_INVALID.
157 DWORD WINAPI GetTimeZoneInformation(
158 LPTIME_ZONE_INFORMATION tzinfo) /* [out] Destination for time zone information */
161 if ((status = RtlQueryTimeZoneInformation(tzinfo)))
162 SetLastError( RtlNtStatusToDosError(status) );
163 return TIME_ZONE_ID_STANDARD;
167 /***********************************************************************
168 * SetTimeZoneInformation (KERNEL32.@)
170 * Change the settings of the current local time zone.
173 * Success: TRUE. The time zone was updated with the settings from tzinfo
176 BOOL WINAPI SetTimeZoneInformation(
177 const LPTIME_ZONE_INFORMATION tzinfo) /* [in] The new time zone. */
180 if ((status = RtlSetTimeZoneInformation(tzinfo)))
181 SetLastError( RtlNtStatusToDosError(status) );
186 /***********************************************************************
187 * _DayLightCompareDate
189 * Compares two dates without looking at the year
193 * -1 if date < compareDate
194 * 0 if date == compareDate
195 * 1 if date > compareDate
196 * -2 if an error occures
199 static int _DayLightCompareDate(
200 const LPSYSTEMTIME date, /* [in] The date to compare. */
201 const LPSYSTEMTIME compareDate) /* [in] The daylight saving begin or end date */
205 if (compareDate->wYear != 0)
207 if (date->wMonth < compareDate->wMonth)
208 return -1; /* We are in a year before the date limit. */
210 if (date->wMonth > compareDate->wMonth)
211 return 1; /* We are in a year after the date limit. */
214 if (date->wMonth < compareDate->wMonth)
215 return -1; /* We are in a month before the date limit. */
217 if (date->wMonth > compareDate->wMonth)
218 return 1; /* We are in a month after the date limit. */
220 if (compareDate->wDayOfWeek <= 6)
225 /* compareDate->wDay is interpreted as number of the week in the month. */
226 /* 5 means: the last week in the month */
227 int weekofmonth = compareDate->wDay;
229 /* calculate day of week for the first day in the month */
230 memcpy(&tmp, date, sizeof(SYSTEMTIME));
234 if (weekofmonth == 5)
236 /* Go to the beginning of the next month. */
237 if (++tmp.wMonth > 12)
244 if (!SystemTimeToFileTime(&tmp, &tmp_ft))
247 if (weekofmonth == 5)
251 t = tmp_ft.dwHighDateTime;
253 t += (UINT)tmp_ft.dwLowDateTime;
255 /* subtract one day */
260 tmp_ft.dwLowDateTime = (UINT)t;
261 tmp_ft.dwHighDateTime = (UINT)(t >> 32);
264 if (!FileTimeToSystemTime(&tmp_ft, &tmp))
267 if (weekofmonth == 5)
269 /* calculate the last matching day of the week in this month */
270 int dif = tmp.wDayOfWeek - compareDate->wDayOfWeek;
274 limit_day = tmp.wDay - dif;
278 /* calculate the matching day of the week in the given week */
279 int dif = compareDate->wDayOfWeek - tmp.wDayOfWeek;
283 limit_day = tmp.wDay + 7*(weekofmonth-1) + dif;
288 limit_day = compareDate->wDay;
291 if (date->wDay < limit_day)
294 if (date->wDay > limit_day)
297 return 0; /* date is equal to the date limit. */
301 /***********************************************************************
304 * Calculates the local time bias for a given time zone
308 * Returns TRUE when the time zone bias was calculated.
311 static BOOL _GetTimezoneBias(
312 const LPTIME_ZONE_INFORMATION lpTimeZoneInformation, /* [in] The time zone data. */
313 LPSYSTEMTIME lpSystemTime, /* [in] The system time. */
314 LONG* pBias) /* [out] The calulated bias in minutes */
317 BOOL beforeStandardDate, afterDaylightDate;
318 BOOL daylightsaving = FALSE;
319 LONG bias = lpTimeZoneInformation->Bias;
321 if (lpTimeZoneInformation->DaylightDate.wMonth != 0)
323 if (lpTimeZoneInformation->StandardDate.wMonth == 0 ||
324 lpTimeZoneInformation->StandardDate.wDay<1 ||
325 lpTimeZoneInformation->StandardDate.wDay>5 ||
326 lpTimeZoneInformation->DaylightDate.wDay<1 ||
327 lpTimeZoneInformation->DaylightDate.wDay>5)
329 SetLastError(ERROR_INVALID_PARAMETER);
333 /* check for daylight saving */
334 ret = _DayLightCompareDate(lpSystemTime, &lpTimeZoneInformation->StandardDate);
338 beforeStandardDate = ret < 0;
340 ret = _DayLightCompareDate(lpSystemTime, &lpTimeZoneInformation->DaylightDate);
344 afterDaylightDate = ret >= 0;
346 if (beforeStandardDate && afterDaylightDate)
347 daylightsaving = TRUE;
351 bias += lpTimeZoneInformation->DaylightBias;
352 else if (lpTimeZoneInformation->StandardDate.wMonth != 0)
353 bias += lpTimeZoneInformation->StandardBias;
361 /***********************************************************************
362 * SystemTimeToTzSpecificLocalTime (KERNEL32.@)
364 * Convert a utc system time to a local time in a given time zone.
367 * Success: TRUE. lpLocalTime contains the converted time
371 BOOL WINAPI SystemTimeToTzSpecificLocalTime(
372 LPTIME_ZONE_INFORMATION lpTimeZoneInformation, /* [in] The desired time zone. */
373 LPSYSTEMTIME lpUniversalTime, /* [in] The utc time to base local time on. */
374 LPSYSTEMTIME lpLocalTime) /* [out] The local time in the time zone. */
379 TIME_ZONE_INFORMATION tzinfo;
381 if (lpTimeZoneInformation != NULL)
383 memcpy(&tzinfo, lpTimeZoneInformation, sizeof(TIME_ZONE_INFORMATION));
387 if (GetTimeZoneInformation(&tzinfo) == TIME_ZONE_ID_INVALID)
391 if (!SystemTimeToFileTime(lpUniversalTime, &ft))
394 t = ft.dwHighDateTime;
396 t += (UINT)ft.dwLowDateTime;
398 if (!_GetTimezoneBias(&tzinfo, lpUniversalTime, &lBias))
401 bias = (LONGLONG)lBias * 600000000; /* 60 seconds per minute, 100000 [100-nanoseconds-ticks] per second */
404 ft.dwLowDateTime = (UINT)t;
405 ft.dwHighDateTime = (UINT)(t >> 32);
407 return FileTimeToSystemTime(&ft, lpLocalTime);
411 /***********************************************************************
412 * TzSpecificLocalTimeToSystemTime (KERNEL32.@)
414 * Converts a local time to a time in utc.
417 * Success: TRUE. lpUniversalTime contains the converted time
420 BOOL WINAPI TzSpecificLocalTimeToSystemTime(
421 LPTIME_ZONE_INFORMATION lpTimeZoneInformation, /* [in] The desired time zone. */
422 LPSYSTEMTIME lpLocalTime, /* [in] The local time. */
423 LPSYSTEMTIME lpUniversalTime) /* [out] The calculated utc time. */
428 TIME_ZONE_INFORMATION tzinfo;
430 if (lpTimeZoneInformation != NULL)
432 memcpy(&tzinfo, lpTimeZoneInformation, sizeof(TIME_ZONE_INFORMATION));
436 if (GetTimeZoneInformation(&tzinfo) == TIME_ZONE_ID_INVALID)
440 if (!SystemTimeToFileTime(lpLocalTime, &ft))
443 t = ft.dwHighDateTime;
445 t += (UINT)ft.dwLowDateTime;
447 if (!_GetTimezoneBias(&tzinfo, lpLocalTime, &lBias))
450 bias = (LONGLONG)lBias * 600000000; /* 60 seconds per minute, 100000 [100-nanoseconds-ticks] per second */
453 ft.dwLowDateTime = (UINT)t;
454 ft.dwHighDateTime = (UINT)(t >> 32);
456 return FileTimeToSystemTime(&ft, lpUniversalTime);
460 /***********************************************************************
461 * GetSystemTimeAsFileTime (KERNEL32.@)
463 * Get the current time in utc format.
468 VOID WINAPI GetSystemTimeAsFileTime(
469 LPFILETIME time) /* [out] Destination for the current utc time */
472 NtQuerySystemTime( &t );
473 time->dwLowDateTime = t.s.LowPart;
474 time->dwHighDateTime = t.s.HighPart;
478 /*********************************************************************
479 * TIME_ClockTimeToFileTime (olorin@fandra.org, 20-Sep-1998)
481 * Used by GetProcessTimes to convert clock_t into FILETIME.
483 * Differences to UnixTimeToFileTime:
484 * 1) Divided by CLK_TCK
485 * 2) Time is relative. There is no 'starting date', so there is
486 * no need for offset correction, like in UnixTimeToFileTime
488 static void TIME_ClockTimeToFileTime(clock_t unix_time, LPFILETIME filetime)
490 ULONGLONG secs = RtlEnlargedUnsignedMultiply( unix_time, 10000000 );
491 secs = RtlExtendedLargeIntegerDivide( secs, CLK_TCK, NULL );
492 filetime->dwLowDateTime = (DWORD)secs;
493 filetime->dwHighDateTime = (DWORD)(secs >> 32);
496 /*********************************************************************
497 * GetProcessTimes (KERNEL32.@)
499 * Get the user and kernel execution times of a process,
500 * along with the creation and exit times if known.
507 * Would be nice to subtract the cpu time used by Wine at startup.
508 * Also, there is a need to separate times used by different applications.
511 * lpCreationTime and lpExitTime are not initialised in the Wine implementation.
513 BOOL WINAPI GetProcessTimes(
514 HANDLE hprocess, /* [in] The process to be queried (obtained from PROCESS_QUERY_INFORMATION). */
515 LPFILETIME lpCreationTime, /* [out] The creation time of the process. */
516 LPFILETIME lpExitTime, /* [out] The exit time of the process if exited. */
517 LPFILETIME lpKernelTime, /* [out] The time spent in kernal routines in 100's of nanoseconds. */
518 LPFILETIME lpUserTime) /* [out] The time spent in user routines in 100's of nanoseconds. */
523 TIME_ClockTimeToFileTime(tms.tms_utime,lpUserTime);
524 TIME_ClockTimeToFileTime(tms.tms_stime,lpKernelTime);
528 /*********************************************************************
529 * GetCalendarInfoA (KERNEL32.@)
532 int WINAPI GetCalendarInfoA(LCID Locale, CALID Calendar, CALTYPE CalType,
533 LPSTR lpCalData, int cchData, LPDWORD lpValue)
536 LPWSTR lpCalDataW = NULL;
538 FIXME("(%08lx,%08lx,%08lx,%p,%d,%p): quarter-stub\n",
539 Locale, Calendar, CalType, lpCalData, cchData, lpValue);
540 /* FIXME: Should verify if Locale is allowable in ANSI, as per MSDN */
543 if(!(lpCalDataW = HeapAlloc(GetProcessHeap(), 0, cchData*sizeof(WCHAR)))) return 0;
545 ret = GetCalendarInfoW(Locale, Calendar, CalType, lpCalDataW, cchData, lpValue);
546 if(ret && lpCalDataW && lpCalData)
547 WideCharToMultiByte(CP_ACP, 0, lpCalDataW, cchData, lpCalData, cchData, NULL, NULL);
549 HeapFree(GetProcessHeap(), 0, lpCalDataW);
554 /*********************************************************************
555 * GetCalendarInfoW (KERNEL32.@)
557 * See GetCalendarInfoA.
559 int WINAPI GetCalendarInfoW(LCID Locale, CALID Calendar, CALTYPE CalType,
560 LPWSTR lpCalData, int cchData, LPDWORD lpValue)
562 FIXME("(%08lx,%08lx,%08lx,%p,%d,%p): quarter-stub\n",
563 Locale, Calendar, CalType, lpCalData, cchData, lpValue);
565 if (CalType & CAL_NOUSEROVERRIDE)
566 FIXME("flag CAL_NOUSEROVERRIDE used, not fully implemented\n");
567 if (CalType & CAL_USE_CP_ACP)
568 FIXME("flag CAL_USE_CP_ACP used, not fully implemented\n");
570 if (CalType & CAL_RETURN_NUMBER) {
571 if (lpCalData != NULL)
572 WARN("lpCalData not NULL (%p) when it should!\n", lpCalData);
574 WARN("cchData not 0 (%d) when it should!\n", cchData);
577 WARN("lpValue not NULL (%p) when it should!\n", lpValue);
580 /* FIXME: No verification is made yet wrt Locale
581 * for the CALTYPES not requiring GetLocaleInfoA */
582 switch (CalType & ~(CAL_NOUSEROVERRIDE|CAL_RETURN_NUMBER|CAL_USE_CP_ACP)) {
583 case CAL_ICALINTVALUE:
584 FIXME("Unimplemented caltype %ld\n", CalType & 0xffff);
587 FIXME("Unimplemented caltype %ld\n", CalType & 0xffff);
589 case CAL_IYEAROFFSETRANGE:
590 FIXME("Unimplemented caltype %ld\n", CalType & 0xffff);
593 FIXME("Unimplemented caltype %ld\n", CalType & 0xffff);
596 return GetLocaleInfoW(Locale, LOCALE_SSHORTDATE, lpCalData, cchData);
598 return GetLocaleInfoW(Locale, LOCALE_SLONGDATE, lpCalData, cchData);
600 return GetLocaleInfoW(Locale, LOCALE_SDAYNAME1, lpCalData, cchData);
602 return GetLocaleInfoW(Locale, LOCALE_SDAYNAME2, lpCalData, cchData);
604 return GetLocaleInfoW(Locale, LOCALE_SDAYNAME3, lpCalData, cchData);
606 return GetLocaleInfoW(Locale, LOCALE_SDAYNAME4, lpCalData, cchData);
608 return GetLocaleInfoW(Locale, LOCALE_SDAYNAME5, lpCalData, cchData);
610 return GetLocaleInfoW(Locale, LOCALE_SDAYNAME6, lpCalData, cchData);
612 return GetLocaleInfoW(Locale, LOCALE_SDAYNAME7, lpCalData, cchData);
613 case CAL_SABBREVDAYNAME1:
614 return GetLocaleInfoW(Locale, LOCALE_SABBREVDAYNAME1, lpCalData, cchData);
615 case CAL_SABBREVDAYNAME2:
616 return GetLocaleInfoW(Locale, LOCALE_SABBREVDAYNAME2, lpCalData, cchData);
617 case CAL_SABBREVDAYNAME3:
618 return GetLocaleInfoW(Locale, LOCALE_SABBREVDAYNAME3, lpCalData, cchData);
619 case CAL_SABBREVDAYNAME4:
620 return GetLocaleInfoW(Locale, LOCALE_SABBREVDAYNAME4, lpCalData, cchData);
621 case CAL_SABBREVDAYNAME5:
622 return GetLocaleInfoW(Locale, LOCALE_SABBREVDAYNAME5, lpCalData, cchData);
623 case CAL_SABBREVDAYNAME6:
624 return GetLocaleInfoW(Locale, LOCALE_SABBREVDAYNAME6, lpCalData, cchData);
625 case CAL_SABBREVDAYNAME7:
626 return GetLocaleInfoW(Locale, LOCALE_SABBREVDAYNAME7, lpCalData, cchData);
627 case CAL_SMONTHNAME1:
628 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME1, lpCalData, cchData);
629 case CAL_SMONTHNAME2:
630 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME2, lpCalData, cchData);
631 case CAL_SMONTHNAME3:
632 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME3, lpCalData, cchData);
633 case CAL_SMONTHNAME4:
634 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME4, lpCalData, cchData);
635 case CAL_SMONTHNAME5:
636 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME5, lpCalData, cchData);
637 case CAL_SMONTHNAME6:
638 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME6, lpCalData, cchData);
639 case CAL_SMONTHNAME7:
640 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME7, lpCalData, cchData);
641 case CAL_SMONTHNAME8:
642 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME8, lpCalData, cchData);
643 case CAL_SMONTHNAME9:
644 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME9, lpCalData, cchData);
645 case CAL_SMONTHNAME10:
646 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME10, lpCalData, cchData);
647 case CAL_SMONTHNAME11:
648 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME11, lpCalData, cchData);
649 case CAL_SMONTHNAME12:
650 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME12, lpCalData, cchData);
651 case CAL_SMONTHNAME13:
652 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME13, lpCalData, cchData);
653 case CAL_SABBREVMONTHNAME1:
654 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME1, lpCalData, cchData);
655 case CAL_SABBREVMONTHNAME2:
656 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME2, lpCalData, cchData);
657 case CAL_SABBREVMONTHNAME3:
658 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME3, lpCalData, cchData);
659 case CAL_SABBREVMONTHNAME4:
660 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME4, lpCalData, cchData);
661 case CAL_SABBREVMONTHNAME5:
662 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME5, lpCalData, cchData);
663 case CAL_SABBREVMONTHNAME6:
664 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME6, lpCalData, cchData);
665 case CAL_SABBREVMONTHNAME7:
666 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME7, lpCalData, cchData);
667 case CAL_SABBREVMONTHNAME8:
668 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME8, lpCalData, cchData);
669 case CAL_SABBREVMONTHNAME9:
670 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME9, lpCalData, cchData);
671 case CAL_SABBREVMONTHNAME10:
672 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME10, lpCalData, cchData);
673 case CAL_SABBREVMONTHNAME11:
674 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME11, lpCalData, cchData);
675 case CAL_SABBREVMONTHNAME12:
676 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME12, lpCalData, cchData);
677 case CAL_SABBREVMONTHNAME13:
678 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME13, lpCalData, cchData);
680 return GetLocaleInfoW(Locale, LOCALE_SYEARMONTH, lpCalData, cchData);
681 case CAL_ITWODIGITYEARMAX:
682 if (lpValue) *lpValue = CALINFO_MAX_YEAR;
684 default: MESSAGE("Unknown caltype %ld\n",CalType & 0xffff);
690 /*********************************************************************
691 * SetCalendarInfoA (KERNEL32.@)
694 int WINAPI SetCalendarInfoA(LCID Locale, CALID Calendar, CALTYPE CalType, LPCSTR lpCalData)
696 FIXME("(%08lx,%08lx,%08lx,%s): stub\n",
697 Locale, Calendar, CalType, debugstr_a(lpCalData));
701 /*********************************************************************
702 * SetCalendarInfoW (KERNEL32.@)
704 * See SetCalendarInfoA.
706 int WINAPI SetCalendarInfoW(LCID Locale, CALID Calendar, CALTYPE CalType, LPCWSTR lpCalData)
708 FIXME("(%08lx,%08lx,%08lx,%s): stub\n",
709 Locale, Calendar, CalType, debugstr_w(lpCalData));
713 /*********************************************************************
714 * LocalFileTimeToFileTime (KERNEL32.@)
716 BOOL WINAPI LocalFileTimeToFileTime( const FILETIME *localft, LPFILETIME utcft )
719 LARGE_INTEGER local, utc;
721 local.s.LowPart = localft->dwLowDateTime;
722 local.s.HighPart = localft->dwHighDateTime;
723 if (!(status = RtlLocalTimeToSystemTime( &local, &utc )))
725 utcft->dwLowDateTime = utc.s.LowPart;
726 utcft->dwHighDateTime = utc.s.HighPart;
728 else SetLastError( RtlNtStatusToDosError(status) );
733 /*********************************************************************
734 * FileTimeToLocalFileTime (KERNEL32.@)
736 BOOL WINAPI FileTimeToLocalFileTime( const FILETIME *utcft, LPFILETIME localft )
739 LARGE_INTEGER local, utc;
741 utc.s.LowPart = utcft->dwLowDateTime;
742 utc.s.HighPart = utcft->dwHighDateTime;
743 if (!(status = RtlSystemTimeToLocalTime( &utc, &local )))
745 localft->dwLowDateTime = local.s.LowPart;
746 localft->dwHighDateTime = local.s.HighPart;
748 else SetLastError( RtlNtStatusToDosError(status) );
753 /*********************************************************************
754 * FileTimeToSystemTime (KERNEL32.@)
756 BOOL WINAPI FileTimeToSystemTime( const FILETIME *ft, LPSYSTEMTIME syst )
761 t.s.LowPart = ft->dwLowDateTime;
762 t.s.HighPart = ft->dwHighDateTime;
763 RtlTimeToTimeFields(&t, &tf);
765 syst->wYear = tf.Year;
766 syst->wMonth = tf.Month;
768 syst->wHour = tf.Hour;
769 syst->wMinute = tf.Minute;
770 syst->wSecond = tf.Second;
771 syst->wMilliseconds = tf.Milliseconds;
772 syst->wDayOfWeek = tf.Weekday;
776 /*********************************************************************
777 * SystemTimeToFileTime (KERNEL32.@)
779 BOOL WINAPI SystemTimeToFileTime( const SYSTEMTIME *syst, LPFILETIME ft )
784 tf.Year = syst->wYear;
785 tf.Month = syst->wMonth;
787 tf.Hour = syst->wHour;
788 tf.Minute = syst->wMinute;
789 tf.Second = syst->wSecond;
790 tf.Milliseconds = syst->wMilliseconds;
792 RtlTimeFieldsToTime(&tf, &t);
793 ft->dwLowDateTime = t.s.LowPart;
794 ft->dwHighDateTime = t.s.HighPart;
798 /*********************************************************************
799 * CompareFileTime (KERNEL32.@)
801 * Compare two FILETIME's to each other.
805 * y [I] time to compare to x
808 * -1, 0, or 1 indicating that x is less than, equal to, or greater
809 * than y respectively.
811 INT WINAPI CompareFileTime( const FILETIME *x, const FILETIME *y )
813 if (!x || !y) return -1;
815 if (x->dwHighDateTime > y->dwHighDateTime)
817 if (x->dwHighDateTime < y->dwHighDateTime)
819 if (x->dwLowDateTime > y->dwLowDateTime)
821 if (x->dwLowDateTime < y->dwLowDateTime)
826 /*********************************************************************
827 * GetLocalTime (KERNEL32.@)
829 * Get the current local time.
834 VOID WINAPI GetLocalTime(LPSYSTEMTIME systime) /* [O] Destination for current time */
837 LARGE_INTEGER ft, ft2;
839 NtQuerySystemTime(&ft);
840 RtlSystemTimeToLocalTime(&ft, &ft2);
841 lft.dwLowDateTime = ft2.s.LowPart;
842 lft.dwHighDateTime = ft2.s.HighPart;
843 FileTimeToSystemTime(&lft, systime);
846 /*********************************************************************
847 * GetSystemTime (KERNEL32.@)
849 * Get the current system time.
854 VOID WINAPI GetSystemTime(LPSYSTEMTIME systime) /* [O] Destination for current time */
859 NtQuerySystemTime(&t);
860 ft.dwLowDateTime = t.s.LowPart;
861 ft.dwHighDateTime = t.s.HighPart;
862 FileTimeToSystemTime(&ft, systime);