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
30 #ifdef HAVE_SYS_TIME_H
31 # include <sys/time.h>
33 #ifdef HAVE_SYS_TIMES_H
34 # include <sys/times.h>
37 #define NONAMELESSUNION
38 #define NONAMELESSSTRUCT
46 #include "kernel_private.h"
47 #include "wine/unicode.h"
48 #include "wine/debug.h"
50 WINE_DEFAULT_DEBUG_CHANNEL(time);
52 /* maximum time adjustment in seconds for SetLocalTime and SetSystemTime */
53 #define SETTIME_MAX_ADJUST 120
54 #define CALINFO_MAX_YEAR 2029
57 /***********************************************************************
58 * SetLocalTime (KERNEL32.@)
60 * Set the local time using current time zone and daylight
64 * Success: TRUE. The time was set
65 * Failure: FALSE, if the time was invalid or caller does not have
66 * permission to change the time.
68 BOOL WINAPI SetLocalTime(
69 const SYSTEMTIME *systime) /* [in] The desired local time. */
72 LARGE_INTEGER st, st2;
75 SystemTimeToFileTime( systime, &ft );
76 st.u.LowPart = ft.dwLowDateTime;
77 st.u.HighPart = ft.dwHighDateTime;
78 RtlLocalTimeToSystemTime( &st, &st2 );
80 if ((status = NtSetSystemTime(&st2, NULL)))
81 SetLastError( RtlNtStatusToDosError(status) );
86 /***********************************************************************
87 * GetSystemTimeAdjustment (KERNEL32.@)
89 * Get the period between clock interrupts and the amount the clock
90 * is adjusted each interrupt so as to keep it in sync with an external source.
96 * Only the special case of disabled time adjustments is supported.
98 BOOL WINAPI GetSystemTimeAdjustment(
99 PDWORD lpTimeAdjustment, /* [out] The clock adjustment per interupt in 100's of nanoseconds. */
100 PDWORD lpTimeIncrement, /* [out] The time between clock interupts in 100's of nanoseconds. */
101 PBOOL lpTimeAdjustmentDisabled) /* [out] The clock synchonisation has been disabled. */
103 *lpTimeAdjustment = 0;
104 *lpTimeIncrement = 0;
105 *lpTimeAdjustmentDisabled = TRUE;
110 /***********************************************************************
111 * SetSystemTime (KERNEL32.@)
113 * Set the system time in utc.
116 * Success: TRUE. The time was set
117 * Failure: FALSE, if the time was invalid or caller does not have
118 * permission to change the time.
120 BOOL WINAPI SetSystemTime(
121 const SYSTEMTIME *systime) /* [in] The desired system time. */
127 SystemTimeToFileTime( systime, &ft );
128 t.u.LowPart = ft.dwLowDateTime;
129 t.u.HighPart = ft.dwHighDateTime;
130 if ((status = NtSetSystemTime(&t, NULL)))
131 SetLastError( RtlNtStatusToDosError(status) );
135 /***********************************************************************
136 * SetSystemTimeAdjustment (KERNEL32.@)
138 * Enables or disables the timing adjustments to the system's clock.
144 BOOL WINAPI SetSystemTimeAdjustment(
145 DWORD dwTimeAdjustment,
146 BOOL bTimeAdjustmentDisabled)
148 /* Fake function for now... */
149 FIXME("(%08lx,%d): stub !\n", dwTimeAdjustment, bTimeAdjustmentDisabled);
154 /***********************************************************************
155 * GetTimeZoneInformation (KERNEL32.@)
157 * Get information about the current local time zone.
160 * Success: TIME_ZONE_ID_STANDARD. tzinfo contains the time zone info.
161 * Failure: TIME_ZONE_ID_INVALID.
162 * FIXME: return TIME_ZONE_ID_DAYLIGHT when daylight saving is on.
164 DWORD WINAPI GetTimeZoneInformation(
165 LPTIME_ZONE_INFORMATION tzinfo) /* [out] Destination for time zone information */
168 if ((status = RtlQueryTimeZoneInformation(tzinfo)))
169 SetLastError( RtlNtStatusToDosError(status) );
170 return TIME_ZONE_ID_STANDARD;
174 /***********************************************************************
175 * SetTimeZoneInformation (KERNEL32.@)
177 * Change the settings of the current local time zone.
180 * Success: TRUE. The time zone was updated with the settings from tzinfo
183 BOOL WINAPI SetTimeZoneInformation(
184 const LPTIME_ZONE_INFORMATION tzinfo) /* [in] The new time zone. */
187 if ((status = RtlSetTimeZoneInformation(tzinfo)))
188 SetLastError( RtlNtStatusToDosError(status) );
193 /***********************************************************************
194 * _DayLightCompareDate
196 * Compares two dates without looking at the year
200 * -1 if date < compareDate
201 * 0 if date == compareDate
202 * 1 if date > compareDate
203 * -2 if an error occures
206 static int _DayLightCompareDate(
207 const LPSYSTEMTIME date, /* [in] The date to compare. */
208 const LPSYSTEMTIME compareDate) /* [in] The daylight saving begin or end date */
212 if (compareDate->wYear != 0)
214 if (date->wMonth < compareDate->wMonth)
215 return -1; /* We are in a year before the date limit. */
217 if (date->wMonth > compareDate->wMonth)
218 return 1; /* We are in a year after the date limit. */
221 if (date->wMonth < compareDate->wMonth)
222 return -1; /* We are in a month before the date limit. */
224 if (date->wMonth > compareDate->wMonth)
225 return 1; /* We are in a month after the date limit. */
227 if (compareDate->wDayOfWeek <= 6)
232 /* compareDate->wDay is interpreted as number of the week in the month. */
233 /* 5 means: the last week in the month */
234 int weekofmonth = compareDate->wDay;
236 /* calculate day of week for the first day in the month */
237 memcpy(&tmp, date, sizeof(SYSTEMTIME));
241 if (weekofmonth == 5)
243 /* Go to the beginning of the next month. */
244 if (++tmp.wMonth > 12)
251 if (!SystemTimeToFileTime(&tmp, &tmp_ft))
254 if (weekofmonth == 5)
258 t = tmp_ft.dwHighDateTime;
260 t += (UINT)tmp_ft.dwLowDateTime;
262 /* subtract one day */
267 tmp_ft.dwLowDateTime = (UINT)t;
268 tmp_ft.dwHighDateTime = (UINT)(t >> 32);
271 if (!FileTimeToSystemTime(&tmp_ft, &tmp))
274 if (weekofmonth == 5)
276 /* calculate the last matching day of the week in this month */
277 int dif = tmp.wDayOfWeek - compareDate->wDayOfWeek;
281 limit_day = tmp.wDay - dif;
285 /* calculate the matching day of the week in the given week */
286 int dif = compareDate->wDayOfWeek - tmp.wDayOfWeek;
290 limit_day = tmp.wDay + 7*(weekofmonth-1) + dif;
295 limit_day = compareDate->wDay;
298 if (date->wDay < limit_day)
301 if (date->wDay > limit_day)
304 return 0; /* date is equal to the date limit. */
308 /***********************************************************************
311 * Calculates the local time bias for a given time zone
315 * Returns TRUE when the time zone bias was calculated.
318 static BOOL _GetTimezoneBias(
319 const LPTIME_ZONE_INFORMATION lpTimeZoneInformation, /* [in] The time zone data. */
320 LPSYSTEMTIME lpSystemTime, /* [in] The system time. */
321 LONG* pBias) /* [out] The calulated bias in minutes */
324 BOOL beforeStandardDate, afterDaylightDate;
325 BOOL daylightsaving = FALSE;
326 LONG bias = lpTimeZoneInformation->Bias;
328 if (lpTimeZoneInformation->DaylightDate.wMonth != 0)
330 if (lpTimeZoneInformation->StandardDate.wMonth == 0 ||
331 lpTimeZoneInformation->StandardDate.wDay<1 ||
332 lpTimeZoneInformation->StandardDate.wDay>5 ||
333 lpTimeZoneInformation->DaylightDate.wDay<1 ||
334 lpTimeZoneInformation->DaylightDate.wDay>5)
336 SetLastError(ERROR_INVALID_PARAMETER);
340 /* check for daylight saving */
341 ret = _DayLightCompareDate(lpSystemTime, &lpTimeZoneInformation->StandardDate);
345 beforeStandardDate = ret < 0;
347 ret = _DayLightCompareDate(lpSystemTime, &lpTimeZoneInformation->DaylightDate);
351 afterDaylightDate = ret >= 0;
353 if (beforeStandardDate && afterDaylightDate)
354 daylightsaving = TRUE;
358 bias += lpTimeZoneInformation->DaylightBias;
359 else if (lpTimeZoneInformation->StandardDate.wMonth != 0)
360 bias += lpTimeZoneInformation->StandardBias;
368 /***********************************************************************
369 * SystemTimeToTzSpecificLocalTime (KERNEL32.@)
371 * Convert a utc system time to a local time in a given time zone.
374 * Success: TRUE. lpLocalTime contains the converted time
378 BOOL WINAPI SystemTimeToTzSpecificLocalTime(
379 LPTIME_ZONE_INFORMATION lpTimeZoneInformation, /* [in] The desired time zone. */
380 LPSYSTEMTIME lpUniversalTime, /* [in] The utc time to base local time on. */
381 LPSYSTEMTIME lpLocalTime) /* [out] The local time in the time zone. */
386 TIME_ZONE_INFORMATION tzinfo;
388 if (lpTimeZoneInformation != NULL)
390 memcpy(&tzinfo, lpTimeZoneInformation, sizeof(TIME_ZONE_INFORMATION));
394 if (GetTimeZoneInformation(&tzinfo) == TIME_ZONE_ID_INVALID)
398 if (!SystemTimeToFileTime(lpUniversalTime, &ft))
401 t = ft.dwHighDateTime;
403 t += (UINT)ft.dwLowDateTime;
405 if (!_GetTimezoneBias(&tzinfo, lpUniversalTime, &lBias))
408 bias = (LONGLONG)lBias * 600000000; /* 60 seconds per minute, 100000 [100-nanoseconds-ticks] per second */
411 ft.dwLowDateTime = (UINT)t;
412 ft.dwHighDateTime = (UINT)(t >> 32);
414 return FileTimeToSystemTime(&ft, lpLocalTime);
418 /***********************************************************************
419 * TzSpecificLocalTimeToSystemTime (KERNEL32.@)
421 * Converts a local time to a time in utc.
424 * Success: TRUE. lpUniversalTime contains the converted time
427 BOOL WINAPI TzSpecificLocalTimeToSystemTime(
428 LPTIME_ZONE_INFORMATION lpTimeZoneInformation, /* [in] The desired time zone. */
429 LPSYSTEMTIME lpLocalTime, /* [in] The local time. */
430 LPSYSTEMTIME lpUniversalTime) /* [out] The calculated utc time. */
435 TIME_ZONE_INFORMATION tzinfo;
437 if (lpTimeZoneInformation != NULL)
439 memcpy(&tzinfo, lpTimeZoneInformation, sizeof(TIME_ZONE_INFORMATION));
443 if (GetTimeZoneInformation(&tzinfo) == TIME_ZONE_ID_INVALID)
447 if (!SystemTimeToFileTime(lpLocalTime, &ft))
450 t = ft.dwHighDateTime;
452 t += (UINT)ft.dwLowDateTime;
454 if (!_GetTimezoneBias(&tzinfo, lpLocalTime, &lBias))
457 bias = (LONGLONG)lBias * 600000000; /* 60 seconds per minute, 100000 [100-nanoseconds-ticks] per second */
460 ft.dwLowDateTime = (UINT)t;
461 ft.dwHighDateTime = (UINT)(t >> 32);
463 return FileTimeToSystemTime(&ft, lpUniversalTime);
467 /***********************************************************************
468 * GetSystemTimeAsFileTime (KERNEL32.@)
470 * Get the current time in utc format.
475 VOID WINAPI GetSystemTimeAsFileTime(
476 LPFILETIME time) /* [out] Destination for the current utc time */
479 NtQuerySystemTime( &t );
480 time->dwLowDateTime = t.u.LowPart;
481 time->dwHighDateTime = t.u.HighPart;
485 /*********************************************************************
486 * TIME_ClockTimeToFileTime (olorin@fandra.org, 20-Sep-1998)
488 * Used by GetProcessTimes to convert clock_t into FILETIME.
490 * Differences to UnixTimeToFileTime:
491 * 1) Divided by CLK_TCK
492 * 2) Time is relative. There is no 'starting date', so there is
493 * no need for offset correction, like in UnixTimeToFileTime
495 static void TIME_ClockTimeToFileTime(clock_t unix_time, LPFILETIME filetime)
497 ULONGLONG secs = RtlEnlargedUnsignedMultiply( unix_time, 10000000 );
498 secs = RtlExtendedLargeIntegerDivide( secs, CLK_TCK, NULL );
499 filetime->dwLowDateTime = (DWORD)secs;
500 filetime->dwHighDateTime = (DWORD)(secs >> 32);
503 /*********************************************************************
504 * GetProcessTimes (KERNEL32.@)
506 * Get the user and kernel execution times of a process,
507 * along with the creation and exit times if known.
514 * Would be nice to subtract the cpu time used by Wine at startup.
515 * Also, there is a need to separate times used by different applications.
518 * lpCreationTime and lpExitTime are not initialised in the Wine implementation.
520 BOOL WINAPI GetProcessTimes(
521 HANDLE hprocess, /* [in] The process to be queried (obtained from PROCESS_QUERY_INFORMATION). */
522 LPFILETIME lpCreationTime, /* [out] The creation time of the process. */
523 LPFILETIME lpExitTime, /* [out] The exit time of the process if exited. */
524 LPFILETIME lpKernelTime, /* [out] The time spent in kernal routines in 100's of nanoseconds. */
525 LPFILETIME lpUserTime) /* [out] The time spent in user routines in 100's of nanoseconds. */
530 TIME_ClockTimeToFileTime(tms.tms_utime,lpUserTime);
531 TIME_ClockTimeToFileTime(tms.tms_stime,lpKernelTime);
535 /*********************************************************************
536 * GetCalendarInfoA (KERNEL32.@)
539 int WINAPI GetCalendarInfoA(LCID lcid, CALID Calendar, CALTYPE CalType,
540 LPSTR lpCalData, int cchData, LPDWORD lpValue)
543 LPWSTR lpCalDataW = NULL;
545 FIXME("(%08lx,%08lx,%08lx,%p,%d,%p): quarter-stub\n",
546 lcid, Calendar, CalType, lpCalData, cchData, lpValue);
548 lcid = ConvertDefaultLocale(lcid);
550 if (NLS_IsUnicodeOnlyLcid(lcid))
552 SetLastError(ERROR_INVALID_PARAMETER);
557 !(lpCalDataW = HeapAlloc(GetProcessHeap(), 0, cchData*sizeof(WCHAR))))
560 ret = GetCalendarInfoW(lcid, Calendar, CalType, lpCalDataW, cchData, lpValue);
561 if(ret && lpCalDataW && lpCalData)
562 WideCharToMultiByte(CP_ACP, 0, lpCalDataW, cchData, lpCalData, cchData, NULL, NULL);
564 HeapFree(GetProcessHeap(), 0, lpCalDataW);
569 /*********************************************************************
570 * GetCalendarInfoW (KERNEL32.@)
572 * See GetCalendarInfoA.
574 int WINAPI GetCalendarInfoW(LCID Locale, CALID Calendar, CALTYPE CalType,
575 LPWSTR lpCalData, int cchData, LPDWORD lpValue)
577 FIXME("(%08lx,%08lx,%08lx,%p,%d,%p): quarter-stub\n",
578 Locale, Calendar, CalType, lpCalData, cchData, lpValue);
580 if (CalType & CAL_NOUSEROVERRIDE)
581 FIXME("flag CAL_NOUSEROVERRIDE used, not fully implemented\n");
582 if (CalType & CAL_USE_CP_ACP)
583 FIXME("flag CAL_USE_CP_ACP used, not fully implemented\n");
585 if (CalType & CAL_RETURN_NUMBER) {
586 if (lpCalData != NULL)
587 WARN("lpCalData not NULL (%p) when it should!\n", lpCalData);
589 WARN("cchData not 0 (%d) when it should!\n", cchData);
592 WARN("lpValue not NULL (%p) when it should!\n", lpValue);
595 /* FIXME: No verification is made yet wrt Locale
596 * for the CALTYPES not requiring GetLocaleInfoA */
597 switch (CalType & ~(CAL_NOUSEROVERRIDE|CAL_RETURN_NUMBER|CAL_USE_CP_ACP)) {
598 case CAL_ICALINTVALUE:
599 FIXME("Unimplemented caltype %ld\n", CalType & 0xffff);
602 FIXME("Unimplemented caltype %ld\n", CalType & 0xffff);
604 case CAL_IYEAROFFSETRANGE:
605 FIXME("Unimplemented caltype %ld\n", CalType & 0xffff);
608 FIXME("Unimplemented caltype %ld\n", CalType & 0xffff);
611 return GetLocaleInfoW(Locale, LOCALE_SSHORTDATE, lpCalData, cchData);
613 return GetLocaleInfoW(Locale, LOCALE_SLONGDATE, lpCalData, cchData);
615 return GetLocaleInfoW(Locale, LOCALE_SDAYNAME1, lpCalData, cchData);
617 return GetLocaleInfoW(Locale, LOCALE_SDAYNAME2, lpCalData, cchData);
619 return GetLocaleInfoW(Locale, LOCALE_SDAYNAME3, lpCalData, cchData);
621 return GetLocaleInfoW(Locale, LOCALE_SDAYNAME4, lpCalData, cchData);
623 return GetLocaleInfoW(Locale, LOCALE_SDAYNAME5, lpCalData, cchData);
625 return GetLocaleInfoW(Locale, LOCALE_SDAYNAME6, lpCalData, cchData);
627 return GetLocaleInfoW(Locale, LOCALE_SDAYNAME7, lpCalData, cchData);
628 case CAL_SABBREVDAYNAME1:
629 return GetLocaleInfoW(Locale, LOCALE_SABBREVDAYNAME1, lpCalData, cchData);
630 case CAL_SABBREVDAYNAME2:
631 return GetLocaleInfoW(Locale, LOCALE_SABBREVDAYNAME2, lpCalData, cchData);
632 case CAL_SABBREVDAYNAME3:
633 return GetLocaleInfoW(Locale, LOCALE_SABBREVDAYNAME3, lpCalData, cchData);
634 case CAL_SABBREVDAYNAME4:
635 return GetLocaleInfoW(Locale, LOCALE_SABBREVDAYNAME4, lpCalData, cchData);
636 case CAL_SABBREVDAYNAME5:
637 return GetLocaleInfoW(Locale, LOCALE_SABBREVDAYNAME5, lpCalData, cchData);
638 case CAL_SABBREVDAYNAME6:
639 return GetLocaleInfoW(Locale, LOCALE_SABBREVDAYNAME6, lpCalData, cchData);
640 case CAL_SABBREVDAYNAME7:
641 return GetLocaleInfoW(Locale, LOCALE_SABBREVDAYNAME7, lpCalData, cchData);
642 case CAL_SMONTHNAME1:
643 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME1, lpCalData, cchData);
644 case CAL_SMONTHNAME2:
645 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME2, lpCalData, cchData);
646 case CAL_SMONTHNAME3:
647 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME3, lpCalData, cchData);
648 case CAL_SMONTHNAME4:
649 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME4, lpCalData, cchData);
650 case CAL_SMONTHNAME5:
651 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME5, lpCalData, cchData);
652 case CAL_SMONTHNAME6:
653 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME6, lpCalData, cchData);
654 case CAL_SMONTHNAME7:
655 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME7, lpCalData, cchData);
656 case CAL_SMONTHNAME8:
657 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME8, lpCalData, cchData);
658 case CAL_SMONTHNAME9:
659 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME9, lpCalData, cchData);
660 case CAL_SMONTHNAME10:
661 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME10, lpCalData, cchData);
662 case CAL_SMONTHNAME11:
663 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME11, lpCalData, cchData);
664 case CAL_SMONTHNAME12:
665 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME12, lpCalData, cchData);
666 case CAL_SMONTHNAME13:
667 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME13, lpCalData, cchData);
668 case CAL_SABBREVMONTHNAME1:
669 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME1, lpCalData, cchData);
670 case CAL_SABBREVMONTHNAME2:
671 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME2, lpCalData, cchData);
672 case CAL_SABBREVMONTHNAME3:
673 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME3, lpCalData, cchData);
674 case CAL_SABBREVMONTHNAME4:
675 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME4, lpCalData, cchData);
676 case CAL_SABBREVMONTHNAME5:
677 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME5, lpCalData, cchData);
678 case CAL_SABBREVMONTHNAME6:
679 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME6, lpCalData, cchData);
680 case CAL_SABBREVMONTHNAME7:
681 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME7, lpCalData, cchData);
682 case CAL_SABBREVMONTHNAME8:
683 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME8, lpCalData, cchData);
684 case CAL_SABBREVMONTHNAME9:
685 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME9, lpCalData, cchData);
686 case CAL_SABBREVMONTHNAME10:
687 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME10, lpCalData, cchData);
688 case CAL_SABBREVMONTHNAME11:
689 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME11, lpCalData, cchData);
690 case CAL_SABBREVMONTHNAME12:
691 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME12, lpCalData, cchData);
692 case CAL_SABBREVMONTHNAME13:
693 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME13, lpCalData, cchData);
695 return GetLocaleInfoW(Locale, LOCALE_SYEARMONTH, lpCalData, cchData);
696 case CAL_ITWODIGITYEARMAX:
697 if (lpValue) *lpValue = CALINFO_MAX_YEAR;
699 default: MESSAGE("Unknown caltype %ld\n",CalType & 0xffff);
705 /*********************************************************************
706 * SetCalendarInfoA (KERNEL32.@)
709 int WINAPI SetCalendarInfoA(LCID Locale, CALID Calendar, CALTYPE CalType, LPCSTR lpCalData)
711 FIXME("(%08lx,%08lx,%08lx,%s): stub\n",
712 Locale, Calendar, CalType, debugstr_a(lpCalData));
716 /*********************************************************************
717 * SetCalendarInfoW (KERNEL32.@)
719 * See SetCalendarInfoA.
721 int WINAPI SetCalendarInfoW(LCID Locale, CALID Calendar, CALTYPE CalType, LPCWSTR lpCalData)
723 FIXME("(%08lx,%08lx,%08lx,%s): stub\n",
724 Locale, Calendar, CalType, debugstr_w(lpCalData));
728 /*********************************************************************
729 * LocalFileTimeToFileTime (KERNEL32.@)
731 BOOL WINAPI LocalFileTimeToFileTime( const FILETIME *localft, LPFILETIME utcft )
734 LARGE_INTEGER local, utc;
736 local.u.LowPart = localft->dwLowDateTime;
737 local.u.HighPart = localft->dwHighDateTime;
738 if (!(status = RtlLocalTimeToSystemTime( &local, &utc )))
740 utcft->dwLowDateTime = utc.u.LowPart;
741 utcft->dwHighDateTime = utc.u.HighPart;
743 else SetLastError( RtlNtStatusToDosError(status) );
748 /*********************************************************************
749 * FileTimeToLocalFileTime (KERNEL32.@)
751 BOOL WINAPI FileTimeToLocalFileTime( const FILETIME *utcft, LPFILETIME localft )
754 LARGE_INTEGER local, utc;
756 utc.u.LowPart = utcft->dwLowDateTime;
757 utc.u.HighPart = utcft->dwHighDateTime;
758 if (!(status = RtlSystemTimeToLocalTime( &utc, &local )))
760 localft->dwLowDateTime = local.u.LowPart;
761 localft->dwHighDateTime = local.u.HighPart;
763 else SetLastError( RtlNtStatusToDosError(status) );
768 /*********************************************************************
769 * FileTimeToSystemTime (KERNEL32.@)
771 BOOL WINAPI FileTimeToSystemTime( const FILETIME *ft, LPSYSTEMTIME syst )
776 t.u.LowPart = ft->dwLowDateTime;
777 t.u.HighPart = ft->dwHighDateTime;
778 RtlTimeToTimeFields(&t, &tf);
780 syst->wYear = tf.Year;
781 syst->wMonth = tf.Month;
783 syst->wHour = tf.Hour;
784 syst->wMinute = tf.Minute;
785 syst->wSecond = tf.Second;
786 syst->wMilliseconds = tf.Milliseconds;
787 syst->wDayOfWeek = tf.Weekday;
791 /*********************************************************************
792 * SystemTimeToFileTime (KERNEL32.@)
794 BOOL WINAPI SystemTimeToFileTime( const SYSTEMTIME *syst, LPFILETIME ft )
799 tf.Year = syst->wYear;
800 tf.Month = syst->wMonth;
802 tf.Hour = syst->wHour;
803 tf.Minute = syst->wMinute;
804 tf.Second = syst->wSecond;
805 tf.Milliseconds = syst->wMilliseconds;
807 RtlTimeFieldsToTime(&tf, &t);
808 ft->dwLowDateTime = t.u.LowPart;
809 ft->dwHighDateTime = t.u.HighPart;
813 /*********************************************************************
814 * CompareFileTime (KERNEL32.@)
816 * Compare two FILETIME's to each other.
820 * y [I] time to compare to x
823 * -1, 0, or 1 indicating that x is less than, equal to, or greater
824 * than y respectively.
826 INT WINAPI CompareFileTime( const FILETIME *x, const FILETIME *y )
828 if (!x || !y) return -1;
830 if (x->dwHighDateTime > y->dwHighDateTime)
832 if (x->dwHighDateTime < y->dwHighDateTime)
834 if (x->dwLowDateTime > y->dwLowDateTime)
836 if (x->dwLowDateTime < y->dwLowDateTime)
841 /*********************************************************************
842 * GetLocalTime (KERNEL32.@)
844 * Get the current local time.
849 VOID WINAPI GetLocalTime(LPSYSTEMTIME systime) /* [O] Destination for current time */
852 LARGE_INTEGER ft, ft2;
854 NtQuerySystemTime(&ft);
855 RtlSystemTimeToLocalTime(&ft, &ft2);
856 lft.dwLowDateTime = ft2.u.LowPart;
857 lft.dwHighDateTime = ft2.u.HighPart;
858 FileTimeToSystemTime(&lft, systime);
861 /*********************************************************************
862 * GetSystemTime (KERNEL32.@)
864 * Get the current system time.
869 VOID WINAPI GetSystemTime(LPSYSTEMTIME systime) /* [O] Destination for current time */
874 NtQuerySystemTime(&t);
875 ft.dwLowDateTime = t.u.LowPart;
876 ft.dwHighDateTime = t.u.HighPart;
877 FileTimeToSystemTime(&ft, systime);
880 /*********************************************************************
881 * GetDaylightFlag (KERNEL32.@)
883 * returns TRUE if daylight saving time is in operation
885 * Note: this function is called from the Win98's control applet
888 BOOL WINAPI GetDaylightFlag(void)
890 time_t t = time(NULL);
891 struct tm *ptm = localtime( &t);
892 return ptm->tm_isdst > 0;