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_SYS_LIMITS_H
37 #include <sys/limits.h>
38 #elif defined(HAVE_MACHINE_LIMITS_H)
39 #include <machine/limits.h>
42 #define NONAMELESSUNION
43 #define NONAMELESSSTRUCT
45 #define WIN32_NO_STATUS
49 #include "kernel_private.h"
50 #include "wine/unicode.h"
51 #include "wine/debug.h"
53 WINE_DEFAULT_DEBUG_CHANNEL(time);
55 /* maximum time adjustment in seconds for SetLocalTime and SetSystemTime */
56 #define SETTIME_MAX_ADJUST 120
57 #define CALINFO_MAX_YEAR 2029
59 #define LL2FILETIME( ll, pft )\
60 (pft)->dwLowDateTime = (UINT)(ll); \
61 (pft)->dwHighDateTime = (UINT)((ll) >> 32);
62 #define FILETIME2LL( pft, ll) \
63 ll = (((LONGLONG)((pft)->dwHighDateTime))<<32) + (pft)-> dwLowDateTime ;
66 static const int MonthLengths[2][12] =
68 { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 },
69 { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }
72 static inline int IsLeapYear(int Year)
74 return Year % 4 == 0 && (Year % 100 != 0 || Year % 400 == 0) ? 1 : 0;
77 /***********************************************************************
78 * TIME_DayLightCompareDate
80 * Compares two dates without looking at the year
84 * -1 if date < compareDate
85 * 0 if date == compareDate
86 * 1 if date > compareDate
87 * -2 if an error occurs
89 static int TIME_DayLightCompareDate(
90 const SYSTEMTIME *date, /* [in] The local time to compare. */
91 const SYSTEMTIME *compareDate) /* [in] The daylight saving begin
94 int limit_day, dayinsecs;
96 if (date->wMonth < compareDate->wMonth)
97 return -1; /* We are in a month before the date limit. */
99 if (date->wMonth > compareDate->wMonth)
100 return 1; /* We are in a month after the date limit. */
102 if (compareDate->wDayOfWeek <= 6)
105 /* compareDate->wDay is interpreted as number of the week in the month
106 * 5 means: the last week in the month */
107 int weekofmonth = compareDate->wDay;
108 /* calculate the day of the first DayOfWeek in the month */
109 First = ( 6 + compareDate->wDayOfWeek - date->wDayOfWeek + date->wDay
111 limit_day = First + 7 * (weekofmonth - 1);
112 /* check needed for the 5th weekday of the month */
113 if(limit_day > MonthLengths[date->wMonth==2 && IsLeapYear(date->wYear)]
119 limit_day = compareDate->wDay;
122 /* convert to seconds */
123 limit_day = ((limit_day * 24 + compareDate->wHour) * 60 +
124 compareDate->wMinute ) * 60;
125 dayinsecs = ((date->wDay * 24 + date->wHour) * 60 +
126 date->wMinute ) * 60 + date->wSecond;
128 return dayinsecs < limit_day ? -1 :
129 dayinsecs > limit_day ? 1 :
130 0; /* date is equal to the date limit. */
133 /***********************************************************************
134 * TIME_CompTimeZoneID
136 * Computes the local time bias for a given time and time zone
139 * TIME_ZONE_ID_INVALID An error occurred
140 * TIME_ZONE_ID_UNKNOWN There are no transition time known
141 * TIME_ZONE_ID_STANDARD Current time is standard time
142 * TIME_ZONE_ID_DAYLIGHT Current time is dayligh saving time
144 static BOOL TIME_CompTimeZoneID (
145 const TIME_ZONE_INFORMATION *pTZinfo, /* [in] The time zone data. */
146 FILETIME *lpFileTime, /* [in] The system or local time. */
147 BOOL islocal /* [in] it is local time */
151 BOOL beforeStandardDate, afterDaylightDate;
152 DWORD retval = TIME_ZONE_ID_INVALID;
153 LONGLONG llTime = 0; /* initialized to prevent gcc complaining */
157 if (pTZinfo->DaylightDate.wMonth != 0)
159 if (pTZinfo->StandardDate.wMonth == 0 ||
160 pTZinfo->StandardDate.wDay<1 ||
161 pTZinfo->StandardDate.wDay>5 ||
162 pTZinfo->DaylightDate.wDay<1 ||
163 pTZinfo->DaylightDate.wDay>5)
165 SetLastError(ERROR_INVALID_PARAMETER);
166 return TIME_ZONE_ID_INVALID;
170 FILETIME2LL( lpFileTime, llTime );
171 llTime -= ( pTZinfo->Bias + pTZinfo->DaylightBias )
172 * (LONGLONG)600000000;
173 LL2FILETIME( llTime, &ftTemp)
174 lpFileTime = &ftTemp;
177 FileTimeToSystemTime(lpFileTime, &SysTime);
179 /* check for daylight saving */
180 ret = TIME_DayLightCompareDate( &SysTime, &pTZinfo->StandardDate);
182 return TIME_ZONE_ID_INVALID;
184 beforeStandardDate = ret < 0;
187 llTime -= ( pTZinfo->StandardBias - pTZinfo->DaylightBias )
188 * (LONGLONG)600000000;
189 LL2FILETIME( llTime, &ftTemp)
190 FileTimeToSystemTime(lpFileTime, &SysTime);
193 ret = TIME_DayLightCompareDate( &SysTime, &pTZinfo->DaylightDate);
195 return TIME_ZONE_ID_INVALID;
197 afterDaylightDate = ret >= 0;
199 retval = TIME_ZONE_ID_STANDARD;
200 if( pTZinfo->DaylightDate.wMonth < pTZinfo->StandardDate.wMonth ) {
201 /* Northern hemisphere */
202 if( beforeStandardDate && afterDaylightDate )
203 retval = TIME_ZONE_ID_DAYLIGHT;
204 } else /* Down south */
205 if( beforeStandardDate || afterDaylightDate )
206 retval = TIME_ZONE_ID_DAYLIGHT;
208 /* No transition date */
209 retval = TIME_ZONE_ID_UNKNOWN;
214 /***********************************************************************
217 * Calculates whether daylight saving is on now.
220 * TIME_ZONE_ID_INVALID An error occurred
221 * TIME_ZONE_ID_UNKNOWN There are no transition time known
222 * TIME_ZONE_ID_STANDARD Current time is standard time
223 * TIME_ZONE_ID_DAYLIGHT Current time is dayligh saving time
225 static DWORD TIME_ZoneID(
226 const TIME_ZONE_INFORMATION *pTzi /* Timezone info */
230 GetSystemTimeAsFileTime( &ftTime);
231 return TIME_CompTimeZoneID( pTzi, &ftTime, FALSE);
234 /***********************************************************************
235 * TIME_GetTimezoneBias
237 * Calculates the local time bias for a given time zone
241 * Returns TRUE when the time zone bias was calculated.
243 static BOOL TIME_GetTimezoneBias(
244 const TIME_ZONE_INFORMATION
245 *pTZinfo, /* [in] The time zone data. */
246 FILETIME *lpFileTime, /* [in] The system or local time. */
247 BOOL islocal, /* [in] it is local time */
248 LONG *pBias /* [out] The calculated bias in minutes */
251 LONG bias = pTZinfo->Bias;
252 DWORD tzid = TIME_CompTimeZoneID( pTZinfo, lpFileTime, islocal);
254 if( tzid == TIME_ZONE_ID_INVALID)
256 if (tzid == TIME_ZONE_ID_DAYLIGHT)
257 bias += pTZinfo->DaylightBias;
258 else if (tzid == TIME_ZONE_ID_STANDARD)
259 bias += pTZinfo->StandardBias;
265 /***********************************************************************
266 * SetLocalTime (KERNEL32.@)
268 * Set the local time using current time zone and daylight
272 * Success: TRUE. The time was set
273 * Failure: FALSE, if the time was invalid or caller does not have
274 * permission to change the time.
276 BOOL WINAPI SetLocalTime(
277 const SYSTEMTIME *systime) /* [in] The desired local time. */
280 LARGE_INTEGER st, st2;
283 if( !SystemTimeToFileTime( systime, &ft ))
285 st.u.LowPart = ft.dwLowDateTime;
286 st.u.HighPart = ft.dwHighDateTime;
287 RtlLocalTimeToSystemTime( &st, &st2 );
289 if ((status = NtSetSystemTime(&st2, NULL)))
290 SetLastError( RtlNtStatusToDosError(status) );
295 /***********************************************************************
296 * GetSystemTimeAdjustment (KERNEL32.@)
298 * Get the period between clock interrupts and the amount the clock
299 * is adjusted each interrupt so as to keep it in sync with an external source.
305 * Only the special case of disabled time adjustments is supported.
307 BOOL WINAPI GetSystemTimeAdjustment(
308 PDWORD lpTimeAdjustment, /* [out] The clock adjustment per interrupt in 100's of nanoseconds. */
309 PDWORD lpTimeIncrement, /* [out] The time between clock interrupts in 100's of nanoseconds. */
310 PBOOL lpTimeAdjustmentDisabled) /* [out] The clock synchronisation has been disabled. */
312 *lpTimeAdjustment = 0;
313 *lpTimeIncrement = 0;
314 *lpTimeAdjustmentDisabled = TRUE;
319 /***********************************************************************
320 * SetSystemTime (KERNEL32.@)
322 * Set the system time in utc.
325 * Success: TRUE. The time was set
326 * Failure: FALSE, if the time was invalid or caller does not have
327 * permission to change the time.
329 BOOL WINAPI SetSystemTime(
330 const SYSTEMTIME *systime) /* [in] The desired system time. */
336 if( !SystemTimeToFileTime( systime, &ft ))
338 t.u.LowPart = ft.dwLowDateTime;
339 t.u.HighPart = ft.dwHighDateTime;
340 if ((status = NtSetSystemTime(&t, NULL)))
341 SetLastError( RtlNtStatusToDosError(status) );
345 /***********************************************************************
346 * SetSystemTimeAdjustment (KERNEL32.@)
348 * Enables or disables the timing adjustments to the system's clock.
354 BOOL WINAPI SetSystemTimeAdjustment(
355 DWORD dwTimeAdjustment,
356 BOOL bTimeAdjustmentDisabled)
358 /* Fake function for now... */
359 FIXME("(%08lx,%d): stub !\n", dwTimeAdjustment, bTimeAdjustmentDisabled);
363 /***********************************************************************
364 * GetTimeZoneInformation (KERNEL32.@)
366 * Get information about the current local time zone.
369 * TIME_ZONE_ID_INVALID An error occurred
370 * TIME_ZONE_ID_UNKNOWN There are no transition time known
371 * TIME_ZONE_ID_STANDARD Current time is standard time
372 * TIME_ZONE_ID_DAYLIGHT Current time is dayligh saving time
374 DWORD WINAPI GetTimeZoneInformation(
375 LPTIME_ZONE_INFORMATION tzinfo) /* [out] Destination for time zone information */
379 status = RtlQueryTimeZoneInformation( (RTL_TIME_ZONE_INFORMATION*)tzinfo );
380 if ( status != STATUS_SUCCESS )
382 SetLastError( RtlNtStatusToDosError(status) );
383 return TIME_ZONE_ID_INVALID;
385 return TIME_ZoneID( tzinfo );
388 /***********************************************************************
389 * SetTimeZoneInformation (KERNEL32.@)
391 * Change the settings of the current local time zone.
394 * Success: TRUE. The time zone was updated with the settings from tzinfo
397 BOOL WINAPI SetTimeZoneInformation(
398 const TIME_ZONE_INFORMATION *tzinfo) /* [in] The new time zone. */
401 status = RtlSetTimeZoneInformation( (RTL_TIME_ZONE_INFORMATION*) tzinfo );
402 if ( status != STATUS_SUCCESS )
403 SetLastError( RtlNtStatusToDosError(status) );
407 /***********************************************************************
408 * SystemTimeToTzSpecificLocalTime (KERNEL32.@)
410 * Convert a utc system time to a local time in a given time zone.
413 * Success: TRUE. lpLocalTime contains the converted time
417 BOOL WINAPI SystemTimeToTzSpecificLocalTime(
418 LPTIME_ZONE_INFORMATION
419 lpTimeZoneInformation, /* [in] The desired time zone. */
420 LPSYSTEMTIME lpUniversalTime, /* [in] The utc time to base local time on. */
421 LPSYSTEMTIME lpLocalTime) /* [out] The local time in the time zone. */
426 TIME_ZONE_INFORMATION tzinfo;
428 if (lpTimeZoneInformation != NULL)
430 memcpy(&tzinfo, lpTimeZoneInformation, sizeof(TIME_ZONE_INFORMATION));
434 if (GetTimeZoneInformation(&tzinfo) == TIME_ZONE_ID_INVALID)
438 if (!SystemTimeToFileTime(lpUniversalTime, &ft))
440 FILETIME2LL( &ft, llTime)
441 if (!TIME_GetTimezoneBias(&tzinfo, &ft, FALSE, &lBias))
443 /* convert minutes to 100-nanoseconds-ticks */
444 llTime -= (LONGLONG)lBias * 600000000;
445 LL2FILETIME( llTime, &ft)
447 return FileTimeToSystemTime(&ft, lpLocalTime);
451 /***********************************************************************
452 * TzSpecificLocalTimeToSystemTime (KERNEL32.@)
454 * Converts a local time to a time in utc.
457 * Success: TRUE. lpUniversalTime contains the converted time
460 BOOL WINAPI TzSpecificLocalTimeToSystemTime(
461 LPTIME_ZONE_INFORMATION lpTimeZoneInformation, /* [in] The desired time zone. */
462 LPSYSTEMTIME lpLocalTime, /* [in] The local time. */
463 LPSYSTEMTIME lpUniversalTime) /* [out] The calculated utc time. */
468 TIME_ZONE_INFORMATION tzinfo;
470 if (lpTimeZoneInformation != NULL)
472 memcpy(&tzinfo, lpTimeZoneInformation, sizeof(TIME_ZONE_INFORMATION));
476 if (GetTimeZoneInformation(&tzinfo) == TIME_ZONE_ID_INVALID)
480 if (!SystemTimeToFileTime(lpLocalTime, &ft))
483 if (!TIME_GetTimezoneBias(&tzinfo, &ft, TRUE, &lBias))
485 /* convert minutes to 100-nanoseconds-ticks */
486 t += (LONGLONG)lBias * 600000000;
488 return FileTimeToSystemTime(&ft, lpUniversalTime);
492 /***********************************************************************
493 * GetSystemTimeAsFileTime (KERNEL32.@)
495 * Get the current time in utc format.
500 VOID WINAPI GetSystemTimeAsFileTime(
501 LPFILETIME time) /* [out] Destination for the current utc time */
504 NtQuerySystemTime( &t );
505 time->dwLowDateTime = t.u.LowPart;
506 time->dwHighDateTime = t.u.HighPart;
510 /*********************************************************************
511 * TIME_ClockTimeToFileTime (olorin@fandra.org, 20-Sep-1998)
513 * Used by GetProcessTimes to convert clock_t into FILETIME.
515 * Differences to UnixTimeToFileTime:
516 * 1) Divided by CLK_TCK
517 * 2) Time is relative. There is no 'starting date', so there is
518 * no need for offset correction, like in UnixTimeToFileTime
521 # define CLK_TCK CLOCKS_PER_SEC
523 static void TIME_ClockTimeToFileTime(clock_t unix_time, LPFILETIME filetime)
525 ULONGLONG secs = RtlEnlargedUnsignedMultiply( unix_time, 10000000 );
526 secs = RtlExtendedLargeIntegerDivide( secs, CLK_TCK, NULL );
527 filetime->dwLowDateTime = (DWORD)secs;
528 filetime->dwHighDateTime = (DWORD)(secs >> 32);
531 /*********************************************************************
532 * GetProcessTimes (KERNEL32.@)
534 * Get the user and kernel execution times of a process,
535 * along with the creation and exit times if known.
542 * Would be nice to subtract the cpu time used by Wine at startup.
543 * Also, there is a need to separate times used by different applications.
546 * lpCreationTime and lpExitTime are not initialised in the Wine implementation.
548 BOOL WINAPI GetProcessTimes(
549 HANDLE hprocess, /* [in] The process to be queried (obtained from PROCESS_QUERY_INFORMATION). */
550 LPFILETIME lpCreationTime, /* [out] The creation time of the process. */
551 LPFILETIME lpExitTime, /* [out] The exit time of the process if exited. */
552 LPFILETIME lpKernelTime, /* [out] The time spent in kernel routines in 100's of nanoseconds. */
553 LPFILETIME lpUserTime) /* [out] The time spent in user routines in 100's of nanoseconds. */
558 TIME_ClockTimeToFileTime(tms.tms_utime,lpUserTime);
559 TIME_ClockTimeToFileTime(tms.tms_stime,lpKernelTime);
563 /*********************************************************************
564 * GetCalendarInfoA (KERNEL32.@)
567 int WINAPI GetCalendarInfoA(LCID lcid, CALID Calendar, CALTYPE CalType,
568 LPSTR lpCalData, int cchData, LPDWORD lpValue)
571 LPWSTR lpCalDataW = NULL;
573 lcid = ConvertDefaultLocale(lcid);
575 if (NLS_IsUnicodeOnlyLcid(lcid))
577 SetLastError(ERROR_INVALID_PARAMETER);
582 !(lpCalDataW = HeapAlloc(GetProcessHeap(), 0, cchData*sizeof(WCHAR))))
585 ret = GetCalendarInfoW(lcid, Calendar, CalType, lpCalDataW, cchData, lpValue);
586 if(ret && lpCalDataW && lpCalData)
587 WideCharToMultiByte(CP_ACP, 0, lpCalDataW, cchData, lpCalData, cchData, NULL, NULL);
588 HeapFree(GetProcessHeap(), 0, lpCalDataW);
593 /*********************************************************************
594 * GetCalendarInfoW (KERNEL32.@)
597 int WINAPI GetCalendarInfoW(LCID Locale, CALID Calendar, CALTYPE CalType,
598 LPWSTR lpCalData, int cchData, LPDWORD lpValue)
600 if (CalType & CAL_NOUSEROVERRIDE)
601 FIXME("flag CAL_NOUSEROVERRIDE used, not fully implemented\n");
602 if (CalType & CAL_USE_CP_ACP)
603 FIXME("flag CAL_USE_CP_ACP used, not fully implemented\n");
605 if (CalType & CAL_RETURN_NUMBER) {
606 if (lpCalData != NULL)
607 WARN("lpCalData not NULL (%p) when it should!\n", lpCalData);
609 WARN("cchData not 0 (%d) when it should!\n", cchData);
612 WARN("lpValue not NULL (%p) when it should!\n", lpValue);
615 /* FIXME: No verification is made yet wrt Locale
616 * for the CALTYPES not requiring GetLocaleInfoA */
617 switch (CalType & ~(CAL_NOUSEROVERRIDE|CAL_RETURN_NUMBER|CAL_USE_CP_ACP)) {
618 case CAL_ICALINTVALUE:
619 FIXME("Unimplemented caltype %ld\n", CalType & 0xffff);
622 FIXME("Unimplemented caltype %ld\n", CalType & 0xffff);
624 case CAL_IYEAROFFSETRANGE:
625 FIXME("Unimplemented caltype %ld\n", CalType & 0xffff);
628 FIXME("Unimplemented caltype %ld\n", CalType & 0xffff);
631 return GetLocaleInfoW(Locale, LOCALE_SSHORTDATE, lpCalData, cchData);
633 return GetLocaleInfoW(Locale, LOCALE_SLONGDATE, lpCalData, cchData);
635 return GetLocaleInfoW(Locale, LOCALE_SDAYNAME1, lpCalData, cchData);
637 return GetLocaleInfoW(Locale, LOCALE_SDAYNAME2, lpCalData, cchData);
639 return GetLocaleInfoW(Locale, LOCALE_SDAYNAME3, lpCalData, cchData);
641 return GetLocaleInfoW(Locale, LOCALE_SDAYNAME4, lpCalData, cchData);
643 return GetLocaleInfoW(Locale, LOCALE_SDAYNAME5, lpCalData, cchData);
645 return GetLocaleInfoW(Locale, LOCALE_SDAYNAME6, lpCalData, cchData);
647 return GetLocaleInfoW(Locale, LOCALE_SDAYNAME7, lpCalData, cchData);
648 case CAL_SABBREVDAYNAME1:
649 return GetLocaleInfoW(Locale, LOCALE_SABBREVDAYNAME1, lpCalData, cchData);
650 case CAL_SABBREVDAYNAME2:
651 return GetLocaleInfoW(Locale, LOCALE_SABBREVDAYNAME2, lpCalData, cchData);
652 case CAL_SABBREVDAYNAME3:
653 return GetLocaleInfoW(Locale, LOCALE_SABBREVDAYNAME3, lpCalData, cchData);
654 case CAL_SABBREVDAYNAME4:
655 return GetLocaleInfoW(Locale, LOCALE_SABBREVDAYNAME4, lpCalData, cchData);
656 case CAL_SABBREVDAYNAME5:
657 return GetLocaleInfoW(Locale, LOCALE_SABBREVDAYNAME5, lpCalData, cchData);
658 case CAL_SABBREVDAYNAME6:
659 return GetLocaleInfoW(Locale, LOCALE_SABBREVDAYNAME6, lpCalData, cchData);
660 case CAL_SABBREVDAYNAME7:
661 return GetLocaleInfoW(Locale, LOCALE_SABBREVDAYNAME7, lpCalData, cchData);
662 case CAL_SMONTHNAME1:
663 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME1, lpCalData, cchData);
664 case CAL_SMONTHNAME2:
665 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME2, lpCalData, cchData);
666 case CAL_SMONTHNAME3:
667 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME3, lpCalData, cchData);
668 case CAL_SMONTHNAME4:
669 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME4, lpCalData, cchData);
670 case CAL_SMONTHNAME5:
671 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME5, lpCalData, cchData);
672 case CAL_SMONTHNAME6:
673 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME6, lpCalData, cchData);
674 case CAL_SMONTHNAME7:
675 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME7, lpCalData, cchData);
676 case CAL_SMONTHNAME8:
677 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME8, lpCalData, cchData);
678 case CAL_SMONTHNAME9:
679 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME9, lpCalData, cchData);
680 case CAL_SMONTHNAME10:
681 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME10, lpCalData, cchData);
682 case CAL_SMONTHNAME11:
683 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME11, lpCalData, cchData);
684 case CAL_SMONTHNAME12:
685 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME12, lpCalData, cchData);
686 case CAL_SMONTHNAME13:
687 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME13, lpCalData, cchData);
688 case CAL_SABBREVMONTHNAME1:
689 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME1, lpCalData, cchData);
690 case CAL_SABBREVMONTHNAME2:
691 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME2, lpCalData, cchData);
692 case CAL_SABBREVMONTHNAME3:
693 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME3, lpCalData, cchData);
694 case CAL_SABBREVMONTHNAME4:
695 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME4, lpCalData, cchData);
696 case CAL_SABBREVMONTHNAME5:
697 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME5, lpCalData, cchData);
698 case CAL_SABBREVMONTHNAME6:
699 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME6, lpCalData, cchData);
700 case CAL_SABBREVMONTHNAME7:
701 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME7, lpCalData, cchData);
702 case CAL_SABBREVMONTHNAME8:
703 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME8, lpCalData, cchData);
704 case CAL_SABBREVMONTHNAME9:
705 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME9, lpCalData, cchData);
706 case CAL_SABBREVMONTHNAME10:
707 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME10, lpCalData, cchData);
708 case CAL_SABBREVMONTHNAME11:
709 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME11, lpCalData, cchData);
710 case CAL_SABBREVMONTHNAME12:
711 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME12, lpCalData, cchData);
712 case CAL_SABBREVMONTHNAME13:
713 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME13, lpCalData, cchData);
715 return GetLocaleInfoW(Locale, LOCALE_SYEARMONTH, lpCalData, cchData);
716 case CAL_ITWODIGITYEARMAX:
717 if (lpValue) *lpValue = CALINFO_MAX_YEAR;
719 default: MESSAGE("Unknown caltype %ld\n",CalType & 0xffff);
725 /*********************************************************************
726 * SetCalendarInfoA (KERNEL32.@)
729 int WINAPI SetCalendarInfoA(LCID Locale, CALID Calendar, CALTYPE CalType, LPCSTR lpCalData)
731 FIXME("(%08lx,%08lx,%08lx,%s): stub\n",
732 Locale, Calendar, CalType, debugstr_a(lpCalData));
736 /*********************************************************************
737 * SetCalendarInfoW (KERNEL32.@)
741 int WINAPI SetCalendarInfoW(LCID Locale, CALID Calendar, CALTYPE CalType, LPCWSTR lpCalData)
743 FIXME("(%08lx,%08lx,%08lx,%s): stub\n",
744 Locale, Calendar, CalType, debugstr_w(lpCalData));
748 /*********************************************************************
749 * LocalFileTimeToFileTime (KERNEL32.@)
751 BOOL WINAPI LocalFileTimeToFileTime( const FILETIME *localft, LPFILETIME utcft )
754 LARGE_INTEGER local, utc;
756 local.u.LowPart = localft->dwLowDateTime;
757 local.u.HighPart = localft->dwHighDateTime;
758 if (!(status = RtlLocalTimeToSystemTime( &local, &utc )))
760 utcft->dwLowDateTime = utc.u.LowPart;
761 utcft->dwHighDateTime = utc.u.HighPart;
763 else SetLastError( RtlNtStatusToDosError(status) );
768 /*********************************************************************
769 * FileTimeToLocalFileTime (KERNEL32.@)
771 BOOL WINAPI FileTimeToLocalFileTime( const FILETIME *utcft, LPFILETIME localft )
774 LARGE_INTEGER local, utc;
776 utc.u.LowPart = utcft->dwLowDateTime;
777 utc.u.HighPart = utcft->dwHighDateTime;
778 if (!(status = RtlSystemTimeToLocalTime( &utc, &local )))
780 localft->dwLowDateTime = local.u.LowPart;
781 localft->dwHighDateTime = local.u.HighPart;
783 else SetLastError( RtlNtStatusToDosError(status) );
788 /*********************************************************************
789 * FileTimeToSystemTime (KERNEL32.@)
791 BOOL WINAPI FileTimeToSystemTime( const FILETIME *ft, LPSYSTEMTIME syst )
796 t.u.LowPart = ft->dwLowDateTime;
797 t.u.HighPart = ft->dwHighDateTime;
798 RtlTimeToTimeFields(&t, &tf);
800 syst->wYear = tf.Year;
801 syst->wMonth = tf.Month;
803 syst->wHour = tf.Hour;
804 syst->wMinute = tf.Minute;
805 syst->wSecond = tf.Second;
806 syst->wMilliseconds = tf.Milliseconds;
807 syst->wDayOfWeek = tf.Weekday;
811 /*********************************************************************
812 * SystemTimeToFileTime (KERNEL32.@)
814 BOOL WINAPI SystemTimeToFileTime( const SYSTEMTIME *syst, LPFILETIME ft )
819 tf.Year = syst->wYear;
820 tf.Month = syst->wMonth;
822 tf.Hour = syst->wHour;
823 tf.Minute = syst->wMinute;
824 tf.Second = syst->wSecond;
825 tf.Milliseconds = syst->wMilliseconds;
827 if( !RtlTimeFieldsToTime(&tf, &t)) {
828 SetLastError( ERROR_INVALID_PARAMETER);
831 ft->dwLowDateTime = t.u.LowPart;
832 ft->dwHighDateTime = t.u.HighPart;
836 /*********************************************************************
837 * CompareFileTime (KERNEL32.@)
839 * Compare two FILETIME's to each other.
843 * y [I] time to compare to x
846 * -1, 0, or 1 indicating that x is less than, equal to, or greater
847 * than y respectively.
849 INT WINAPI CompareFileTime( const FILETIME *x, const FILETIME *y )
851 if (!x || !y) return -1;
853 if (x->dwHighDateTime > y->dwHighDateTime)
855 if (x->dwHighDateTime < y->dwHighDateTime)
857 if (x->dwLowDateTime > y->dwLowDateTime)
859 if (x->dwLowDateTime < y->dwLowDateTime)
864 /*********************************************************************
865 * GetLocalTime (KERNEL32.@)
867 * Get the current local time.
872 VOID WINAPI GetLocalTime(LPSYSTEMTIME systime) /* [O] Destination for current time */
875 LARGE_INTEGER ft, ft2;
877 NtQuerySystemTime(&ft);
878 RtlSystemTimeToLocalTime(&ft, &ft2);
879 lft.dwLowDateTime = ft2.u.LowPart;
880 lft.dwHighDateTime = ft2.u.HighPart;
881 FileTimeToSystemTime(&lft, systime);
884 /*********************************************************************
885 * GetSystemTime (KERNEL32.@)
887 * Get the current system time.
892 VOID WINAPI GetSystemTime(LPSYSTEMTIME systime) /* [O] Destination for current time */
897 NtQuerySystemTime(&t);
898 ft.dwLowDateTime = t.u.LowPart;
899 ft.dwHighDateTime = t.u.HighPart;
900 FileTimeToSystemTime(&ft, systime);
903 /*********************************************************************
904 * GetDaylightFlag (KERNEL32.@)
906 * returns TRUE if daylight saving time is in operation
908 * Note: this function is called from the Win98's control applet
911 BOOL WINAPI GetDaylightFlag(void)
913 TIME_ZONE_INFORMATION tzinfo;
914 return GetTimeZoneInformation( &tzinfo) == TIME_ZONE_ID_DAYLIGHT;
917 /***********************************************************************
918 * DosDateTimeToFileTime (KERNEL32.@)
920 BOOL WINAPI DosDateTimeToFileTime( WORD fatdate, WORD fattime, LPFILETIME ft)
928 newtm.tm_sec = (fattime & 0x1f) * 2;
929 newtm.tm_min = (fattime >> 5) & 0x3f;
930 newtm.tm_hour = (fattime >> 11);
931 newtm.tm_mday = (fatdate & 0x1f);
932 newtm.tm_mon = ((fatdate >> 5) & 0x0f) - 1;
933 newtm.tm_year = (fatdate >> 9) + 80;
935 RtlSecondsSince1970ToTime( timegm(&newtm), (LARGE_INTEGER *)ft );
937 time1 = mktime(&newtm);
938 gtm = gmtime(&time1);
940 RtlSecondsSince1970ToTime( 2*time1-time2, (LARGE_INTEGER *)ft );
946 /***********************************************************************
947 * FileTimeToDosDateTime (KERNEL32.@)
949 BOOL WINAPI FileTimeToDosDateTime( const FILETIME *ft, LPWORD fatdate,
957 li.u.LowPart = ft->dwLowDateTime;
958 li.u.HighPart = ft->dwHighDateTime;
959 RtlTimeToSecondsSince1970( &li, &t );
961 tm = gmtime( &unixtime );
963 *fattime = (tm->tm_hour << 11) + (tm->tm_min << 5) + (tm->tm_sec / 2);
965 *fatdate = ((tm->tm_year - 80) << 9) + ((tm->tm_mon + 1) << 5)