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 * Sets the local time using current time zone and daylight
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. */
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 * 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.
88 * Always returns true.
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;
106 /***********************************************************************
107 * SetSystemTime (KERNEL32.@)
109 * Sets the system time (utc).
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. */
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) );
132 /***********************************************************************
133 * GetTimeZoneInformation (KERNEL32.@)
135 * Fills in the a time zone information structure with values based on
136 * the current local time.
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. */
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.
159 * True on successful setting of the time zone.
161 BOOL WINAPI SetTimeZoneInformation(
162 const LPTIME_ZONE_INFORMATION tzinfo) /* [in] The new time zone. */
165 if ((status = RtlSetTimeZoneInformation(tzinfo)))
166 SetLastError( RtlNtStatusToDosError(status) );
171 /***********************************************************************
172 * _DayLightCompareDate
174 * Compares two dates without looking at the year
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 */
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)
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));
219 if (weekofmonth == 5)
221 /* Go to the beginning of the next month. */
222 if (++tmp.wMonth > 12)
229 if (!SystemTimeToFileTime(&tmp, &tmp_ft))
232 if (weekofmonth == 5)
236 t = tmp_ft.dwHighDateTime;
238 t += (UINT)tmp_ft.dwLowDateTime;
240 /* substract one day */
245 tmp_ft.dwLowDateTime = (UINT)t;
246 tmp_ft.dwHighDateTime = (UINT)(t >> 32);
249 if (!FileTimeToSystemTime(&tmp_ft, &tmp))
252 if (weekofmonth == 5)
254 /* calculate the last matching day of the week in this month */
255 int dif = tmp.wDayOfWeek - compareDate->wDayOfWeek;
259 limit_day = tmp.wDay - dif;
263 /* calulcate the matching day of the week in the given week */
264 int dif = compareDate->wDayOfWeek - tmp.wDayOfWeek;
268 limit_day = tmp.wDay + 7*(weekofmonth-1) + dif;
273 limit_day = compareDate->wDay;
276 if (date->wDay < limit_day)
279 if (date->wDay > limit_day)
282 return 0; /* date is equal to the date limit. */
286 /***********************************************************************
289 * Calculates the local time bias for a given time zone
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 */
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);
318 /* check for daylight saving */
319 ret = _DayLightCompareDate(lpSystemTime, &lpTimeZoneInformation->StandardDate);
323 beforedaylightsaving = ret < 0;
325 _DayLightCompareDate(lpSystemTime, &lpTimeZoneInformation->DaylightDate);
329 afterdaylightsaving = ret >= 0;
331 if (!beforedaylightsaving && !afterdaylightsaving)
332 daylightsaving = TRUE;
336 bias += lpTimeZoneInformation->DaylightBias;
337 else if (lpTimeZoneInformation->StandardDate.wMonth != 0)
338 bias += lpTimeZoneInformation->StandardBias;
346 /***********************************************************************
347 * SystemTimeToTzSpecificLocalTime (KERNEL32.@)
349 * Converts the system time (utc) to the local time in the specified time zone.
353 * Returns true when the local time was calculated.
354 * Returns TRUE when the local time was calculated.
358 BOOL WINAPI SystemTimeToTzSpecificLocalTime(
359 LPTIME_ZONE_INFORMATION lpTimeZoneInformation, /* [in] The desired time zone. */
360 LPSYSTEMTIME lpUniversalTime, /* [in] The utc time to base local time on. */
361 LPSYSTEMTIME lpLocalTime) /* [out] The local time in the time zone. */
366 TIME_ZONE_INFORMATION tzinfo;
368 if (lpTimeZoneInformation != NULL)
370 memcpy(&tzinfo, lpTimeZoneInformation, sizeof(TIME_ZONE_INFORMATION));
374 if (GetTimeZoneInformation(&tzinfo) == TIME_ZONE_ID_INVALID)
378 if (!SystemTimeToFileTime(lpUniversalTime, &ft))
381 t = ft.dwHighDateTime;
383 t += (UINT)ft.dwLowDateTime;
385 if (!_GetTimezoneBias(&tzinfo, lpUniversalTime, &lBias))
388 bias = lBias * 600000000; /* 60 seconds per minute, 100000 [100-nanoseconds-ticks] per second */
391 ft.dwLowDateTime = (UINT)t;
392 ft.dwHighDateTime = (UINT)(t >> 32);
394 return FileTimeToSystemTime(&ft, lpLocalTime);
398 /***********************************************************************
399 * TzSpecificLocalTimeToSystemTime (KERNEL32.@)
401 * Converts a local time to a time in Coordinated Universal Time (UTC).
405 * Returns TRUE when the utc time was calculated.
408 BOOL WINAPI TzSpecificLocalTimeToSystemTime(
409 LPTIME_ZONE_INFORMATION lpTimeZoneInformation, /* [in] The desired time zone. */
410 LPSYSTEMTIME lpLocalTime, /* [in] The local time. */
411 LPSYSTEMTIME lpUniversalTime) /* [out] The calculated utc time. */
416 TIME_ZONE_INFORMATION tzinfo;
418 if (lpTimeZoneInformation != NULL)
420 memcpy(&tzinfo, lpTimeZoneInformation, sizeof(TIME_ZONE_INFORMATION));
424 if (GetTimeZoneInformation(&tzinfo) == TIME_ZONE_ID_INVALID)
428 if (!SystemTimeToFileTime(lpLocalTime, &ft))
431 t = ft.dwHighDateTime;
433 t += (UINT)ft.dwLowDateTime;
435 if (!_GetTimezoneBias(&tzinfo, lpUniversalTime, &lBias))
438 bias = lBias * 600000000; /* 60 seconds per minute, 100000 [100-nanoseconds-ticks] per second */
441 ft.dwLowDateTime = (UINT)t;
442 ft.dwHighDateTime = (UINT)(t >> 32);
444 return FileTimeToSystemTime(&ft, lpUniversalTime);
450 /***********************************************************************
451 * GetSystemTimeAsFileTime (KERNEL32.@)
453 * Fills in a file time structure with the current time in UTC format.
455 VOID WINAPI GetSystemTimeAsFileTime(
456 LPFILETIME time) /* [out] The file time struct to be filled with the system time. */
459 NtQuerySystemTime( &t );
460 time->dwLowDateTime = t.s.LowPart;
461 time->dwHighDateTime = t.s.HighPart;
465 /*********************************************************************
466 * TIME_ClockTimeToFileTime (olorin@fandra.org, 20-Sep-1998)
468 * Used by GetProcessTimes to convert clock_t into FILETIME.
470 * Differences to UnixTimeToFileTime:
471 * 1) Divided by CLK_TCK
472 * 2) Time is relative. There is no 'starting date', so there is
473 * no need in offset correction, like in UnixTimeToFileTime
475 static void TIME_ClockTimeToFileTime(clock_t unix_time, LPFILETIME filetime)
477 ULONGLONG secs = RtlEnlargedUnsignedMultiply( unix_time, 10000000 );
478 secs = RtlExtendedLargeIntegerDivide( secs, CLK_TCK, NULL );
479 filetime->dwLowDateTime = (DWORD)secs;
480 filetime->dwHighDateTime = (DWORD)(secs >> 32);
483 /*********************************************************************
484 * GetProcessTimes (KERNEL32.@)
486 * Returns the user and kernel execution times of a process,
487 * along with the creation and exit times if known.
490 * Would be nice to subtract the cpu time, used by Wine at startup.
491 * Also, there is a need to separate times used by different applications.
495 * Always returns true.
499 * lpCreationTime, lpExitTime are NOT INITIALIZED.
501 BOOL WINAPI GetProcessTimes(
502 HANDLE hprocess, /* [in] The process to be queried (obtained from PROCESS_QUERY_INFORMATION). */
503 LPFILETIME lpCreationTime, /* [out] The creation time of the process. */
504 LPFILETIME lpExitTime, /* [out] The exit time of the process if exited. */
505 LPFILETIME lpKernelTime, /* [out] The time spent in kernal routines in 100's of nanoseconds. */
506 LPFILETIME lpUserTime) /* [out] The time spent in user routines in 100's of nanoseconds. */
511 TIME_ClockTimeToFileTime(tms.tms_utime,lpUserTime);
512 TIME_ClockTimeToFileTime(tms.tms_stime,lpKernelTime);
516 /*********************************************************************
517 * GetCalendarInfoA (KERNEL32.@)
520 int WINAPI GetCalendarInfoA(LCID Locale, CALID Calendar, CALTYPE CalType,
521 LPSTR lpCalData, int cchData, LPDWORD lpValue)
524 LPWSTR lpCalDataW = NULL;
526 FIXME("(%08lx,%08lx,%08lx,%p,%d,%p): quarter-stub\n",
527 Locale, Calendar, CalType, lpCalData, cchData, lpValue);
528 /* FIXME: Should verify if Locale is allowable in ANSI, as per MSDN */
531 if(!(lpCalDataW = HeapAlloc(GetProcessHeap(), 0, cchData*sizeof(WCHAR)))) return 0;
533 ret = GetCalendarInfoW(Locale, Calendar, CalType, lpCalDataW, cchData, lpValue);
534 if(ret && lpCalDataW && lpCalData)
535 WideCharToMultiByte(CP_ACP, 0, lpCalDataW, cchData, lpCalData, cchData, NULL, NULL);
537 HeapFree(GetProcessHeap(), 0, lpCalDataW);
542 /*********************************************************************
543 * GetCalendarInfoW (KERNEL32.@)
546 int WINAPI GetCalendarInfoW(LCID Locale, CALID Calendar, CALTYPE CalType,
547 LPWSTR lpCalData, int cchData, LPDWORD lpValue)
549 FIXME("(%08lx,%08lx,%08lx,%p,%d,%p): quarter-stub\n",
550 Locale, Calendar, CalType, lpCalData, cchData, lpValue);
552 if (CalType & CAL_NOUSEROVERRIDE)
553 FIXME("flag CAL_NOUSEROVERRIDE used, not fully implemented\n");
554 if (CalType & CAL_USE_CP_ACP)
555 FIXME("flag CAL_USE_CP_ACP used, not fully implemented\n");
557 if (CalType & CAL_RETURN_NUMBER) {
558 if (lpCalData != NULL)
559 WARN("lpCalData not NULL (%p) when it should!\n", lpCalData);
561 WARN("cchData not 0 (%d) when it should!\n", cchData);
564 WARN("lpValue not NULL (%p) when it should!\n", lpValue);
567 /* FIXME: No verification is made yet wrt Locale
568 * for the CALTYPES not requiring GetLocaleInfoA */
569 switch (CalType & ~(CAL_NOUSEROVERRIDE|CAL_RETURN_NUMBER|CAL_USE_CP_ACP)) {
570 case CAL_ICALINTVALUE:
571 FIXME("Unimplemented caltype %ld\n", CalType & 0xffff);
574 FIXME("Unimplemented caltype %ld\n", CalType & 0xffff);
576 case CAL_IYEAROFFSETRANGE:
577 FIXME("Unimplemented caltype %ld\n", CalType & 0xffff);
580 FIXME("Unimplemented caltype %ld\n", CalType & 0xffff);
583 return GetLocaleInfoW(Locale, LOCALE_SSHORTDATE, lpCalData, cchData);
585 return GetLocaleInfoW(Locale, LOCALE_SLONGDATE, lpCalData, cchData);
587 return GetLocaleInfoW(Locale, LOCALE_SDAYNAME1, lpCalData, cchData);
589 return GetLocaleInfoW(Locale, LOCALE_SDAYNAME2, lpCalData, cchData);
591 return GetLocaleInfoW(Locale, LOCALE_SDAYNAME3, lpCalData, cchData);
593 return GetLocaleInfoW(Locale, LOCALE_SDAYNAME4, lpCalData, cchData);
595 return GetLocaleInfoW(Locale, LOCALE_SDAYNAME5, lpCalData, cchData);
597 return GetLocaleInfoW(Locale, LOCALE_SDAYNAME6, lpCalData, cchData);
599 return GetLocaleInfoW(Locale, LOCALE_SDAYNAME7, lpCalData, cchData);
600 case CAL_SABBREVDAYNAME1:
601 return GetLocaleInfoW(Locale, LOCALE_SABBREVDAYNAME1, lpCalData, cchData);
602 case CAL_SABBREVDAYNAME2:
603 return GetLocaleInfoW(Locale, LOCALE_SABBREVDAYNAME2, lpCalData, cchData);
604 case CAL_SABBREVDAYNAME3:
605 return GetLocaleInfoW(Locale, LOCALE_SABBREVDAYNAME3, lpCalData, cchData);
606 case CAL_SABBREVDAYNAME4:
607 return GetLocaleInfoW(Locale, LOCALE_SABBREVDAYNAME4, lpCalData, cchData);
608 case CAL_SABBREVDAYNAME5:
609 return GetLocaleInfoW(Locale, LOCALE_SABBREVDAYNAME5, lpCalData, cchData);
610 case CAL_SABBREVDAYNAME6:
611 return GetLocaleInfoW(Locale, LOCALE_SABBREVDAYNAME6, lpCalData, cchData);
612 case CAL_SABBREVDAYNAME7:
613 return GetLocaleInfoW(Locale, LOCALE_SABBREVDAYNAME7, lpCalData, cchData);
614 case CAL_SMONTHNAME1:
615 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME1, lpCalData, cchData);
616 case CAL_SMONTHNAME2:
617 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME2, lpCalData, cchData);
618 case CAL_SMONTHNAME3:
619 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME3, lpCalData, cchData);
620 case CAL_SMONTHNAME4:
621 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME4, lpCalData, cchData);
622 case CAL_SMONTHNAME5:
623 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME5, lpCalData, cchData);
624 case CAL_SMONTHNAME6:
625 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME6, lpCalData, cchData);
626 case CAL_SMONTHNAME7:
627 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME7, lpCalData, cchData);
628 case CAL_SMONTHNAME8:
629 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME8, lpCalData, cchData);
630 case CAL_SMONTHNAME9:
631 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME9, lpCalData, cchData);
632 case CAL_SMONTHNAME10:
633 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME10, lpCalData, cchData);
634 case CAL_SMONTHNAME11:
635 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME11, lpCalData, cchData);
636 case CAL_SMONTHNAME12:
637 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME12, lpCalData, cchData);
638 case CAL_SMONTHNAME13:
639 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME13, lpCalData, cchData);
640 case CAL_SABBREVMONTHNAME1:
641 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME1, lpCalData, cchData);
642 case CAL_SABBREVMONTHNAME2:
643 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME2, lpCalData, cchData);
644 case CAL_SABBREVMONTHNAME3:
645 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME3, lpCalData, cchData);
646 case CAL_SABBREVMONTHNAME4:
647 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME4, lpCalData, cchData);
648 case CAL_SABBREVMONTHNAME5:
649 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME5, lpCalData, cchData);
650 case CAL_SABBREVMONTHNAME6:
651 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME6, lpCalData, cchData);
652 case CAL_SABBREVMONTHNAME7:
653 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME7, lpCalData, cchData);
654 case CAL_SABBREVMONTHNAME8:
655 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME8, lpCalData, cchData);
656 case CAL_SABBREVMONTHNAME9:
657 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME9, lpCalData, cchData);
658 case CAL_SABBREVMONTHNAME10:
659 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME10, lpCalData, cchData);
660 case CAL_SABBREVMONTHNAME11:
661 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME11, lpCalData, cchData);
662 case CAL_SABBREVMONTHNAME12:
663 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME12, lpCalData, cchData);
664 case CAL_SABBREVMONTHNAME13:
665 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME13, lpCalData, cchData);
667 return GetLocaleInfoW(Locale, LOCALE_SYEARMONTH, lpCalData, cchData);
668 case CAL_ITWODIGITYEARMAX:
669 if (lpValue) *lpValue = CALINFO_MAX_YEAR;
671 default: MESSAGE("Unknown caltype %ld\n",CalType & 0xffff);
677 /*********************************************************************
678 * SetCalendarInfoA (KERNEL32.@)
681 int WINAPI SetCalendarInfoA(LCID Locale, CALID Calendar, CALTYPE CalType, LPCSTR lpCalData)
683 FIXME("(%08lx,%08lx,%08lx,%s): stub\n",
684 Locale, Calendar, CalType, debugstr_a(lpCalData));
688 /*********************************************************************
689 * SetCalendarInfoW (KERNEL32.@)
692 int WINAPI SetCalendarInfoW(LCID Locale, CALID Calendar, CALTYPE CalType, LPCWSTR lpCalData)
694 FIXME("(%08lx,%08lx,%08lx,%s): stub\n",
695 Locale, Calendar, CalType, debugstr_w(lpCalData));
699 /*********************************************************************
700 * LocalFileTimeToFileTime (KERNEL32.@)
702 BOOL WINAPI LocalFileTimeToFileTime( const FILETIME *localft, LPFILETIME utcft )
705 LARGE_INTEGER local, utc;
707 local.s.LowPart = localft->dwLowDateTime;
708 local.s.HighPart = localft->dwHighDateTime;
709 if (!(status = RtlLocalTimeToSystemTime( &local, &utc )))
711 utcft->dwLowDateTime = utc.s.LowPart;
712 utcft->dwHighDateTime = utc.s.HighPart;
714 else SetLastError( RtlNtStatusToDosError(status) );
719 /*********************************************************************
720 * FileTimeToLocalFileTime (KERNEL32.@)
722 BOOL WINAPI FileTimeToLocalFileTime( const FILETIME *utcft, LPFILETIME localft )
725 LARGE_INTEGER local, utc;
727 utc.s.LowPart = utcft->dwLowDateTime;
728 utc.s.HighPart = utcft->dwHighDateTime;
729 if (!(status = RtlSystemTimeToLocalTime( &utc, &local )))
731 localft->dwLowDateTime = local.s.LowPart;
732 localft->dwHighDateTime = local.s.HighPart;
734 else SetLastError( RtlNtStatusToDosError(status) );
739 /*********************************************************************
740 * FileTimeToSystemTime (KERNEL32.@)
742 BOOL WINAPI FileTimeToSystemTime( const FILETIME *ft, LPSYSTEMTIME syst )
747 t.s.LowPart = ft->dwLowDateTime;
748 t.s.HighPart = ft->dwHighDateTime;
749 RtlTimeToTimeFields(&t, &tf);
751 syst->wYear = tf.Year;
752 syst->wMonth = tf.Month;
754 syst->wHour = tf.Hour;
755 syst->wMinute = tf.Minute;
756 syst->wSecond = tf.Second;
757 syst->wMilliseconds = tf.Milliseconds;
758 syst->wDayOfWeek = tf.Weekday;
762 /*********************************************************************
763 * SystemTimeToFileTime (KERNEL32.@)
765 BOOL WINAPI SystemTimeToFileTime( const SYSTEMTIME *syst, LPFILETIME ft )
770 tf.Year = syst->wYear;
771 tf.Month = syst->wMonth;
773 tf.Hour = syst->wHour;
774 tf.Minute = syst->wMinute;
775 tf.Second = syst->wSecond;
776 tf.Milliseconds = syst->wMilliseconds;
778 RtlTimeFieldsToTime(&tf, &t);
779 ft->dwLowDateTime = t.s.LowPart;
780 ft->dwHighDateTime = t.s.HighPart;
784 /*********************************************************************
785 * CompareFileTime (KERNEL32.@)
787 INT WINAPI CompareFileTime( const FILETIME *x, const FILETIME *y )
789 if (!x || !y) return -1;
791 if (x->dwHighDateTime > y->dwHighDateTime)
793 if (x->dwHighDateTime < y->dwHighDateTime)
795 if (x->dwLowDateTime > y->dwLowDateTime)
797 if (x->dwLowDateTime < y->dwLowDateTime)
802 /*********************************************************************
803 * GetLocalTime (KERNEL32.@)
805 VOID WINAPI GetLocalTime(LPSYSTEMTIME systime)
808 LARGE_INTEGER ft, ft2;
810 NtQuerySystemTime(&ft);
811 RtlSystemTimeToLocalTime(&ft, &ft2);
812 lft.dwLowDateTime = ft2.s.LowPart;
813 lft.dwHighDateTime = ft2.s.HighPart;
814 FileTimeToSystemTime(&lft, systime);
817 /*********************************************************************
818 * GetSystemTime (KERNEL32.@)
820 VOID WINAPI GetSystemTime(LPSYSTEMTIME systime)
825 NtQuerySystemTime(&t);
826 ft.dwLowDateTime = t.s.LowPart;
827 ft.dwHighDateTime = t.s.HighPart;
828 FileTimeToSystemTime(&ft, systime);