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>
36 #ifdef HAVE_MACHINE_LIMITS_H
37 #include <machine/limits.h>
40 #define NONAMELESSUNION
41 #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
56 #define LL2FILETIME( ll, pft )\
57 (pft)->dwLowDateTime = (UINT)(ll); \
58 (pft)->dwHighDateTime = (UINT)((ll) >> 32);
59 #define FILETIME2LL( pft, ll) \
60 ll = (((LONGLONG)((pft)->dwHighDateTime))<<32) + (pft)-> dwLowDateTime ;
63 static const int MonthLengths[2][12] =
65 { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 },
66 { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }
69 static inline int IsLeapYear(int Year)
71 return Year % 4 == 0 && (Year % 100 != 0 || Year % 400 == 0) ? 1 : 0;
74 /***********************************************************************
75 * TIME_DayLightCompareDate
77 * Compares two dates without looking at the year
81 * -1 if date < compareDate
82 * 0 if date == compareDate
83 * 1 if date > compareDate
84 * -2 if an error occurs
86 static int TIME_DayLightCompareDate(
87 const SYSTEMTIME *date, /* [in] The local time to compare. */
88 const SYSTEMTIME *compareDate) /* [in] The daylight saving begin
91 int limit_day, dayinsecs;
93 if (date->wMonth < compareDate->wMonth)
94 return -1; /* We are in a month before the date limit. */
96 if (date->wMonth > compareDate->wMonth)
97 return 1; /* We are in a month after the date limit. */
99 if (compareDate->wDayOfWeek <= 6)
102 /* compareDate->wDay is interpreted as number of the week in the month
103 * 5 means: the last week in the month */
104 int weekofmonth = compareDate->wDay;
105 /* calculate the day of the first DayOfWeek in the month */
106 First = ( 6 + compareDate->wDayOfWeek - date->wDayOfWeek + date->wDay
108 limit_day = First + 7 * (weekofmonth - 1);
109 /* check needed for the 5th weekday of the month */
110 if(limit_day > MonthLengths[date->wMonth==2 && IsLeapYear(date->wYear)]
116 limit_day = compareDate->wDay;
119 /* convert to seconds */
120 limit_day = ((limit_day * 24 + compareDate->wHour) * 60 +
121 compareDate->wMinute ) * 60;
122 dayinsecs = ((date->wDay * 24 + date->wHour) * 60 +
123 date->wMinute ) * 60 + date->wSecond;
125 return dayinsecs < limit_day ? -1 :
126 dayinsecs > limit_day ? 1 :
127 0; /* date is equal to the date limit. */
130 /***********************************************************************
131 * TIME_CompTimeZoneID
133 * Computes the local time bias for a given time and time zone
136 * TIME_ZONE_ID_INVALID An error occurred
137 * TIME_ZONE_ID_UNKNOWN There are no transition time known
138 * TIME_ZONE_ID_STANDARD Current time is standard time
139 * TIME_ZONE_ID_DAYLIGHT Current time is dayligh saving time
141 static BOOL TIME_CompTimeZoneID (
142 const TIME_ZONE_INFORMATION *pTZinfo, /* [in] The time zone data. */
143 FILETIME *lpFileTime, /* [in] The system or local time. */
144 BOOL islocal /* [in] it is local time */
148 BOOL beforeStandardDate, afterDaylightDate;
149 DWORD retval = TIME_ZONE_ID_INVALID;
150 LONGLONG llTime = 0; /* initialized to prevent gcc complaining */
154 if (pTZinfo->DaylightDate.wMonth != 0)
156 if (pTZinfo->StandardDate.wMonth == 0 ||
157 pTZinfo->StandardDate.wDay<1 ||
158 pTZinfo->StandardDate.wDay>5 ||
159 pTZinfo->DaylightDate.wDay<1 ||
160 pTZinfo->DaylightDate.wDay>5)
162 SetLastError(ERROR_INVALID_PARAMETER);
163 return TIME_ZONE_ID_INVALID;
167 FILETIME2LL( lpFileTime, llTime );
168 llTime -= ( pTZinfo->Bias + pTZinfo->DaylightBias )
169 * (LONGLONG)600000000;
170 LL2FILETIME( llTime, &ftTemp)
171 lpFileTime = &ftTemp;
174 FileTimeToSystemTime(lpFileTime, &SysTime);
176 /* check for daylight saving */
177 ret = TIME_DayLightCompareDate( &SysTime, &pTZinfo->StandardDate);
179 return TIME_ZONE_ID_INVALID;
181 beforeStandardDate = ret < 0;
184 llTime -= ( pTZinfo->StandardBias - pTZinfo->DaylightBias )
185 * (LONGLONG)600000000;
186 LL2FILETIME( llTime, &ftTemp)
187 FileTimeToSystemTime(lpFileTime, &SysTime);
190 ret = TIME_DayLightCompareDate( &SysTime, &pTZinfo->DaylightDate);
192 return TIME_ZONE_ID_INVALID;
194 afterDaylightDate = ret >= 0;
196 retval = TIME_ZONE_ID_STANDARD;
197 if( pTZinfo->DaylightDate.wMonth < pTZinfo->StandardDate.wMonth ) {
198 /* Northern hemisphere */
199 if( beforeStandardDate && afterDaylightDate )
200 retval = TIME_ZONE_ID_DAYLIGHT;
201 } else /* Down south */
202 if( beforeStandardDate || afterDaylightDate )
203 retval = TIME_ZONE_ID_DAYLIGHT;
205 /* No transition date */
206 retval = TIME_ZONE_ID_UNKNOWN;
211 /***********************************************************************
214 * Calculates whether daylight saving is on now.
217 * TIME_ZONE_ID_INVALID An error occurred
218 * TIME_ZONE_ID_UNKNOWN There are no transition time known
219 * TIME_ZONE_ID_STANDARD Current time is standard time
220 * TIME_ZONE_ID_DAYLIGHT Current time is dayligh saving time
222 static DWORD TIME_ZoneID(
223 const TIME_ZONE_INFORMATION *pTzi /* Timezone info */
227 GetSystemTimeAsFileTime( &ftTime);
228 return TIME_CompTimeZoneID( pTzi, &ftTime, FALSE);
231 /***********************************************************************
232 * TIME_GetTimezoneBias
234 * Calculates the local time bias for a given time zone
238 * Returns TRUE when the time zone bias was calculated.
240 static BOOL TIME_GetTimezoneBias(
241 const TIME_ZONE_INFORMATION
242 *pTZinfo, /* [in] The time zone data. */
243 FILETIME *lpFileTime, /* [in] The system or local time. */
244 BOOL islocal, /* [in] it is local time */
245 LONG *pBias /* [out] The calculated bias in minutes */
248 LONG bias = pTZinfo->Bias;
249 DWORD tzid = TIME_CompTimeZoneID( pTZinfo, lpFileTime, islocal);
251 if( tzid == TIME_ZONE_ID_INVALID)
253 if (tzid == TIME_ZONE_ID_DAYLIGHT)
254 bias += pTZinfo->DaylightBias;
255 else if (tzid == TIME_ZONE_ID_STANDARD)
256 bias += pTZinfo->StandardBias;
262 /***********************************************************************
263 * SetLocalTime (KERNEL32.@)
265 * Set the local time using current time zone and daylight
269 * Success: TRUE. The time was set
270 * Failure: FALSE, if the time was invalid or caller does not have
271 * permission to change the time.
273 BOOL WINAPI SetLocalTime(
274 const SYSTEMTIME *systime) /* [in] The desired local time. */
277 LARGE_INTEGER st, st2;
280 if( !SystemTimeToFileTime( systime, &ft ))
282 st.u.LowPart = ft.dwLowDateTime;
283 st.u.HighPart = ft.dwHighDateTime;
284 RtlLocalTimeToSystemTime( &st, &st2 );
286 if ((status = NtSetSystemTime(&st2, NULL)))
287 SetLastError( RtlNtStatusToDosError(status) );
292 /***********************************************************************
293 * GetSystemTimeAdjustment (KERNEL32.@)
295 * Get the period between clock interrupts and the amount the clock
296 * is adjusted each interrupt so as to keep it in sync with an external source.
302 * Only the special case of disabled time adjustments is supported.
304 BOOL WINAPI GetSystemTimeAdjustment(
305 PDWORD lpTimeAdjustment, /* [out] The clock adjustment per interrupt in 100's of nanoseconds. */
306 PDWORD lpTimeIncrement, /* [out] The time between clock interrupts in 100's of nanoseconds. */
307 PBOOL lpTimeAdjustmentDisabled) /* [out] The clock synchronisation has been disabled. */
309 *lpTimeAdjustment = 0;
310 *lpTimeIncrement = 0;
311 *lpTimeAdjustmentDisabled = TRUE;
316 /***********************************************************************
317 * SetSystemTime (KERNEL32.@)
319 * Set the system time in utc.
322 * Success: TRUE. The time was set
323 * Failure: FALSE, if the time was invalid or caller does not have
324 * permission to change the time.
326 BOOL WINAPI SetSystemTime(
327 const SYSTEMTIME *systime) /* [in] The desired system time. */
333 if( !SystemTimeToFileTime( systime, &ft ))
335 t.u.LowPart = ft.dwLowDateTime;
336 t.u.HighPart = ft.dwHighDateTime;
337 if ((status = NtSetSystemTime(&t, NULL)))
338 SetLastError( RtlNtStatusToDosError(status) );
342 /***********************************************************************
343 * SetSystemTimeAdjustment (KERNEL32.@)
345 * Enables or disables the timing adjustments to the system's clock.
351 BOOL WINAPI SetSystemTimeAdjustment(
352 DWORD dwTimeAdjustment,
353 BOOL bTimeAdjustmentDisabled)
355 /* Fake function for now... */
356 FIXME("(%08lx,%d): stub !\n", dwTimeAdjustment, bTimeAdjustmentDisabled);
360 /***********************************************************************
361 * GetTimeZoneInformation (KERNEL32.@)
363 * Get information about the current local time zone.
366 * TIME_ZONE_ID_INVALID An error occurred
367 * TIME_ZONE_ID_UNKNOWN There are no transition time known
368 * TIME_ZONE_ID_STANDARD Current time is standard time
369 * TIME_ZONE_ID_DAYLIGHT Current time is dayligh saving time
371 DWORD WINAPI GetTimeZoneInformation(
372 LPTIME_ZONE_INFORMATION tzinfo) /* [out] Destination for time zone information */
375 if ((status = RtlQueryTimeZoneInformation(tzinfo))) {
376 SetLastError( RtlNtStatusToDosError(status) );
377 return TIME_ZONE_ID_INVALID;
379 return TIME_ZoneID( tzinfo );
382 /***********************************************************************
383 * SetTimeZoneInformation (KERNEL32.@)
385 * Change the settings of the current local time zone.
388 * Success: TRUE. The time zone was updated with the settings from tzinfo
391 BOOL WINAPI SetTimeZoneInformation(
392 const TIME_ZONE_INFORMATION *tzinfo) /* [in] The new time zone. */
395 if ((status = RtlSetTimeZoneInformation(tzinfo)))
396 SetLastError( RtlNtStatusToDosError(status) );
400 /***********************************************************************
401 * SystemTimeToTzSpecificLocalTime (KERNEL32.@)
403 * Convert a utc system time to a local time in a given time zone.
406 * Success: TRUE. lpLocalTime contains the converted time
410 BOOL WINAPI SystemTimeToTzSpecificLocalTime(
411 LPTIME_ZONE_INFORMATION
412 lpTimeZoneInformation, /* [in] The desired time zone. */
413 LPSYSTEMTIME lpUniversalTime, /* [in] The utc time to base local time on. */
414 LPSYSTEMTIME lpLocalTime) /* [out] The local time in the time zone. */
419 TIME_ZONE_INFORMATION tzinfo;
421 if (lpTimeZoneInformation != NULL)
423 memcpy(&tzinfo, lpTimeZoneInformation, sizeof(TIME_ZONE_INFORMATION));
427 if (GetTimeZoneInformation(&tzinfo) == TIME_ZONE_ID_INVALID)
431 if (!SystemTimeToFileTime(lpUniversalTime, &ft))
433 FILETIME2LL( &ft, llTime)
434 if (!TIME_GetTimezoneBias(&tzinfo, &ft, FALSE, &lBias))
436 /* convert minutes to 100-nanoseconds-ticks */
437 llTime -= (LONGLONG)lBias * 600000000;
438 LL2FILETIME( llTime, &ft)
440 return FileTimeToSystemTime(&ft, lpLocalTime);
444 /***********************************************************************
445 * TzSpecificLocalTimeToSystemTime (KERNEL32.@)
447 * Converts a local time to a time in utc.
450 * Success: TRUE. lpUniversalTime contains the converted time
453 BOOL WINAPI TzSpecificLocalTimeToSystemTime(
454 LPTIME_ZONE_INFORMATION lpTimeZoneInformation, /* [in] The desired time zone. */
455 LPSYSTEMTIME lpLocalTime, /* [in] The local time. */
456 LPSYSTEMTIME lpUniversalTime) /* [out] The calculated utc time. */
461 TIME_ZONE_INFORMATION tzinfo;
463 if (lpTimeZoneInformation != NULL)
465 memcpy(&tzinfo, lpTimeZoneInformation, sizeof(TIME_ZONE_INFORMATION));
469 if (GetTimeZoneInformation(&tzinfo) == TIME_ZONE_ID_INVALID)
473 if (!SystemTimeToFileTime(lpLocalTime, &ft))
476 if (!TIME_GetTimezoneBias(&tzinfo, &ft, TRUE, &lBias))
478 /* convert minutes to 100-nanoseconds-ticks */
479 t += (LONGLONG)lBias * 600000000;
481 return FileTimeToSystemTime(&ft, lpUniversalTime);
485 /***********************************************************************
486 * GetSystemTimeAsFileTime (KERNEL32.@)
488 * Get the current time in utc format.
493 VOID WINAPI GetSystemTimeAsFileTime(
494 LPFILETIME time) /* [out] Destination for the current utc time */
497 NtQuerySystemTime( &t );
498 time->dwLowDateTime = t.u.LowPart;
499 time->dwHighDateTime = t.u.HighPart;
503 /*********************************************************************
504 * TIME_ClockTimeToFileTime (olorin@fandra.org, 20-Sep-1998)
506 * Used by GetProcessTimes to convert clock_t into FILETIME.
508 * Differences to UnixTimeToFileTime:
509 * 1) Divided by CLK_TCK
510 * 2) Time is relative. There is no 'starting date', so there is
511 * no need for offset correction, like in UnixTimeToFileTime
513 static void TIME_ClockTimeToFileTime(clock_t unix_time, LPFILETIME filetime)
515 ULONGLONG secs = RtlEnlargedUnsignedMultiply( unix_time, 10000000 );
516 secs = RtlExtendedLargeIntegerDivide( secs, CLK_TCK, NULL );
517 filetime->dwLowDateTime = (DWORD)secs;
518 filetime->dwHighDateTime = (DWORD)(secs >> 32);
521 /*********************************************************************
522 * GetProcessTimes (KERNEL32.@)
524 * Get the user and kernel execution times of a process,
525 * along with the creation and exit times if known.
532 * Would be nice to subtract the cpu time used by Wine at startup.
533 * Also, there is a need to separate times used by different applications.
536 * lpCreationTime and lpExitTime are not initialised in the Wine implementation.
538 BOOL WINAPI GetProcessTimes(
539 HANDLE hprocess, /* [in] The process to be queried (obtained from PROCESS_QUERY_INFORMATION). */
540 LPFILETIME lpCreationTime, /* [out] The creation time of the process. */
541 LPFILETIME lpExitTime, /* [out] The exit time of the process if exited. */
542 LPFILETIME lpKernelTime, /* [out] The time spent in kernel routines in 100's of nanoseconds. */
543 LPFILETIME lpUserTime) /* [out] The time spent in user routines in 100's of nanoseconds. */
548 TIME_ClockTimeToFileTime(tms.tms_utime,lpUserTime);
549 TIME_ClockTimeToFileTime(tms.tms_stime,lpKernelTime);
553 /*********************************************************************
554 * GetCalendarInfoA (KERNEL32.@)
557 int WINAPI GetCalendarInfoA(LCID lcid, CALID Calendar, CALTYPE CalType,
558 LPSTR lpCalData, int cchData, LPDWORD lpValue)
561 LPWSTR lpCalDataW = NULL;
563 FIXME("(%08lx,%08lx,%08lx,%p,%d,%p): quarter-stub\n",
564 lcid, Calendar, CalType, lpCalData, cchData, lpValue);
566 lcid = ConvertDefaultLocale(lcid);
568 if (NLS_IsUnicodeOnlyLcid(lcid))
570 SetLastError(ERROR_INVALID_PARAMETER);
575 !(lpCalDataW = HeapAlloc(GetProcessHeap(), 0, cchData*sizeof(WCHAR))))
578 ret = GetCalendarInfoW(lcid, Calendar, CalType, lpCalDataW, cchData, lpValue);
579 if(ret && lpCalDataW && lpCalData)
580 WideCharToMultiByte(CP_ACP, 0, lpCalDataW, cchData, lpCalData, cchData, NULL, NULL);
581 HeapFree(GetProcessHeap(), 0, lpCalDataW);
586 /*********************************************************************
587 * GetCalendarInfoW (KERNEL32.@)
589 * See GetCalendarInfoA.
591 int WINAPI GetCalendarInfoW(LCID Locale, CALID Calendar, CALTYPE CalType,
592 LPWSTR lpCalData, int cchData, LPDWORD lpValue)
594 FIXME("(%08lx,%08lx,%08lx,%p,%d,%p): quarter-stub\n",
595 Locale, Calendar, CalType, lpCalData, cchData, lpValue);
597 if (CalType & CAL_NOUSEROVERRIDE)
598 FIXME("flag CAL_NOUSEROVERRIDE used, not fully implemented\n");
599 if (CalType & CAL_USE_CP_ACP)
600 FIXME("flag CAL_USE_CP_ACP used, not fully implemented\n");
602 if (CalType & CAL_RETURN_NUMBER) {
603 if (lpCalData != NULL)
604 WARN("lpCalData not NULL (%p) when it should!\n", lpCalData);
606 WARN("cchData not 0 (%d) when it should!\n", cchData);
609 WARN("lpValue not NULL (%p) when it should!\n", lpValue);
612 /* FIXME: No verification is made yet wrt Locale
613 * for the CALTYPES not requiring GetLocaleInfoA */
614 switch (CalType & ~(CAL_NOUSEROVERRIDE|CAL_RETURN_NUMBER|CAL_USE_CP_ACP)) {
615 case CAL_ICALINTVALUE:
616 FIXME("Unimplemented caltype %ld\n", CalType & 0xffff);
619 FIXME("Unimplemented caltype %ld\n", CalType & 0xffff);
621 case CAL_IYEAROFFSETRANGE:
622 FIXME("Unimplemented caltype %ld\n", CalType & 0xffff);
625 FIXME("Unimplemented caltype %ld\n", CalType & 0xffff);
628 return GetLocaleInfoW(Locale, LOCALE_SSHORTDATE, lpCalData, cchData);
630 return GetLocaleInfoW(Locale, LOCALE_SLONGDATE, lpCalData, cchData);
632 return GetLocaleInfoW(Locale, LOCALE_SDAYNAME1, lpCalData, cchData);
634 return GetLocaleInfoW(Locale, LOCALE_SDAYNAME2, lpCalData, cchData);
636 return GetLocaleInfoW(Locale, LOCALE_SDAYNAME3, lpCalData, cchData);
638 return GetLocaleInfoW(Locale, LOCALE_SDAYNAME4, lpCalData, cchData);
640 return GetLocaleInfoW(Locale, LOCALE_SDAYNAME5, lpCalData, cchData);
642 return GetLocaleInfoW(Locale, LOCALE_SDAYNAME6, lpCalData, cchData);
644 return GetLocaleInfoW(Locale, LOCALE_SDAYNAME7, lpCalData, cchData);
645 case CAL_SABBREVDAYNAME1:
646 return GetLocaleInfoW(Locale, LOCALE_SABBREVDAYNAME1, lpCalData, cchData);
647 case CAL_SABBREVDAYNAME2:
648 return GetLocaleInfoW(Locale, LOCALE_SABBREVDAYNAME2, lpCalData, cchData);
649 case CAL_SABBREVDAYNAME3:
650 return GetLocaleInfoW(Locale, LOCALE_SABBREVDAYNAME3, lpCalData, cchData);
651 case CAL_SABBREVDAYNAME4:
652 return GetLocaleInfoW(Locale, LOCALE_SABBREVDAYNAME4, lpCalData, cchData);
653 case CAL_SABBREVDAYNAME5:
654 return GetLocaleInfoW(Locale, LOCALE_SABBREVDAYNAME5, lpCalData, cchData);
655 case CAL_SABBREVDAYNAME6:
656 return GetLocaleInfoW(Locale, LOCALE_SABBREVDAYNAME6, lpCalData, cchData);
657 case CAL_SABBREVDAYNAME7:
658 return GetLocaleInfoW(Locale, LOCALE_SABBREVDAYNAME7, lpCalData, cchData);
659 case CAL_SMONTHNAME1:
660 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME1, lpCalData, cchData);
661 case CAL_SMONTHNAME2:
662 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME2, lpCalData, cchData);
663 case CAL_SMONTHNAME3:
664 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME3, lpCalData, cchData);
665 case CAL_SMONTHNAME4:
666 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME4, lpCalData, cchData);
667 case CAL_SMONTHNAME5:
668 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME5, lpCalData, cchData);
669 case CAL_SMONTHNAME6:
670 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME6, lpCalData, cchData);
671 case CAL_SMONTHNAME7:
672 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME7, lpCalData, cchData);
673 case CAL_SMONTHNAME8:
674 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME8, lpCalData, cchData);
675 case CAL_SMONTHNAME9:
676 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME9, lpCalData, cchData);
677 case CAL_SMONTHNAME10:
678 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME10, lpCalData, cchData);
679 case CAL_SMONTHNAME11:
680 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME11, lpCalData, cchData);
681 case CAL_SMONTHNAME12:
682 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME12, lpCalData, cchData);
683 case CAL_SMONTHNAME13:
684 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME13, lpCalData, cchData);
685 case CAL_SABBREVMONTHNAME1:
686 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME1, lpCalData, cchData);
687 case CAL_SABBREVMONTHNAME2:
688 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME2, lpCalData, cchData);
689 case CAL_SABBREVMONTHNAME3:
690 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME3, lpCalData, cchData);
691 case CAL_SABBREVMONTHNAME4:
692 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME4, lpCalData, cchData);
693 case CAL_SABBREVMONTHNAME5:
694 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME5, lpCalData, cchData);
695 case CAL_SABBREVMONTHNAME6:
696 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME6, lpCalData, cchData);
697 case CAL_SABBREVMONTHNAME7:
698 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME7, lpCalData, cchData);
699 case CAL_SABBREVMONTHNAME8:
700 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME8, lpCalData, cchData);
701 case CAL_SABBREVMONTHNAME9:
702 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME9, lpCalData, cchData);
703 case CAL_SABBREVMONTHNAME10:
704 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME10, lpCalData, cchData);
705 case CAL_SABBREVMONTHNAME11:
706 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME11, lpCalData, cchData);
707 case CAL_SABBREVMONTHNAME12:
708 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME12, lpCalData, cchData);
709 case CAL_SABBREVMONTHNAME13:
710 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME13, lpCalData, cchData);
712 return GetLocaleInfoW(Locale, LOCALE_SYEARMONTH, lpCalData, cchData);
713 case CAL_ITWODIGITYEARMAX:
714 if (lpValue) *lpValue = CALINFO_MAX_YEAR;
716 default: MESSAGE("Unknown caltype %ld\n",CalType & 0xffff);
722 /*********************************************************************
723 * SetCalendarInfoA (KERNEL32.@)
726 int WINAPI SetCalendarInfoA(LCID Locale, CALID Calendar, CALTYPE CalType, LPCSTR lpCalData)
728 FIXME("(%08lx,%08lx,%08lx,%s): stub\n",
729 Locale, Calendar, CalType, debugstr_a(lpCalData));
733 /*********************************************************************
734 * SetCalendarInfoW (KERNEL32.@)
736 * See SetCalendarInfoA.
738 int WINAPI SetCalendarInfoW(LCID Locale, CALID Calendar, CALTYPE CalType, LPCWSTR lpCalData)
740 FIXME("(%08lx,%08lx,%08lx,%s): stub\n",
741 Locale, Calendar, CalType, debugstr_w(lpCalData));
745 /*********************************************************************
746 * LocalFileTimeToFileTime (KERNEL32.@)
748 BOOL WINAPI LocalFileTimeToFileTime( const FILETIME *localft, LPFILETIME utcft )
751 LARGE_INTEGER local, utc;
753 local.u.LowPart = localft->dwLowDateTime;
754 local.u.HighPart = localft->dwHighDateTime;
755 if (!(status = RtlLocalTimeToSystemTime( &local, &utc )))
757 utcft->dwLowDateTime = utc.u.LowPart;
758 utcft->dwHighDateTime = utc.u.HighPart;
760 else SetLastError( RtlNtStatusToDosError(status) );
765 /*********************************************************************
766 * FileTimeToLocalFileTime (KERNEL32.@)
768 BOOL WINAPI FileTimeToLocalFileTime( const FILETIME *utcft, LPFILETIME localft )
771 LARGE_INTEGER local, utc;
773 utc.u.LowPart = utcft->dwLowDateTime;
774 utc.u.HighPart = utcft->dwHighDateTime;
775 if (!(status = RtlSystemTimeToLocalTime( &utc, &local )))
777 localft->dwLowDateTime = local.u.LowPart;
778 localft->dwHighDateTime = local.u.HighPart;
780 else SetLastError( RtlNtStatusToDosError(status) );
785 /*********************************************************************
786 * FileTimeToSystemTime (KERNEL32.@)
788 BOOL WINAPI FileTimeToSystemTime( const FILETIME *ft, LPSYSTEMTIME syst )
793 t.u.LowPart = ft->dwLowDateTime;
794 t.u.HighPart = ft->dwHighDateTime;
795 RtlTimeToTimeFields(&t, &tf);
797 syst->wYear = tf.Year;
798 syst->wMonth = tf.Month;
800 syst->wHour = tf.Hour;
801 syst->wMinute = tf.Minute;
802 syst->wSecond = tf.Second;
803 syst->wMilliseconds = tf.Milliseconds;
804 syst->wDayOfWeek = tf.Weekday;
808 /*********************************************************************
809 * SystemTimeToFileTime (KERNEL32.@)
811 BOOL WINAPI SystemTimeToFileTime( const SYSTEMTIME *syst, LPFILETIME ft )
816 tf.Year = syst->wYear;
817 tf.Month = syst->wMonth;
819 tf.Hour = syst->wHour;
820 tf.Minute = syst->wMinute;
821 tf.Second = syst->wSecond;
822 tf.Milliseconds = syst->wMilliseconds;
824 if( !RtlTimeFieldsToTime(&tf, &t)) {
825 SetLastError( ERROR_INVALID_PARAMETER);
828 ft->dwLowDateTime = t.u.LowPart;
829 ft->dwHighDateTime = t.u.HighPart;
833 /*********************************************************************
834 * CompareFileTime (KERNEL32.@)
836 * Compare two FILETIME's to each other.
840 * y [I] time to compare to x
843 * -1, 0, or 1 indicating that x is less than, equal to, or greater
844 * than y respectively.
846 INT WINAPI CompareFileTime( const FILETIME *x, const FILETIME *y )
848 if (!x || !y) return -1;
850 if (x->dwHighDateTime > y->dwHighDateTime)
852 if (x->dwHighDateTime < y->dwHighDateTime)
854 if (x->dwLowDateTime > y->dwLowDateTime)
856 if (x->dwLowDateTime < y->dwLowDateTime)
861 /*********************************************************************
862 * GetLocalTime (KERNEL32.@)
864 * Get the current local time.
869 VOID WINAPI GetLocalTime(LPSYSTEMTIME systime) /* [O] Destination for current time */
872 LARGE_INTEGER ft, ft2;
874 NtQuerySystemTime(&ft);
875 RtlSystemTimeToLocalTime(&ft, &ft2);
876 lft.dwLowDateTime = ft2.u.LowPart;
877 lft.dwHighDateTime = ft2.u.HighPart;
878 FileTimeToSystemTime(&lft, systime);
881 /*********************************************************************
882 * GetSystemTime (KERNEL32.@)
884 * Get the current system time.
889 VOID WINAPI GetSystemTime(LPSYSTEMTIME systime) /* [O] Destination for current time */
894 NtQuerySystemTime(&t);
895 ft.dwLowDateTime = t.u.LowPart;
896 ft.dwHighDateTime = t.u.HighPart;
897 FileTimeToSystemTime(&ft, systime);
900 /*********************************************************************
901 * GetDaylightFlag (KERNEL32.@)
903 * returns TRUE if daylight saving time is in operation
905 * Note: this function is called from the Win98's control applet
908 BOOL WINAPI GetDaylightFlag(void)
910 TIME_ZONE_INFORMATION tzinfo;
911 return GetTimeZoneInformation( &tzinfo) == TIME_ZONE_ID_DAYLIGHT;
914 /***********************************************************************
915 * DosDateTimeToFileTime (KERNEL32.@)
917 BOOL WINAPI DosDateTimeToFileTime( WORD fatdate, WORD fattime, LPFILETIME ft)
925 newtm.tm_sec = (fattime & 0x1f) * 2;
926 newtm.tm_min = (fattime >> 5) & 0x3f;
927 newtm.tm_hour = (fattime >> 11);
928 newtm.tm_mday = (fatdate & 0x1f);
929 newtm.tm_mon = ((fatdate >> 5) & 0x0f) - 1;
930 newtm.tm_year = (fatdate >> 9) + 80;
932 RtlSecondsSince1970ToTime( timegm(&newtm), (LARGE_INTEGER *)ft );
934 time1 = mktime(&newtm);
935 gtm = gmtime(&time1);
937 RtlSecondsSince1970ToTime( 2*time1-time2, (LARGE_INTEGER *)ft );
943 /***********************************************************************
944 * FileTimeToDosDateTime (KERNEL32.@)
946 BOOL WINAPI FileTimeToDosDateTime( const FILETIME *ft, LPWORD fatdate,
954 li.u.LowPart = ft->dwLowDateTime;
955 li.u.HighPart = ft->dwHighDateTime;
956 RtlTimeToSecondsSince1970( &li, &t );
958 tm = gmtime( &unixtime );
960 *fattime = (tm->tm_hour << 11) + (tm->tm_min << 5) + (tm->tm_sec / 2);
962 *fatdate = ((tm->tm_year - 80) << 9) + ((tm->tm_mon + 1) << 5)