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
45 #include "kernel_private.h"
46 #include "wine/unicode.h"
47 #include "wine/debug.h"
49 WINE_DEFAULT_DEBUG_CHANNEL(time);
51 /* maximum time adjustment in seconds for SetLocalTime and SetSystemTime */
52 #define SETTIME_MAX_ADJUST 120
53 #define CALINFO_MAX_YEAR 2029
55 #define LL2FILETIME( ll, pft )\
56 (pft)->dwLowDateTime = (UINT)(ll); \
57 (pft)->dwHighDateTime = (UINT)((ll) >> 32);
58 #define FILETIME2LL( pft, ll) \
59 ll = (((LONGLONG)((pft)->dwHighDateTime))<<32) + (pft)-> dwLowDateTime ;
62 static const int MonthLengths[2][12] =
64 { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 },
65 { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }
68 static inline int IsLeapYear(int Year)
70 return Year % 4 == 0 && (Year % 100 != 0 || Year % 400 == 0) ? 1 : 0;
73 /***********************************************************************
74 * TIME_DayLightCompareDate
76 * Compares two dates without looking at the year
80 * -1 if date < compareDate
81 * 0 if date == compareDate
82 * 1 if date > compareDate
83 * -2 if an error occurs
85 static int TIME_DayLightCompareDate(
86 const SYSTEMTIME *date, /* [in] The local time to compare. */
87 const SYSTEMTIME *compareDate) /* [in] The daylight saving begin
90 int limit_day, dayinsecs;
92 if (date->wMonth < compareDate->wMonth)
93 return -1; /* We are in a month before the date limit. */
95 if (date->wMonth > compareDate->wMonth)
96 return 1; /* We are in a month after the date limit. */
98 if (compareDate->wDayOfWeek <= 6)
101 /* compareDate->wDay is interpreted as number of the week in the month
102 * 5 means: the last week in the month */
103 int weekofmonth = compareDate->wDay;
104 /* calculate the day of the first DayOfWeek in the month */
105 First = ( 6 + compareDate->wDayOfWeek - date->wDayOfWeek + date->wDay
107 limit_day = First + 7 * (weekofmonth - 1);
108 /* check needed for the 5th weekday of the month */
109 if(limit_day > MonthLengths[date->wMonth==2 && IsLeapYear(date->wYear)]
115 limit_day = compareDate->wDay;
118 /* convert to seconds */
119 limit_day = ((limit_day * 24 + compareDate->wHour) * 60 +
120 compareDate->wMinute ) * 60;
121 dayinsecs = ((date->wDay * 24 + date->wHour) * 60 +
122 date->wMinute ) * 60 + date->wSecond;
124 return dayinsecs < limit_day ? -1 :
125 dayinsecs > limit_day ? 1 :
126 0; /* date is equal to the date limit. */
129 /***********************************************************************
130 * TIME_CompTimeZoneID
132 * Computes the local time bias for a given time and time zone
135 * TIME_ZONE_ID_INVALID An error occurred
136 * TIME_ZONE_ID_UNKNOWN There are no transition time known
137 * TIME_ZONE_ID_STANDARD Current time is standard time
138 * TIME_ZONE_ID_DAYLIGHT Current time is dayligh saving time
140 static BOOL TIME_CompTimeZoneID (
141 const TIME_ZONE_INFORMATION *pTZinfo, /* [in] The time zone data. */
142 FILETIME *lpFileTime, /* [in] The system or local time. */
143 BOOL islocal /* [in] it is local time */
147 BOOL beforeStandardDate, afterDaylightDate;
148 DWORD retval = TIME_ZONE_ID_INVALID;
149 LONGLONG llTime = 0; /* initialized to prevent gcc complaining */
153 if (pTZinfo->DaylightDate.wMonth != 0)
155 if (pTZinfo->StandardDate.wMonth == 0 ||
156 pTZinfo->StandardDate.wDay<1 ||
157 pTZinfo->StandardDate.wDay>5 ||
158 pTZinfo->DaylightDate.wDay<1 ||
159 pTZinfo->DaylightDate.wDay>5)
161 SetLastError(ERROR_INVALID_PARAMETER);
162 return TIME_ZONE_ID_INVALID;
166 FILETIME2LL( lpFileTime, llTime );
167 llTime -= ( pTZinfo->Bias + pTZinfo->DaylightBias )
168 * (LONGLONG)600000000;
169 LL2FILETIME( llTime, &ftTemp)
170 lpFileTime = &ftTemp;
173 FileTimeToSystemTime(lpFileTime, &SysTime);
175 /* check for daylight saving */
176 ret = TIME_DayLightCompareDate( &SysTime, &pTZinfo->StandardDate);
178 return TIME_ZONE_ID_INVALID;
180 beforeStandardDate = ret < 0;
183 llTime -= ( pTZinfo->StandardBias - pTZinfo->DaylightBias )
184 * (LONGLONG)600000000;
185 LL2FILETIME( llTime, &ftTemp)
186 FileTimeToSystemTime(lpFileTime, &SysTime);
189 ret = TIME_DayLightCompareDate( &SysTime, &pTZinfo->DaylightDate);
191 return TIME_ZONE_ID_INVALID;
193 afterDaylightDate = ret >= 0;
195 retval = TIME_ZONE_ID_STANDARD;
196 if( pTZinfo->DaylightDate.wMonth < pTZinfo->StandardDate.wMonth ) {
197 /* Northern hemisphere */
198 if( beforeStandardDate && afterDaylightDate )
199 retval = TIME_ZONE_ID_DAYLIGHT;
200 } else /* Down south */
201 if( beforeStandardDate || afterDaylightDate )
202 retval = TIME_ZONE_ID_DAYLIGHT;
204 /* No transition date */
205 retval = TIME_ZONE_ID_UNKNOWN;
210 /***********************************************************************
213 * Calculates whether daylight saving is on now.
216 * TIME_ZONE_ID_INVALID An error occurred
217 * TIME_ZONE_ID_UNKNOWN There are no transition time known
218 * TIME_ZONE_ID_STANDARD Current time is standard time
219 * TIME_ZONE_ID_DAYLIGHT Current time is dayligh saving time
221 static DWORD TIME_ZoneID(
222 const TIME_ZONE_INFORMATION *pTzi /* Timezone info */
226 GetSystemTimeAsFileTime( &ftTime);
227 return TIME_CompTimeZoneID( pTzi, &ftTime, FALSE);
230 /***********************************************************************
231 * TIME_GetTimezoneBias
233 * Calculates the local time bias for a given time zone
237 * Returns TRUE when the time zone bias was calculated.
239 static BOOL TIME_GetTimezoneBias(
240 const TIME_ZONE_INFORMATION
241 *pTZinfo, /* [in] The time zone data. */
242 FILETIME *lpFileTime, /* [in] The system or local time. */
243 BOOL islocal, /* [in] it is local time */
244 LONG *pBias /* [out] The calculated bias in minutes */
247 LONG bias = pTZinfo->Bias;
248 DWORD tzid = TIME_CompTimeZoneID( pTZinfo, lpFileTime, islocal);
250 if( tzid == TIME_ZONE_ID_INVALID)
252 if (tzid == TIME_ZONE_ID_DAYLIGHT)
253 bias += pTZinfo->DaylightBias;
254 else if (tzid == TIME_ZONE_ID_STANDARD)
255 bias += pTZinfo->StandardBias;
261 /***********************************************************************
262 * SetLocalTime (KERNEL32.@)
264 * Set the local time using current time zone and daylight
268 * Success: TRUE. The time was set
269 * Failure: FALSE, if the time was invalid or caller does not have
270 * permission to change the time.
272 BOOL WINAPI SetLocalTime(
273 const SYSTEMTIME *systime) /* [in] The desired local time. */
276 LARGE_INTEGER st, st2;
279 if( !SystemTimeToFileTime( systime, &ft ))
281 st.u.LowPart = ft.dwLowDateTime;
282 st.u.HighPart = ft.dwHighDateTime;
283 RtlLocalTimeToSystemTime( &st, &st2 );
285 if ((status = NtSetSystemTime(&st2, NULL)))
286 SetLastError( RtlNtStatusToDosError(status) );
291 /***********************************************************************
292 * GetSystemTimeAdjustment (KERNEL32.@)
294 * Get the period between clock interrupts and the amount the clock
295 * is adjusted each interrupt so as to keep it in sync with an external source.
301 * Only the special case of disabled time adjustments is supported.
303 BOOL WINAPI GetSystemTimeAdjustment(
304 PDWORD lpTimeAdjustment, /* [out] The clock adjustment per interrupt in 100's of nanoseconds. */
305 PDWORD lpTimeIncrement, /* [out] The time between clock interrupts in 100's of nanoseconds. */
306 PBOOL lpTimeAdjustmentDisabled) /* [out] The clock synchronisation has been disabled. */
308 *lpTimeAdjustment = 0;
309 *lpTimeIncrement = 0;
310 *lpTimeAdjustmentDisabled = TRUE;
315 /***********************************************************************
316 * SetSystemTime (KERNEL32.@)
318 * Set the system time in utc.
321 * Success: TRUE. The time was set
322 * Failure: FALSE, if the time was invalid or caller does not have
323 * permission to change the time.
325 BOOL WINAPI SetSystemTime(
326 const SYSTEMTIME *systime) /* [in] The desired system time. */
332 if( !SystemTimeToFileTime( systime, &ft ))
334 t.u.LowPart = ft.dwLowDateTime;
335 t.u.HighPart = ft.dwHighDateTime;
336 if ((status = NtSetSystemTime(&t, NULL)))
337 SetLastError( RtlNtStatusToDosError(status) );
341 /***********************************************************************
342 * SetSystemTimeAdjustment (KERNEL32.@)
344 * Enables or disables the timing adjustments to the system's clock.
350 BOOL WINAPI SetSystemTimeAdjustment(
351 DWORD dwTimeAdjustment,
352 BOOL bTimeAdjustmentDisabled)
354 /* Fake function for now... */
355 FIXME("(%08lx,%d): stub !\n", dwTimeAdjustment, bTimeAdjustmentDisabled);
359 /***********************************************************************
360 * GetTimeZoneInformation (KERNEL32.@)
362 * Get information about the current local time zone.
365 * TIME_ZONE_ID_INVALID An error occurred
366 * TIME_ZONE_ID_UNKNOWN There are no transition time known
367 * TIME_ZONE_ID_STANDARD Current time is standard time
368 * TIME_ZONE_ID_DAYLIGHT Current time is dayligh saving time
370 DWORD WINAPI GetTimeZoneInformation(
371 LPTIME_ZONE_INFORMATION tzinfo) /* [out] Destination for time zone information */
374 if ((status = RtlQueryTimeZoneInformation(tzinfo))) {
375 SetLastError( RtlNtStatusToDosError(status) );
376 return TIME_ZONE_ID_INVALID;
378 return TIME_ZoneID( tzinfo );
381 /***********************************************************************
382 * SetTimeZoneInformation (KERNEL32.@)
384 * Change the settings of the current local time zone.
387 * Success: TRUE. The time zone was updated with the settings from tzinfo
390 BOOL WINAPI SetTimeZoneInformation(
391 const TIME_ZONE_INFORMATION *tzinfo) /* [in] The new time zone. */
394 if ((status = RtlSetTimeZoneInformation(tzinfo)))
395 SetLastError( RtlNtStatusToDosError(status) );
399 /***********************************************************************
400 * SystemTimeToTzSpecificLocalTime (KERNEL32.@)
402 * Convert a utc system time to a local time in a given time zone.
405 * Success: TRUE. lpLocalTime contains the converted time
409 BOOL WINAPI SystemTimeToTzSpecificLocalTime(
410 LPTIME_ZONE_INFORMATION
411 lpTimeZoneInformation, /* [in] The desired time zone. */
412 LPSYSTEMTIME lpUniversalTime, /* [in] The utc time to base local time on. */
413 LPSYSTEMTIME lpLocalTime) /* [out] The local time in the time zone. */
418 TIME_ZONE_INFORMATION tzinfo;
420 if (lpTimeZoneInformation != NULL)
422 memcpy(&tzinfo, lpTimeZoneInformation, sizeof(TIME_ZONE_INFORMATION));
426 if (GetTimeZoneInformation(&tzinfo) == TIME_ZONE_ID_INVALID)
430 if (!SystemTimeToFileTime(lpUniversalTime, &ft))
432 FILETIME2LL( &ft, llTime)
433 if (!TIME_GetTimezoneBias(&tzinfo, &ft, FALSE, &lBias))
435 /* convert minutes to 100-nanoseconds-ticks */
436 llTime -= (LONGLONG)lBias * 600000000;
437 LL2FILETIME( llTime, &ft)
439 return FileTimeToSystemTime(&ft, lpLocalTime);
443 /***********************************************************************
444 * TzSpecificLocalTimeToSystemTime (KERNEL32.@)
446 * Converts a local time to a time in utc.
449 * Success: TRUE. lpUniversalTime contains the converted time
452 BOOL WINAPI TzSpecificLocalTimeToSystemTime(
453 LPTIME_ZONE_INFORMATION lpTimeZoneInformation, /* [in] The desired time zone. */
454 LPSYSTEMTIME lpLocalTime, /* [in] The local time. */
455 LPSYSTEMTIME lpUniversalTime) /* [out] The calculated utc time. */
460 TIME_ZONE_INFORMATION tzinfo;
462 if (lpTimeZoneInformation != NULL)
464 memcpy(&tzinfo, lpTimeZoneInformation, sizeof(TIME_ZONE_INFORMATION));
468 if (GetTimeZoneInformation(&tzinfo) == TIME_ZONE_ID_INVALID)
472 if (!SystemTimeToFileTime(lpLocalTime, &ft))
475 if (!TIME_GetTimezoneBias(&tzinfo, &ft, TRUE, &lBias))
477 /* convert minutes to 100-nanoseconds-ticks */
478 t += (LONGLONG)lBias * 600000000;
480 return FileTimeToSystemTime(&ft, lpUniversalTime);
484 /***********************************************************************
485 * GetSystemTimeAsFileTime (KERNEL32.@)
487 * Get the current time in utc format.
492 VOID WINAPI GetSystemTimeAsFileTime(
493 LPFILETIME time) /* [out] Destination for the current utc time */
496 NtQuerySystemTime( &t );
497 time->dwLowDateTime = t.u.LowPart;
498 time->dwHighDateTime = t.u.HighPart;
502 /*********************************************************************
503 * TIME_ClockTimeToFileTime (olorin@fandra.org, 20-Sep-1998)
505 * Used by GetProcessTimes to convert clock_t into FILETIME.
507 * Differences to UnixTimeToFileTime:
508 * 1) Divided by CLK_TCK
509 * 2) Time is relative. There is no 'starting date', so there is
510 * no need for offset correction, like in UnixTimeToFileTime
512 static void TIME_ClockTimeToFileTime(clock_t unix_time, LPFILETIME filetime)
514 ULONGLONG secs = RtlEnlargedUnsignedMultiply( unix_time, 10000000 );
515 secs = RtlExtendedLargeIntegerDivide( secs, CLK_TCK, NULL );
516 filetime->dwLowDateTime = (DWORD)secs;
517 filetime->dwHighDateTime = (DWORD)(secs >> 32);
520 /*********************************************************************
521 * GetProcessTimes (KERNEL32.@)
523 * Get the user and kernel execution times of a process,
524 * along with the creation and exit times if known.
531 * Would be nice to subtract the cpu time used by Wine at startup.
532 * Also, there is a need to separate times used by different applications.
535 * lpCreationTime and lpExitTime are not initialised in the Wine implementation.
537 BOOL WINAPI GetProcessTimes(
538 HANDLE hprocess, /* [in] The process to be queried (obtained from PROCESS_QUERY_INFORMATION). */
539 LPFILETIME lpCreationTime, /* [out] The creation time of the process. */
540 LPFILETIME lpExitTime, /* [out] The exit time of the process if exited. */
541 LPFILETIME lpKernelTime, /* [out] The time spent in kernel routines in 100's of nanoseconds. */
542 LPFILETIME lpUserTime) /* [out] The time spent in user routines in 100's of nanoseconds. */
547 TIME_ClockTimeToFileTime(tms.tms_utime,lpUserTime);
548 TIME_ClockTimeToFileTime(tms.tms_stime,lpKernelTime);
552 /*********************************************************************
553 * GetCalendarInfoA (KERNEL32.@)
556 int WINAPI GetCalendarInfoA(LCID lcid, CALID Calendar, CALTYPE CalType,
557 LPSTR lpCalData, int cchData, LPDWORD lpValue)
560 LPWSTR lpCalDataW = NULL;
562 FIXME("(%08lx,%08lx,%08lx,%p,%d,%p): quarter-stub\n",
563 lcid, Calendar, CalType, lpCalData, cchData, lpValue);
565 lcid = ConvertDefaultLocale(lcid);
567 if (NLS_IsUnicodeOnlyLcid(lcid))
569 SetLastError(ERROR_INVALID_PARAMETER);
574 !(lpCalDataW = HeapAlloc(GetProcessHeap(), 0, cchData*sizeof(WCHAR))))
577 ret = GetCalendarInfoW(lcid, Calendar, CalType, lpCalDataW, cchData, lpValue);
578 if(ret && lpCalDataW && lpCalData)
579 WideCharToMultiByte(CP_ACP, 0, lpCalDataW, cchData, lpCalData, cchData, NULL, NULL);
580 HeapFree(GetProcessHeap(), 0, lpCalDataW);
585 /*********************************************************************
586 * GetCalendarInfoW (KERNEL32.@)
588 * See GetCalendarInfoA.
590 int WINAPI GetCalendarInfoW(LCID Locale, CALID Calendar, CALTYPE CalType,
591 LPWSTR lpCalData, int cchData, LPDWORD lpValue)
593 FIXME("(%08lx,%08lx,%08lx,%p,%d,%p): quarter-stub\n",
594 Locale, Calendar, CalType, lpCalData, cchData, lpValue);
596 if (CalType & CAL_NOUSEROVERRIDE)
597 FIXME("flag CAL_NOUSEROVERRIDE used, not fully implemented\n");
598 if (CalType & CAL_USE_CP_ACP)
599 FIXME("flag CAL_USE_CP_ACP used, not fully implemented\n");
601 if (CalType & CAL_RETURN_NUMBER) {
602 if (lpCalData != NULL)
603 WARN("lpCalData not NULL (%p) when it should!\n", lpCalData);
605 WARN("cchData not 0 (%d) when it should!\n", cchData);
608 WARN("lpValue not NULL (%p) when it should!\n", lpValue);
611 /* FIXME: No verification is made yet wrt Locale
612 * for the CALTYPES not requiring GetLocaleInfoA */
613 switch (CalType & ~(CAL_NOUSEROVERRIDE|CAL_RETURN_NUMBER|CAL_USE_CP_ACP)) {
614 case CAL_ICALINTVALUE:
615 FIXME("Unimplemented caltype %ld\n", CalType & 0xffff);
618 FIXME("Unimplemented caltype %ld\n", CalType & 0xffff);
620 case CAL_IYEAROFFSETRANGE:
621 FIXME("Unimplemented caltype %ld\n", CalType & 0xffff);
624 FIXME("Unimplemented caltype %ld\n", CalType & 0xffff);
627 return GetLocaleInfoW(Locale, LOCALE_SSHORTDATE, lpCalData, cchData);
629 return GetLocaleInfoW(Locale, LOCALE_SLONGDATE, lpCalData, cchData);
631 return GetLocaleInfoW(Locale, LOCALE_SDAYNAME1, lpCalData, cchData);
633 return GetLocaleInfoW(Locale, LOCALE_SDAYNAME2, lpCalData, cchData);
635 return GetLocaleInfoW(Locale, LOCALE_SDAYNAME3, lpCalData, cchData);
637 return GetLocaleInfoW(Locale, LOCALE_SDAYNAME4, lpCalData, cchData);
639 return GetLocaleInfoW(Locale, LOCALE_SDAYNAME5, lpCalData, cchData);
641 return GetLocaleInfoW(Locale, LOCALE_SDAYNAME6, lpCalData, cchData);
643 return GetLocaleInfoW(Locale, LOCALE_SDAYNAME7, lpCalData, cchData);
644 case CAL_SABBREVDAYNAME1:
645 return GetLocaleInfoW(Locale, LOCALE_SABBREVDAYNAME1, lpCalData, cchData);
646 case CAL_SABBREVDAYNAME2:
647 return GetLocaleInfoW(Locale, LOCALE_SABBREVDAYNAME2, lpCalData, cchData);
648 case CAL_SABBREVDAYNAME3:
649 return GetLocaleInfoW(Locale, LOCALE_SABBREVDAYNAME3, lpCalData, cchData);
650 case CAL_SABBREVDAYNAME4:
651 return GetLocaleInfoW(Locale, LOCALE_SABBREVDAYNAME4, lpCalData, cchData);
652 case CAL_SABBREVDAYNAME5:
653 return GetLocaleInfoW(Locale, LOCALE_SABBREVDAYNAME5, lpCalData, cchData);
654 case CAL_SABBREVDAYNAME6:
655 return GetLocaleInfoW(Locale, LOCALE_SABBREVDAYNAME6, lpCalData, cchData);
656 case CAL_SABBREVDAYNAME7:
657 return GetLocaleInfoW(Locale, LOCALE_SABBREVDAYNAME7, lpCalData, cchData);
658 case CAL_SMONTHNAME1:
659 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME1, lpCalData, cchData);
660 case CAL_SMONTHNAME2:
661 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME2, lpCalData, cchData);
662 case CAL_SMONTHNAME3:
663 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME3, lpCalData, cchData);
664 case CAL_SMONTHNAME4:
665 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME4, lpCalData, cchData);
666 case CAL_SMONTHNAME5:
667 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME5, lpCalData, cchData);
668 case CAL_SMONTHNAME6:
669 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME6, lpCalData, cchData);
670 case CAL_SMONTHNAME7:
671 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME7, lpCalData, cchData);
672 case CAL_SMONTHNAME8:
673 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME8, lpCalData, cchData);
674 case CAL_SMONTHNAME9:
675 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME9, lpCalData, cchData);
676 case CAL_SMONTHNAME10:
677 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME10, lpCalData, cchData);
678 case CAL_SMONTHNAME11:
679 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME11, lpCalData, cchData);
680 case CAL_SMONTHNAME12:
681 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME12, lpCalData, cchData);
682 case CAL_SMONTHNAME13:
683 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME13, lpCalData, cchData);
684 case CAL_SABBREVMONTHNAME1:
685 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME1, lpCalData, cchData);
686 case CAL_SABBREVMONTHNAME2:
687 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME2, lpCalData, cchData);
688 case CAL_SABBREVMONTHNAME3:
689 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME3, lpCalData, cchData);
690 case CAL_SABBREVMONTHNAME4:
691 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME4, lpCalData, cchData);
692 case CAL_SABBREVMONTHNAME5:
693 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME5, lpCalData, cchData);
694 case CAL_SABBREVMONTHNAME6:
695 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME6, lpCalData, cchData);
696 case CAL_SABBREVMONTHNAME7:
697 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME7, lpCalData, cchData);
698 case CAL_SABBREVMONTHNAME8:
699 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME8, lpCalData, cchData);
700 case CAL_SABBREVMONTHNAME9:
701 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME9, lpCalData, cchData);
702 case CAL_SABBREVMONTHNAME10:
703 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME10, lpCalData, cchData);
704 case CAL_SABBREVMONTHNAME11:
705 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME11, lpCalData, cchData);
706 case CAL_SABBREVMONTHNAME12:
707 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME12, lpCalData, cchData);
708 case CAL_SABBREVMONTHNAME13:
709 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME13, lpCalData, cchData);
711 return GetLocaleInfoW(Locale, LOCALE_SYEARMONTH, lpCalData, cchData);
712 case CAL_ITWODIGITYEARMAX:
713 if (lpValue) *lpValue = CALINFO_MAX_YEAR;
715 default: MESSAGE("Unknown caltype %ld\n",CalType & 0xffff);
721 /*********************************************************************
722 * SetCalendarInfoA (KERNEL32.@)
725 int WINAPI SetCalendarInfoA(LCID Locale, CALID Calendar, CALTYPE CalType, LPCSTR lpCalData)
727 FIXME("(%08lx,%08lx,%08lx,%s): stub\n",
728 Locale, Calendar, CalType, debugstr_a(lpCalData));
732 /*********************************************************************
733 * SetCalendarInfoW (KERNEL32.@)
735 * See SetCalendarInfoA.
737 int WINAPI SetCalendarInfoW(LCID Locale, CALID Calendar, CALTYPE CalType, LPCWSTR lpCalData)
739 FIXME("(%08lx,%08lx,%08lx,%s): stub\n",
740 Locale, Calendar, CalType, debugstr_w(lpCalData));
744 /*********************************************************************
745 * LocalFileTimeToFileTime (KERNEL32.@)
747 BOOL WINAPI LocalFileTimeToFileTime( const FILETIME *localft, LPFILETIME utcft )
750 LARGE_INTEGER local, utc;
752 local.u.LowPart = localft->dwLowDateTime;
753 local.u.HighPart = localft->dwHighDateTime;
754 if (!(status = RtlLocalTimeToSystemTime( &local, &utc )))
756 utcft->dwLowDateTime = utc.u.LowPart;
757 utcft->dwHighDateTime = utc.u.HighPart;
759 else SetLastError( RtlNtStatusToDosError(status) );
764 /*********************************************************************
765 * FileTimeToLocalFileTime (KERNEL32.@)
767 BOOL WINAPI FileTimeToLocalFileTime( const FILETIME *utcft, LPFILETIME localft )
770 LARGE_INTEGER local, utc;
772 utc.u.LowPart = utcft->dwLowDateTime;
773 utc.u.HighPart = utcft->dwHighDateTime;
774 if (!(status = RtlSystemTimeToLocalTime( &utc, &local )))
776 localft->dwLowDateTime = local.u.LowPart;
777 localft->dwHighDateTime = local.u.HighPart;
779 else SetLastError( RtlNtStatusToDosError(status) );
784 /*********************************************************************
785 * FileTimeToSystemTime (KERNEL32.@)
787 BOOL WINAPI FileTimeToSystemTime( const FILETIME *ft, LPSYSTEMTIME syst )
792 t.u.LowPart = ft->dwLowDateTime;
793 t.u.HighPart = ft->dwHighDateTime;
794 RtlTimeToTimeFields(&t, &tf);
796 syst->wYear = tf.Year;
797 syst->wMonth = tf.Month;
799 syst->wHour = tf.Hour;
800 syst->wMinute = tf.Minute;
801 syst->wSecond = tf.Second;
802 syst->wMilliseconds = tf.Milliseconds;
803 syst->wDayOfWeek = tf.Weekday;
807 /*********************************************************************
808 * SystemTimeToFileTime (KERNEL32.@)
810 BOOL WINAPI SystemTimeToFileTime( const SYSTEMTIME *syst, LPFILETIME ft )
815 tf.Year = syst->wYear;
816 tf.Month = syst->wMonth;
818 tf.Hour = syst->wHour;
819 tf.Minute = syst->wMinute;
820 tf.Second = syst->wSecond;
821 tf.Milliseconds = syst->wMilliseconds;
823 if( !RtlTimeFieldsToTime(&tf, &t)) {
824 SetLastError( ERROR_INVALID_PARAMETER);
827 ft->dwLowDateTime = t.u.LowPart;
828 ft->dwHighDateTime = t.u.HighPart;
832 /*********************************************************************
833 * CompareFileTime (KERNEL32.@)
835 * Compare two FILETIME's to each other.
839 * y [I] time to compare to x
842 * -1, 0, or 1 indicating that x is less than, equal to, or greater
843 * than y respectively.
845 INT WINAPI CompareFileTime( const FILETIME *x, const FILETIME *y )
847 if (!x || !y) return -1;
849 if (x->dwHighDateTime > y->dwHighDateTime)
851 if (x->dwHighDateTime < y->dwHighDateTime)
853 if (x->dwLowDateTime > y->dwLowDateTime)
855 if (x->dwLowDateTime < y->dwLowDateTime)
860 /*********************************************************************
861 * GetLocalTime (KERNEL32.@)
863 * Get the current local time.
868 VOID WINAPI GetLocalTime(LPSYSTEMTIME systime) /* [O] Destination for current time */
871 LARGE_INTEGER ft, ft2;
873 NtQuerySystemTime(&ft);
874 RtlSystemTimeToLocalTime(&ft, &ft2);
875 lft.dwLowDateTime = ft2.u.LowPart;
876 lft.dwHighDateTime = ft2.u.HighPart;
877 FileTimeToSystemTime(&lft, systime);
880 /*********************************************************************
881 * GetSystemTime (KERNEL32.@)
883 * Get the current system time.
888 VOID WINAPI GetSystemTime(LPSYSTEMTIME systime) /* [O] Destination for current time */
893 NtQuerySystemTime(&t);
894 ft.dwLowDateTime = t.u.LowPart;
895 ft.dwHighDateTime = t.u.HighPart;
896 FileTimeToSystemTime(&ft, systime);
899 /*********************************************************************
900 * GetDaylightFlag (KERNEL32.@)
902 * returns TRUE if daylight saving time is in operation
904 * Note: this function is called from the Win98's control applet
907 BOOL WINAPI GetDaylightFlag(void)
909 TIME_ZONE_INFORMATION tzinfo;
910 return GetTimeZoneInformation( &tzinfo) == TIME_ZONE_ID_DAYLIGHT;
913 /***********************************************************************
914 * DosDateTimeToFileTime (KERNEL32.@)
916 BOOL WINAPI DosDateTimeToFileTime( WORD fatdate, WORD fattime, LPFILETIME ft)
924 newtm.tm_sec = (fattime & 0x1f) * 2;
925 newtm.tm_min = (fattime >> 5) & 0x3f;
926 newtm.tm_hour = (fattime >> 11);
927 newtm.tm_mday = (fatdate & 0x1f);
928 newtm.tm_mon = ((fatdate >> 5) & 0x0f) - 1;
929 newtm.tm_year = (fatdate >> 9) + 80;
931 RtlSecondsSince1970ToTime( timegm(&newtm), (LARGE_INTEGER *)ft );
933 time1 = mktime(&newtm);
934 gtm = gmtime(&time1);
936 RtlSecondsSince1970ToTime( 2*time1-time2, (LARGE_INTEGER *)ft );
942 /***********************************************************************
943 * FileTimeToDosDateTime (KERNEL32.@)
945 BOOL WINAPI FileTimeToDosDateTime( const FILETIME *ft, LPWORD fatdate,
953 li.u.LowPart = ft->dwLowDateTime;
954 li.u.HighPart = ft->dwHighDateTime;
955 RtlTimeToSecondsSince1970( &li, &t );
957 tm = gmtime( &unixtime );
959 *fattime = (tm->tm_hour << 11) + (tm->tm_min << 5) + (tm->tm_sec / 2);
961 *fatdate = ((tm->tm_year - 80) << 9) + ((tm->tm_mon + 1) << 5)