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>
38 #include "wine/unicode.h"
39 #include "wine/debug.h"
41 WINE_DEFAULT_DEBUG_CHANNEL(win32);
43 /* maximum time adjustment in seconds for SetLocalTime and SetSystemTime */
44 #define SETTIME_MAX_ADJUST 120
45 #define CALINFO_MAX_YEAR 2029
48 /***********************************************************************
49 * SetLocalTime (KERNEL32.@)
51 * Sets the local time using current time zone and daylight
56 * True if the time was set, false if the time was invalid or the
57 * necessary permissions were not held.
59 BOOL WINAPI SetLocalTime(
60 const SYSTEMTIME *systime) /* [in] The desired local time. */
63 LARGE_INTEGER st, st2;
66 SystemTimeToFileTime( systime, &ft );
67 st.s.LowPart = ft.dwLowDateTime;
68 st.s.HighPart = ft.dwHighDateTime;
69 RtlLocalTimeToSystemTime( &st, &st2 );
71 if ((status = NtSetSystemTime(&st2, NULL)))
72 SetLastError( RtlNtStatusToDosError(status) );
77 /***********************************************************************
78 * GetSystemTimeAdjustment (KERNEL32.@)
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.
85 * Always returns true.
89 * Only the special case of disabled time adjustments is supported.
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. */
96 *lpTimeAdjustment = 0;
98 *lpTimeAdjustmentDisabled = TRUE;
103 /***********************************************************************
104 * SetSystemTime (KERNEL32.@)
106 * Sets the system time (utc).
110 * True if the time was set, false if the time was invalid or the
111 * necessary permissions were not held.
113 BOOL WINAPI SetSystemTime(
114 const SYSTEMTIME *systime) /* [in] The desired system time. */
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) );
129 /***********************************************************************
130 * GetTimeZoneInformation (KERNEL32.@)
132 * Fills in the a time zone information structure with values based on
133 * the current local time.
137 * The daylight savings time standard or TIME_ZONE_ID_INVALID if the call failed.
139 DWORD WINAPI GetTimeZoneInformation(
140 LPTIME_ZONE_INFORMATION tzinfo) /* [out] The time zone structure to be filled in. */
143 if ((status = RtlQueryTimeZoneInformation(tzinfo)))
144 SetLastError( RtlNtStatusToDosError(status) );
145 return TIME_ZONE_ID_STANDARD;
149 /***********************************************************************
150 * SetTimeZoneInformation (KERNEL32.@)
152 * Set the local time zone with values based on the time zone structure.
156 * True on successful setting of the time zone.
158 BOOL WINAPI SetTimeZoneInformation(
159 const LPTIME_ZONE_INFORMATION tzinfo) /* [in] The new time zone. */
162 if ((status = RtlSetTimeZoneInformation(tzinfo)))
163 SetLastError( RtlNtStatusToDosError(status) );
168 /***********************************************************************
169 * _DayLightCompareDate
171 * Compares two dates without looking at the year
175 * -1 if date < compareDate
176 * 0 if date == compareDate
177 * 1 if date > compareDate
178 * -2 if an error occures
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 */
187 if (compareDate->wYear != 0)
189 if (date->wMonth < compareDate->wMonth)
190 return -1; /* We are in a year before the date limit. */
192 if (date->wMonth > compareDate->wMonth)
193 return 1; /* We are in a year after the date limit. */
196 if (date->wMonth < compareDate->wMonth)
197 return -1; /* We are in a month before the date limit. */
199 if (date->wMonth > compareDate->wMonth)
200 return 1; /* We are in a month after the date limit. */
202 if (compareDate->wDayOfWeek <= 6)
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;
211 /* calculate day of week for the first day in the month */
212 memcpy(&tmp, date, sizeof(SYSTEMTIME));
216 if (weekofmonth == 5)
218 /* Go to the beginning of the next month. */
219 if (++tmp.wMonth > 12)
226 if (!SystemTimeToFileTime(&tmp, &tmp_ft))
229 if (weekofmonth == 5)
233 t = tmp_ft.dwHighDateTime;
235 t += (UINT)tmp_ft.dwLowDateTime;
237 /* substract one day */
242 tmp_ft.dwLowDateTime = (UINT)t;
243 tmp_ft.dwHighDateTime = (UINT)(t >> 32);
246 if (!FileTimeToSystemTime(&tmp_ft, &tmp))
249 if (weekofmonth == 5)
251 /* calculate the last matching day of the week in this month */
252 int dif = tmp.wDayOfWeek - compareDate->wDayOfWeek;
256 limit_day = tmp.wDay - dif;
260 /* calulcate the matching day of the week in the given week */
261 int dif = compareDate->wDayOfWeek - tmp.wDayOfWeek;
265 limit_day = tmp.wDay + 7*(weekofmonth-1) + dif;
270 limit_day = compareDate->wDay;
273 if (date->wDay < limit_day)
276 if (date->wDay > limit_day)
279 return 0; /* date is equal to the date limit. */
283 /***********************************************************************
286 * Calculates the local time bias for a given time zone
290 * Returns TRUE when the time zone bias was calculated.
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 */
299 BOOL beforedaylightsaving, afterdaylightsaving;
300 BOOL daylightsaving = FALSE;
301 LONG bias = lpTimeZoneInformation->Bias;
303 if (lpTimeZoneInformation->DaylightDate.wMonth != 0)
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)
311 SetLastError(ERROR_INVALID_PARAMETER);
315 /* check for daylight saving */
316 ret = _DayLightCompareDate(lpSystemTime, &lpTimeZoneInformation->StandardDate);
320 beforedaylightsaving = ret < 0;
322 _DayLightCompareDate(lpSystemTime, &lpTimeZoneInformation->DaylightDate);
326 afterdaylightsaving = ret >= 0;
328 if (!beforedaylightsaving && !afterdaylightsaving)
329 daylightsaving = TRUE;
333 bias += lpTimeZoneInformation->DaylightBias;
334 else if (lpTimeZoneInformation->StandardDate.wMonth != 0)
335 bias += lpTimeZoneInformation->StandardBias;
343 /***********************************************************************
344 * SystemTimeToTzSpecificLocalTime (KERNEL32.@)
346 * Converts the system time (utc) to the local time in the specified time zone.
350 * Returns true when the local time was calculated.
351 * Returns TRUE when the local time was calculated.
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. */
363 TIME_ZONE_INFORMATION tzinfo;
365 if (lpTimeZoneInformation != NULL)
367 memcpy(&tzinfo, lpTimeZoneInformation, sizeof(TIME_ZONE_INFORMATION));
371 if (GetTimeZoneInformation(&tzinfo) == TIME_ZONE_ID_INVALID)
375 if (!SystemTimeToFileTime(lpUniversalTime, &ft))
378 t = ft.dwHighDateTime;
380 t += (UINT)ft.dwLowDateTime;
382 if (!_GetTimezoneBias(&tzinfo, lpUniversalTime, &lBias))
385 bias = lBias * 600000000; /* 60 seconds per minute, 100000 [100-nanoseconds-ticks] per second */
388 ft.dwLowDateTime = (UINT)t;
389 ft.dwHighDateTime = (UINT)(t >> 32);
391 return FileTimeToSystemTime(&ft, lpLocalTime);
395 /***********************************************************************
396 * TzSpecificLocalTimeToSystemTime (KERNEL32.@)
398 * Converts a local time to a time in Coordinated Universal Time (UTC).
402 * Returns TRUE when the utc time was calculated.
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. */
413 TIME_ZONE_INFORMATION tzinfo;
415 if (lpTimeZoneInformation != NULL)
417 memcpy(&tzinfo, lpTimeZoneInformation, sizeof(TIME_ZONE_INFORMATION));
421 if (GetTimeZoneInformation(&tzinfo) == TIME_ZONE_ID_INVALID)
425 if (!SystemTimeToFileTime(lpLocalTime, &ft))
428 t = ft.dwHighDateTime;
430 t += (UINT)ft.dwLowDateTime;
432 if (!_GetTimezoneBias(&tzinfo, lpUniversalTime, &lBias))
435 bias = lBias * 600000000; /* 60 seconds per minute, 100000 [100-nanoseconds-ticks] per second */
438 ft.dwLowDateTime = (UINT)t;
439 ft.dwHighDateTime = (UINT)(t >> 32);
441 return FileTimeToSystemTime(&ft, lpUniversalTime);
447 /***********************************************************************
448 * GetSystemTimeAsFileTime (KERNEL32.@)
450 * Fills in a file time structure with the current time in UTC format.
452 VOID WINAPI GetSystemTimeAsFileTime(
453 LPFILETIME time) /* [out] The file time struct to be filled with the system time. */
456 NtQuerySystemTime( &t );
457 time->dwLowDateTime = t.s.LowPart;
458 time->dwHighDateTime = t.s.HighPart;
462 /*********************************************************************
463 * TIME_ClockTimeToFileTime (olorin@fandra.org, 20-Sep-1998)
465 * Used by GetProcessTimes to convert clock_t into FILETIME.
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
472 static void TIME_ClockTimeToFileTime(clock_t unix_time, LPFILETIME filetime)
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);
480 /*********************************************************************
481 * GetProcessTimes (KERNEL32.@)
483 * Returns the user and kernel execution times of a process,
484 * along with the creation and exit times if known.
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.
492 * Always returns true.
496 * lpCreationTime, lpExitTime are NOT INITIALIZED.
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. */
508 TIME_ClockTimeToFileTime(tms.tms_utime,lpUserTime);
509 TIME_ClockTimeToFileTime(tms.tms_stime,lpKernelTime);
513 /*********************************************************************
514 * GetCalendarInfoA (KERNEL32.@)
517 int WINAPI GetCalendarInfoA(LCID Locale, CALID Calendar, CALTYPE CalType,
518 LPSTR lpCalData, int cchData, LPDWORD lpValue)
521 LPWSTR lpCalDataW = NULL;
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 */
528 if(!(lpCalDataW = HeapAlloc(GetProcessHeap(), 0, cchData*sizeof(WCHAR)))) return 0;
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);
534 HeapFree(GetProcessHeap(), 0, lpCalDataW);
539 /*********************************************************************
540 * GetCalendarInfoW (KERNEL32.@)
543 int WINAPI GetCalendarInfoW(LCID Locale, CALID Calendar, CALTYPE CalType,
544 LPWSTR lpCalData, int cchData, LPDWORD lpValue)
546 FIXME("(%08lx,%08lx,%08lx,%p,%d,%p): quarter-stub\n",
547 Locale, Calendar, CalType, lpCalData, cchData, lpValue);
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");
554 if (CalType & CAL_RETURN_NUMBER) {
555 if (lpCalData != NULL)
556 WARN("lpCalData not NULL (%p) when it should!\n", lpCalData);
558 WARN("cchData not 0 (%d) when it should!\n", cchData);
561 WARN("lpValue not NULL (%p) when it should!\n", lpValue);
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);
571 FIXME("Unimplemented caltype %ld\n", CalType & 0xffff);
573 case CAL_IYEAROFFSETRANGE:
574 FIXME("Unimplemented caltype %ld\n", CalType & 0xffff);
577 FIXME("Unimplemented caltype %ld\n", CalType & 0xffff);
580 return GetLocaleInfoW(Locale, LOCALE_SSHORTDATE, lpCalData, cchData);
582 return GetLocaleInfoW(Locale, LOCALE_SLONGDATE, lpCalData, cchData);
584 return GetLocaleInfoW(Locale, LOCALE_SDAYNAME1, lpCalData, cchData);
586 return GetLocaleInfoW(Locale, LOCALE_SDAYNAME2, lpCalData, cchData);
588 return GetLocaleInfoW(Locale, LOCALE_SDAYNAME3, lpCalData, cchData);
590 return GetLocaleInfoW(Locale, LOCALE_SDAYNAME4, lpCalData, cchData);
592 return GetLocaleInfoW(Locale, LOCALE_SDAYNAME5, lpCalData, cchData);
594 return GetLocaleInfoW(Locale, LOCALE_SDAYNAME6, lpCalData, cchData);
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);
664 return GetLocaleInfoW(Locale, LOCALE_SYEARMONTH, lpCalData, cchData);
665 case CAL_ITWODIGITYEARMAX:
666 if (lpValue) *lpValue = CALINFO_MAX_YEAR;
668 default: MESSAGE("Unknown caltype %ld\n",CalType & 0xffff);
674 /*********************************************************************
675 * SetCalendarInfoA (KERNEL32.@)
678 int WINAPI SetCalendarInfoA(LCID Locale, CALID Calendar, CALTYPE CalType, LPCSTR lpCalData)
680 FIXME("(%08lx,%08lx,%08lx,%s): stub\n",
681 Locale, Calendar, CalType, debugstr_a(lpCalData));
685 /*********************************************************************
686 * SetCalendarInfoW (KERNEL32.@)
689 int WINAPI SetCalendarInfoW(LCID Locale, CALID Calendar, CALTYPE CalType, LPCWSTR lpCalData)
691 FIXME("(%08lx,%08lx,%08lx,%s): stub\n",
692 Locale, Calendar, CalType, debugstr_w(lpCalData));
696 /*********************************************************************
697 * LocalFileTimeToFileTime (KERNEL32.@)
699 BOOL WINAPI LocalFileTimeToFileTime( const FILETIME *localft, LPFILETIME utcft )
702 LARGE_INTEGER local, utc;
704 local.s.LowPart = localft->dwLowDateTime;
705 local.s.HighPart = localft->dwHighDateTime;
706 if (!(status = RtlLocalTimeToSystemTime( &local, &utc )))
708 utcft->dwLowDateTime = utc.s.LowPart;
709 utcft->dwHighDateTime = utc.s.HighPart;
711 else SetLastError( RtlNtStatusToDosError(status) );
716 /*********************************************************************
717 * FileTimeToLocalFileTime (KERNEL32.@)
719 BOOL WINAPI FileTimeToLocalFileTime( const FILETIME *utcft, LPFILETIME localft )
722 LARGE_INTEGER local, utc;
724 utc.s.LowPart = utcft->dwLowDateTime;
725 utc.s.HighPart = utcft->dwHighDateTime;
726 if (!(status = RtlSystemTimeToLocalTime( &utc, &local )))
728 localft->dwLowDateTime = local.s.LowPart;
729 localft->dwHighDateTime = local.s.HighPart;
731 else SetLastError( RtlNtStatusToDosError(status) );
736 /*********************************************************************
737 * FileTimeToSystemTime (KERNEL32.@)
739 BOOL WINAPI FileTimeToSystemTime( const FILETIME *ft, LPSYSTEMTIME syst )
744 t.s.LowPart = ft->dwLowDateTime;
745 t.s.HighPart = ft->dwHighDateTime;
746 RtlTimeToTimeFields(&t, &tf);
748 syst->wYear = tf.Year;
749 syst->wMonth = tf.Month;
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;
759 /*********************************************************************
760 * SystemTimeToFileTime (KERNEL32.@)
762 BOOL WINAPI SystemTimeToFileTime( const SYSTEMTIME *syst, LPFILETIME ft )
767 tf.Year = syst->wYear;
768 tf.Month = syst->wMonth;
770 tf.Hour = syst->wHour;
771 tf.Minute = syst->wMinute;
772 tf.Second = syst->wSecond;
773 tf.Milliseconds = syst->wMilliseconds;
775 RtlTimeFieldsToTime(&tf, &t);
776 ft->dwLowDateTime = t.s.LowPart;
777 ft->dwHighDateTime = t.s.HighPart;
781 /*********************************************************************
782 * CompareFileTime (KERNEL32.@)
784 INT WINAPI CompareFileTime( const FILETIME *x, const FILETIME *y )
786 if (!x || !y) return -1;
788 if (x->dwHighDateTime > y->dwHighDateTime)
790 if (x->dwHighDateTime < y->dwHighDateTime)
792 if (x->dwLowDateTime > y->dwLowDateTime)
794 if (x->dwLowDateTime < y->dwLowDateTime)
799 /*********************************************************************
800 * GetLocalTime (KERNEL32.@)
802 VOID WINAPI GetLocalTime(LPSYSTEMTIME systime)
805 LARGE_INTEGER ft, ft2;
807 NtQuerySystemTime(&ft);
808 RtlSystemTimeToLocalTime(&ft, &ft2);
809 lft.dwLowDateTime = ft2.s.LowPart;
810 lft.dwHighDateTime = ft2.s.HighPart;
811 FileTimeToSystemTime(&lft, systime);
814 /*********************************************************************
815 * GetSystemTime (KERNEL32.@)
817 VOID WINAPI GetSystemTime(LPSYSTEMTIME systime)
822 NtQuerySystemTime(&t);
823 ft.dwLowDateTime = t.s.LowPart;
824 ft.dwHighDateTime = t.s.HighPart;
825 FileTimeToSystemTime(&ft, systime);