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) );
130 /***********************************************************************
131 * GetTimeZoneInformation (KERNEL32.@)
133 * Get information about the current local time zone.
136 * Success: TIME_ZONE_ID_STANDARD. tzinfo contains the time zone info.
137 * Failure: TIME_ZONE_ID_INVALID.
139 DWORD WINAPI GetTimeZoneInformation(
140 LPTIME_ZONE_INFORMATION tzinfo) /* [out] Destination for time zone information */
143 if ((status = RtlQueryTimeZoneInformation(tzinfo)))
144 SetLastError( RtlNtStatusToDosError(status) );
145 return TIME_ZONE_ID_STANDARD;
149 /***********************************************************************
150 * SetTimeZoneInformation (KERNEL32.@)
152 * Change the settings of the current local time zone.
155 * Success: TRUE. The time zone was updated with the settings from tzinfo
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 * Convert a utc system time to a local time in a given time zone.
349 * Success: TRUE. lpLocalTime contains the converted time
353 BOOL WINAPI SystemTimeToTzSpecificLocalTime(
354 LPTIME_ZONE_INFORMATION lpTimeZoneInformation, /* [in] The desired time zone. */
355 LPSYSTEMTIME lpUniversalTime, /* [in] The utc time to base local time on. */
356 LPSYSTEMTIME lpLocalTime) /* [out] The local time in the time zone. */
361 TIME_ZONE_INFORMATION tzinfo;
363 if (lpTimeZoneInformation != NULL)
365 memcpy(&tzinfo, lpTimeZoneInformation, sizeof(TIME_ZONE_INFORMATION));
369 if (GetTimeZoneInformation(&tzinfo) == TIME_ZONE_ID_INVALID)
373 if (!SystemTimeToFileTime(lpUniversalTime, &ft))
376 t = ft.dwHighDateTime;
378 t += (UINT)ft.dwLowDateTime;
380 if (!_GetTimezoneBias(&tzinfo, lpUniversalTime, &lBias))
383 bias = (LONGLONG)lBias * 600000000; /* 60 seconds per minute, 100000 [100-nanoseconds-ticks] per second */
386 ft.dwLowDateTime = (UINT)t;
387 ft.dwHighDateTime = (UINT)(t >> 32);
389 return FileTimeToSystemTime(&ft, lpLocalTime);
393 /***********************************************************************
394 * TzSpecificLocalTimeToSystemTime (KERNEL32.@)
396 * Converts a local time to a time in utc.
399 * Success: TRUE. lpUniversalTime contains the converted time
402 BOOL WINAPI TzSpecificLocalTimeToSystemTime(
403 LPTIME_ZONE_INFORMATION lpTimeZoneInformation, /* [in] The desired time zone. */
404 LPSYSTEMTIME lpLocalTime, /* [in] The local time. */
405 LPSYSTEMTIME lpUniversalTime) /* [out] The calculated utc time. */
410 TIME_ZONE_INFORMATION tzinfo;
412 if (lpTimeZoneInformation != NULL)
414 memcpy(&tzinfo, lpTimeZoneInformation, sizeof(TIME_ZONE_INFORMATION));
418 if (GetTimeZoneInformation(&tzinfo) == TIME_ZONE_ID_INVALID)
422 if (!SystemTimeToFileTime(lpLocalTime, &ft))
425 t = ft.dwHighDateTime;
427 t += (UINT)ft.dwLowDateTime;
429 if (!_GetTimezoneBias(&tzinfo, lpUniversalTime, &lBias))
432 bias = (LONGLONG)lBias * 600000000; /* 60 seconds per minute, 100000 [100-nanoseconds-ticks] per second */
435 ft.dwLowDateTime = (UINT)t;
436 ft.dwHighDateTime = (UINT)(t >> 32);
438 return FileTimeToSystemTime(&ft, lpUniversalTime);
442 /***********************************************************************
443 * GetSystemTimeAsFileTime (KERNEL32.@)
445 * Get the current time in utc format.
450 VOID WINAPI GetSystemTimeAsFileTime(
451 LPFILETIME time) /* [out] Destination for the current utc time */
454 NtQuerySystemTime( &t );
455 time->dwLowDateTime = t.s.LowPart;
456 time->dwHighDateTime = t.s.HighPart;
460 /*********************************************************************
461 * TIME_ClockTimeToFileTime (olorin@fandra.org, 20-Sep-1998)
463 * Used by GetProcessTimes to convert clock_t into FILETIME.
465 * Differences to UnixTimeToFileTime:
466 * 1) Divided by CLK_TCK
467 * 2) Time is relative. There is no 'starting date', so there is
468 * no need in offset correction, like in UnixTimeToFileTime
470 static void TIME_ClockTimeToFileTime(clock_t unix_time, LPFILETIME filetime)
472 ULONGLONG secs = RtlEnlargedUnsignedMultiply( unix_time, 10000000 );
473 secs = RtlExtendedLargeIntegerDivide( secs, CLK_TCK, NULL );
474 filetime->dwLowDateTime = (DWORD)secs;
475 filetime->dwHighDateTime = (DWORD)(secs >> 32);
478 /*********************************************************************
479 * GetProcessTimes (KERNEL32.@)
481 * Get the user and kernel execution times of a process,
482 * along with the creation and exit times if known.
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.
493 * lpCreationTime and lpExitTime are not initialised in the Wine implementation.
495 BOOL WINAPI GetProcessTimes(
496 HANDLE hprocess, /* [in] The process to be queried (obtained from PROCESS_QUERY_INFORMATION). */
497 LPFILETIME lpCreationTime, /* [out] The creation time of the process. */
498 LPFILETIME lpExitTime, /* [out] The exit time of the process if exited. */
499 LPFILETIME lpKernelTime, /* [out] The time spent in kernal routines in 100's of nanoseconds. */
500 LPFILETIME lpUserTime) /* [out] The time spent in user routines in 100's of nanoseconds. */
505 TIME_ClockTimeToFileTime(tms.tms_utime,lpUserTime);
506 TIME_ClockTimeToFileTime(tms.tms_stime,lpKernelTime);
510 /*********************************************************************
511 * GetCalendarInfoA (KERNEL32.@)
514 int WINAPI GetCalendarInfoA(LCID Locale, CALID Calendar, CALTYPE CalType,
515 LPSTR lpCalData, int cchData, LPDWORD lpValue)
518 LPWSTR lpCalDataW = NULL;
520 FIXME("(%08lx,%08lx,%08lx,%p,%d,%p): quarter-stub\n",
521 Locale, Calendar, CalType, lpCalData, cchData, lpValue);
522 /* FIXME: Should verify if Locale is allowable in ANSI, as per MSDN */
525 if(!(lpCalDataW = HeapAlloc(GetProcessHeap(), 0, cchData*sizeof(WCHAR)))) return 0;
527 ret = GetCalendarInfoW(Locale, Calendar, CalType, lpCalDataW, cchData, lpValue);
528 if(ret && lpCalDataW && lpCalData)
529 WideCharToMultiByte(CP_ACP, 0, lpCalDataW, cchData, lpCalData, cchData, NULL, NULL);
531 HeapFree(GetProcessHeap(), 0, lpCalDataW);
536 /*********************************************************************
537 * GetCalendarInfoW (KERNEL32.@)
539 * See GetCalendarInfoA.
541 int WINAPI GetCalendarInfoW(LCID Locale, CALID Calendar, CALTYPE CalType,
542 LPWSTR lpCalData, int cchData, LPDWORD lpValue)
544 FIXME("(%08lx,%08lx,%08lx,%p,%d,%p): quarter-stub\n",
545 Locale, Calendar, CalType, lpCalData, cchData, lpValue);
547 if (CalType & CAL_NOUSEROVERRIDE)
548 FIXME("flag CAL_NOUSEROVERRIDE used, not fully implemented\n");
549 if (CalType & CAL_USE_CP_ACP)
550 FIXME("flag CAL_USE_CP_ACP used, not fully implemented\n");
552 if (CalType & CAL_RETURN_NUMBER) {
553 if (lpCalData != NULL)
554 WARN("lpCalData not NULL (%p) when it should!\n", lpCalData);
556 WARN("cchData not 0 (%d) when it should!\n", cchData);
559 WARN("lpValue not NULL (%p) when it should!\n", lpValue);
562 /* FIXME: No verification is made yet wrt Locale
563 * for the CALTYPES not requiring GetLocaleInfoA */
564 switch (CalType & ~(CAL_NOUSEROVERRIDE|CAL_RETURN_NUMBER|CAL_USE_CP_ACP)) {
565 case CAL_ICALINTVALUE:
566 FIXME("Unimplemented caltype %ld\n", CalType & 0xffff);
569 FIXME("Unimplemented caltype %ld\n", CalType & 0xffff);
571 case CAL_IYEAROFFSETRANGE:
572 FIXME("Unimplemented caltype %ld\n", CalType & 0xffff);
575 FIXME("Unimplemented caltype %ld\n", CalType & 0xffff);
578 return GetLocaleInfoW(Locale, LOCALE_SSHORTDATE, lpCalData, cchData);
580 return GetLocaleInfoW(Locale, LOCALE_SLONGDATE, lpCalData, cchData);
582 return GetLocaleInfoW(Locale, LOCALE_SDAYNAME1, lpCalData, cchData);
584 return GetLocaleInfoW(Locale, LOCALE_SDAYNAME2, lpCalData, cchData);
586 return GetLocaleInfoW(Locale, LOCALE_SDAYNAME3, lpCalData, cchData);
588 return GetLocaleInfoW(Locale, LOCALE_SDAYNAME4, lpCalData, cchData);
590 return GetLocaleInfoW(Locale, LOCALE_SDAYNAME5, lpCalData, cchData);
592 return GetLocaleInfoW(Locale, LOCALE_SDAYNAME6, lpCalData, cchData);
594 return GetLocaleInfoW(Locale, LOCALE_SDAYNAME7, lpCalData, cchData);
595 case CAL_SABBREVDAYNAME1:
596 return GetLocaleInfoW(Locale, LOCALE_SABBREVDAYNAME1, lpCalData, cchData);
597 case CAL_SABBREVDAYNAME2:
598 return GetLocaleInfoW(Locale, LOCALE_SABBREVDAYNAME2, lpCalData, cchData);
599 case CAL_SABBREVDAYNAME3:
600 return GetLocaleInfoW(Locale, LOCALE_SABBREVDAYNAME3, lpCalData, cchData);
601 case CAL_SABBREVDAYNAME4:
602 return GetLocaleInfoW(Locale, LOCALE_SABBREVDAYNAME4, lpCalData, cchData);
603 case CAL_SABBREVDAYNAME5:
604 return GetLocaleInfoW(Locale, LOCALE_SABBREVDAYNAME5, lpCalData, cchData);
605 case CAL_SABBREVDAYNAME6:
606 return GetLocaleInfoW(Locale, LOCALE_SABBREVDAYNAME6, lpCalData, cchData);
607 case CAL_SABBREVDAYNAME7:
608 return GetLocaleInfoW(Locale, LOCALE_SABBREVDAYNAME7, lpCalData, cchData);
609 case CAL_SMONTHNAME1:
610 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME1, lpCalData, cchData);
611 case CAL_SMONTHNAME2:
612 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME2, lpCalData, cchData);
613 case CAL_SMONTHNAME3:
614 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME3, lpCalData, cchData);
615 case CAL_SMONTHNAME4:
616 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME4, lpCalData, cchData);
617 case CAL_SMONTHNAME5:
618 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME5, lpCalData, cchData);
619 case CAL_SMONTHNAME6:
620 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME6, lpCalData, cchData);
621 case CAL_SMONTHNAME7:
622 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME7, lpCalData, cchData);
623 case CAL_SMONTHNAME8:
624 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME8, lpCalData, cchData);
625 case CAL_SMONTHNAME9:
626 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME9, lpCalData, cchData);
627 case CAL_SMONTHNAME10:
628 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME10, lpCalData, cchData);
629 case CAL_SMONTHNAME11:
630 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME11, lpCalData, cchData);
631 case CAL_SMONTHNAME12:
632 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME12, lpCalData, cchData);
633 case CAL_SMONTHNAME13:
634 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME13, lpCalData, cchData);
635 case CAL_SABBREVMONTHNAME1:
636 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME1, lpCalData, cchData);
637 case CAL_SABBREVMONTHNAME2:
638 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME2, lpCalData, cchData);
639 case CAL_SABBREVMONTHNAME3:
640 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME3, lpCalData, cchData);
641 case CAL_SABBREVMONTHNAME4:
642 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME4, lpCalData, cchData);
643 case CAL_SABBREVMONTHNAME5:
644 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME5, lpCalData, cchData);
645 case CAL_SABBREVMONTHNAME6:
646 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME6, lpCalData, cchData);
647 case CAL_SABBREVMONTHNAME7:
648 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME7, lpCalData, cchData);
649 case CAL_SABBREVMONTHNAME8:
650 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME8, lpCalData, cchData);
651 case CAL_SABBREVMONTHNAME9:
652 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME9, lpCalData, cchData);
653 case CAL_SABBREVMONTHNAME10:
654 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME10, lpCalData, cchData);
655 case CAL_SABBREVMONTHNAME11:
656 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME11, lpCalData, cchData);
657 case CAL_SABBREVMONTHNAME12:
658 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME12, lpCalData, cchData);
659 case CAL_SABBREVMONTHNAME13:
660 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME13, lpCalData, cchData);
662 return GetLocaleInfoW(Locale, LOCALE_SYEARMONTH, lpCalData, cchData);
663 case CAL_ITWODIGITYEARMAX:
664 if (lpValue) *lpValue = CALINFO_MAX_YEAR;
666 default: MESSAGE("Unknown caltype %ld\n",CalType & 0xffff);
672 /*********************************************************************
673 * SetCalendarInfoA (KERNEL32.@)
676 int WINAPI SetCalendarInfoA(LCID Locale, CALID Calendar, CALTYPE CalType, LPCSTR lpCalData)
678 FIXME("(%08lx,%08lx,%08lx,%s): stub\n",
679 Locale, Calendar, CalType, debugstr_a(lpCalData));
683 /*********************************************************************
684 * SetCalendarInfoW (KERNEL32.@)
686 * See SetCalendarInfoA.
688 int WINAPI SetCalendarInfoW(LCID Locale, CALID Calendar, CALTYPE CalType, LPCWSTR lpCalData)
690 FIXME("(%08lx,%08lx,%08lx,%s): stub\n",
691 Locale, Calendar, CalType, debugstr_w(lpCalData));
695 /*********************************************************************
696 * LocalFileTimeToFileTime (KERNEL32.@)
698 BOOL WINAPI LocalFileTimeToFileTime( const FILETIME *localft, LPFILETIME utcft )
701 LARGE_INTEGER local, utc;
703 local.s.LowPart = localft->dwLowDateTime;
704 local.s.HighPart = localft->dwHighDateTime;
705 if (!(status = RtlLocalTimeToSystemTime( &local, &utc )))
707 utcft->dwLowDateTime = utc.s.LowPart;
708 utcft->dwHighDateTime = utc.s.HighPart;
710 else SetLastError( RtlNtStatusToDosError(status) );
715 /*********************************************************************
716 * FileTimeToLocalFileTime (KERNEL32.@)
718 BOOL WINAPI FileTimeToLocalFileTime( const FILETIME *utcft, LPFILETIME localft )
721 LARGE_INTEGER local, utc;
723 utc.s.LowPart = utcft->dwLowDateTime;
724 utc.s.HighPart = utcft->dwHighDateTime;
725 if (!(status = RtlSystemTimeToLocalTime( &utc, &local )))
727 localft->dwLowDateTime = local.s.LowPart;
728 localft->dwHighDateTime = local.s.HighPart;
730 else SetLastError( RtlNtStatusToDosError(status) );
735 /*********************************************************************
736 * FileTimeToSystemTime (KERNEL32.@)
738 BOOL WINAPI FileTimeToSystemTime( const FILETIME *ft, LPSYSTEMTIME syst )
743 t.s.LowPart = ft->dwLowDateTime;
744 t.s.HighPart = ft->dwHighDateTime;
745 RtlTimeToTimeFields(&t, &tf);
747 syst->wYear = tf.Year;
748 syst->wMonth = tf.Month;
750 syst->wHour = tf.Hour;
751 syst->wMinute = tf.Minute;
752 syst->wSecond = tf.Second;
753 syst->wMilliseconds = tf.Milliseconds;
754 syst->wDayOfWeek = tf.Weekday;
758 /*********************************************************************
759 * SystemTimeToFileTime (KERNEL32.@)
761 BOOL WINAPI SystemTimeToFileTime( const SYSTEMTIME *syst, LPFILETIME ft )
766 tf.Year = syst->wYear;
767 tf.Month = syst->wMonth;
769 tf.Hour = syst->wHour;
770 tf.Minute = syst->wMinute;
771 tf.Second = syst->wSecond;
772 tf.Milliseconds = syst->wMilliseconds;
774 RtlTimeFieldsToTime(&tf, &t);
775 ft->dwLowDateTime = t.s.LowPart;
776 ft->dwHighDateTime = t.s.HighPart;
780 /*********************************************************************
781 * CompareFileTime (KERNEL32.@)
783 * Compare two FILETIME's to each other.
787 * y [I] time to compare to x
790 * -1, 0, or 1 indicating that x is less than, equal to, or greater
791 * than y respectively.
793 INT WINAPI CompareFileTime( const FILETIME *x, const FILETIME *y )
795 if (!x || !y) return -1;
797 if (x->dwHighDateTime > y->dwHighDateTime)
799 if (x->dwHighDateTime < y->dwHighDateTime)
801 if (x->dwLowDateTime > y->dwLowDateTime)
803 if (x->dwLowDateTime < y->dwLowDateTime)
808 /*********************************************************************
809 * GetLocalTime (KERNEL32.@)
811 * Get the current local time.
816 VOID WINAPI GetLocalTime(LPSYSTEMTIME systime) /* [O] Destination for current time */
819 LARGE_INTEGER ft, ft2;
821 NtQuerySystemTime(&ft);
822 RtlSystemTimeToLocalTime(&ft, &ft2);
823 lft.dwLowDateTime = ft2.s.LowPart;
824 lft.dwHighDateTime = ft2.s.HighPart;
825 FileTimeToSystemTime(&lft, systime);
828 /*********************************************************************
829 * GetSystemTime (KERNEL32.@)
831 * Get the current system time.
836 VOID WINAPI GetSystemTime(LPSYSTEMTIME systime) /* [O] Destination for current time */
841 NtQuerySystemTime(&t);
842 ft.dwLowDateTime = t.s.LowPart;
843 ft.dwHighDateTime = t.s.HighPart;
844 FileTimeToSystemTime(&ft, systime);