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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, 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.
83 * date [in] The local time to compare.
84 * compareDate [in] The daylight saving begin or end date.
88 * -1 if date < compareDate
89 * 0 if date == compareDate
90 * 1 if date > compareDate
91 * -2 if an error occurs
93 static int TIME_DayLightCompareDate( const SYSTEMTIME *date,
94 const SYSTEMTIME *compareDate )
96 int limit_day, dayinsecs;
98 if (date->wMonth < compareDate->wMonth)
99 return -1; /* We are in a month before the date limit. */
101 if (date->wMonth > compareDate->wMonth)
102 return 1; /* We are in a month after the date limit. */
104 if (compareDate->wDayOfWeek <= 6)
107 /* compareDate->wDay is interpreted as number of the week in the month
108 * 5 means: the last week in the month */
109 int weekofmonth = compareDate->wDay;
110 /* calculate the day of the first DayOfWeek in the month */
111 First = ( 6 + compareDate->wDayOfWeek - date->wDayOfWeek + date->wDay
113 limit_day = First + 7 * (weekofmonth - 1);
114 /* check needed for the 5th weekday of the month */
115 if(limit_day > MonthLengths[date->wMonth==2 && IsLeapYear(date->wYear)]
121 limit_day = compareDate->wDay;
124 /* convert to seconds */
125 limit_day = ((limit_day * 24 + compareDate->wHour) * 60 +
126 compareDate->wMinute ) * 60;
127 dayinsecs = ((date->wDay * 24 + date->wHour) * 60 +
128 date->wMinute ) * 60 + date->wSecond;
130 return dayinsecs < limit_day ? -1 :
131 dayinsecs > limit_day ? 1 :
132 0; /* date is equal to the date limit. */
135 /***********************************************************************
136 * TIME_CompTimeZoneID
138 * Computes the local time bias for a given time and time zone.
141 * pTZinfo [in] The time zone data.
142 * lpFileTime [in] The system or local time.
143 * islocal [in] it is local time.
146 * TIME_ZONE_ID_INVALID An error occurred
147 * TIME_ZONE_ID_UNKNOWN There are no transition time known
148 * TIME_ZONE_ID_STANDARD Current time is standard time
149 * TIME_ZONE_ID_DAYLIGHT Current time is dayligh saving time
151 static BOOL TIME_CompTimeZoneID ( const TIME_ZONE_INFORMATION *pTZinfo,
152 FILETIME *lpFileTime, BOOL islocal )
155 BOOL beforeStandardDate, afterDaylightDate;
156 DWORD retval = TIME_ZONE_ID_INVALID;
157 LONGLONG llTime = 0; /* initialized to prevent gcc complaining */
161 if (pTZinfo->DaylightDate.wMonth != 0)
163 if (pTZinfo->StandardDate.wMonth == 0 ||
164 pTZinfo->StandardDate.wDay<1 ||
165 pTZinfo->StandardDate.wDay>5 ||
166 pTZinfo->DaylightDate.wDay<1 ||
167 pTZinfo->DaylightDate.wDay>5)
169 SetLastError(ERROR_INVALID_PARAMETER);
170 return TIME_ZONE_ID_INVALID;
174 FILETIME2LL( lpFileTime, llTime );
175 llTime -= ( pTZinfo->Bias + pTZinfo->DaylightBias )
176 * (LONGLONG)600000000;
177 LL2FILETIME( llTime, &ftTemp)
178 lpFileTime = &ftTemp;
181 FileTimeToSystemTime(lpFileTime, &SysTime);
183 /* check for daylight saving */
184 ret = TIME_DayLightCompareDate( &SysTime, &pTZinfo->StandardDate);
186 return TIME_ZONE_ID_INVALID;
188 beforeStandardDate = ret < 0;
191 llTime -= ( pTZinfo->StandardBias - pTZinfo->DaylightBias )
192 * (LONGLONG)600000000;
193 LL2FILETIME( llTime, &ftTemp)
194 FileTimeToSystemTime(lpFileTime, &SysTime);
197 ret = TIME_DayLightCompareDate( &SysTime, &pTZinfo->DaylightDate);
199 return TIME_ZONE_ID_INVALID;
201 afterDaylightDate = ret >= 0;
203 retval = TIME_ZONE_ID_STANDARD;
204 if( pTZinfo->DaylightDate.wMonth < pTZinfo->StandardDate.wMonth ) {
205 /* Northern hemisphere */
206 if( beforeStandardDate && afterDaylightDate )
207 retval = TIME_ZONE_ID_DAYLIGHT;
208 } else /* Down south */
209 if( beforeStandardDate || afterDaylightDate )
210 retval = TIME_ZONE_ID_DAYLIGHT;
212 /* No transition date */
213 retval = TIME_ZONE_ID_UNKNOWN;
218 /***********************************************************************
221 * Calculates whether daylight saving is on now.
224 * pTzi [in] Timezone info.
227 * TIME_ZONE_ID_INVALID An error occurred
228 * TIME_ZONE_ID_UNKNOWN There are no transition time known
229 * TIME_ZONE_ID_STANDARD Current time is standard time
230 * TIME_ZONE_ID_DAYLIGHT Current time is dayligh saving time
232 static DWORD TIME_ZoneID( const TIME_ZONE_INFORMATION *pTzi )
235 GetSystemTimeAsFileTime( &ftTime);
236 return TIME_CompTimeZoneID( pTzi, &ftTime, FALSE);
239 /***********************************************************************
240 * TIME_GetTimezoneBias
242 * Calculates the local time bias for a given time zone.
245 * pTZinfo [in] The time zone data.
246 * lpFileTime [in] The system or local time.
247 * islocal [in] It is local time.
248 * pBias [out] The calculated bias in minutes.
251 * TRUE when the time zone bias was calculated.
253 static BOOL TIME_GetTimezoneBias( const TIME_ZONE_INFORMATION *pTZinfo,
254 FILETIME *lpFileTime, BOOL islocal, LONG *pBias )
256 LONG bias = pTZinfo->Bias;
257 DWORD tzid = TIME_CompTimeZoneID( pTZinfo, lpFileTime, islocal);
259 if( tzid == TIME_ZONE_ID_INVALID)
261 if (tzid == TIME_ZONE_ID_DAYLIGHT)
262 bias += pTZinfo->DaylightBias;
263 else if (tzid == TIME_ZONE_ID_STANDARD)
264 bias += pTZinfo->StandardBias;
270 /***********************************************************************
271 * SetLocalTime (KERNEL32.@)
273 * Set the local time using current time zone and daylight
277 * systime [in] The desired local time.
280 * Success: TRUE. The time was set.
281 * Failure: FALSE, if the time was invalid or caller does not have
282 * permission to change the time.
284 BOOL WINAPI SetLocalTime( const SYSTEMTIME *systime )
287 LARGE_INTEGER st, st2;
290 if( !SystemTimeToFileTime( systime, &ft ))
292 st.u.LowPart = ft.dwLowDateTime;
293 st.u.HighPart = ft.dwHighDateTime;
294 RtlLocalTimeToSystemTime( &st, &st2 );
296 if ((status = NtSetSystemTime(&st2, NULL)))
297 SetLastError( RtlNtStatusToDosError(status) );
302 /***********************************************************************
303 * GetSystemTimeAdjustment (KERNEL32.@)
305 * Get the period between clock interrupts and the amount the clock
306 * is adjusted each interrupt so as to keep it in sync with an external source.
309 * lpTimeAdjustment [out] The clock adjustment per interrupt in 100's of nanoseconds.
310 * lpTimeIncrement [out] The time between clock interrupts in 100's of nanoseconds.
311 * lpTimeAdjustmentDisabled [out] The clock synchronisation has been disabled.
317 * Only the special case of disabled time adjustments is supported.
319 BOOL WINAPI GetSystemTimeAdjustment( PDWORD lpTimeAdjustment, PDWORD lpTimeIncrement,
320 PBOOL lpTimeAdjustmentDisabled )
322 *lpTimeAdjustment = 0;
323 *lpTimeIncrement = 0;
324 *lpTimeAdjustmentDisabled = TRUE;
329 /***********************************************************************
330 * SetSystemTime (KERNEL32.@)
332 * Set the system time in utc.
335 * systime [in] The desired system time.
338 * Success: TRUE. The time was set.
339 * Failure: FALSE, if the time was invalid or caller does not have
340 * permission to change the time.
342 BOOL WINAPI SetSystemTime( const SYSTEMTIME *systime )
348 if( !SystemTimeToFileTime( systime, &ft ))
350 t.u.LowPart = ft.dwLowDateTime;
351 t.u.HighPart = ft.dwHighDateTime;
352 if ((status = NtSetSystemTime(&t, NULL)))
353 SetLastError( RtlNtStatusToDosError(status) );
357 /***********************************************************************
358 * SetSystemTimeAdjustment (KERNEL32.@)
360 * Enables or disables the timing adjustments to the system's clock.
363 * dwTimeAdjustment [in] Number of units to add per clock interrupt.
364 * bTimeAdjustmentDisabled [in] Adjustment mode.
370 BOOL WINAPI SetSystemTimeAdjustment( DWORD dwTimeAdjustment, BOOL bTimeAdjustmentDisabled )
372 /* Fake function for now... */
373 FIXME("(%08x,%d): stub !\n", dwTimeAdjustment, bTimeAdjustmentDisabled);
377 /***********************************************************************
378 * GetTimeZoneInformation (KERNEL32.@)
380 * Get information about the current local time zone.
383 * tzinfo [out] Destination for time zone information.
386 * TIME_ZONE_ID_INVALID An error occurred
387 * TIME_ZONE_ID_UNKNOWN There are no transition time known
388 * TIME_ZONE_ID_STANDARD Current time is standard time
389 * TIME_ZONE_ID_DAYLIGHT Current time is dayligh saving time
391 DWORD WINAPI GetTimeZoneInformation( LPTIME_ZONE_INFORMATION tzinfo )
395 status = RtlQueryTimeZoneInformation( (RTL_TIME_ZONE_INFORMATION*)tzinfo );
396 if ( status != STATUS_SUCCESS )
398 SetLastError( RtlNtStatusToDosError(status) );
399 return TIME_ZONE_ID_INVALID;
401 return TIME_ZoneID( tzinfo );
404 /***********************************************************************
405 * SetTimeZoneInformation (KERNEL32.@)
407 * Change the settings of the current local time zone.
410 * tzinfo [in] The new time zone.
413 * Success: TRUE. The time zone was updated with the settings from tzinfo.
416 BOOL WINAPI SetTimeZoneInformation( const TIME_ZONE_INFORMATION *tzinfo )
419 status = RtlSetTimeZoneInformation( (const RTL_TIME_ZONE_INFORMATION *)tzinfo );
420 if ( status != STATUS_SUCCESS )
421 SetLastError( RtlNtStatusToDosError(status) );
425 /***********************************************************************
426 * SystemTimeToTzSpecificLocalTime (KERNEL32.@)
428 * Convert a utc system time to a local time in a given time zone.
431 * lpTimeZoneInformation [in] The desired time zone.
432 * lpUniversalTime [in] The utc time to base local time on.
433 * lpLocalTime [out] The local time in the time zone.
436 * Success: TRUE. lpLocalTime contains the converted time
440 BOOL WINAPI SystemTimeToTzSpecificLocalTime(
441 LPTIME_ZONE_INFORMATION lpTimeZoneInformation,
442 LPSYSTEMTIME lpUniversalTime, LPSYSTEMTIME lpLocalTime )
447 TIME_ZONE_INFORMATION tzinfo;
449 if (lpTimeZoneInformation != NULL)
451 memcpy(&tzinfo, lpTimeZoneInformation, sizeof(TIME_ZONE_INFORMATION));
455 if (GetTimeZoneInformation(&tzinfo) == TIME_ZONE_ID_INVALID)
459 if (!SystemTimeToFileTime(lpUniversalTime, &ft))
461 FILETIME2LL( &ft, llTime)
462 if (!TIME_GetTimezoneBias(&tzinfo, &ft, FALSE, &lBias))
464 /* convert minutes to 100-nanoseconds-ticks */
465 llTime -= (LONGLONG)lBias * 600000000;
466 LL2FILETIME( llTime, &ft)
468 return FileTimeToSystemTime(&ft, lpLocalTime);
472 /***********************************************************************
473 * TzSpecificLocalTimeToSystemTime (KERNEL32.@)
475 * Converts a local time to a time in utc.
478 * lpTimeZoneInformation [in] The desired time zone.
479 * lpLocalTime [in] The local time.
480 * lpUniversalTime [out] The calculated utc time.
483 * Success: TRUE. lpUniversalTime contains the converted time.
486 BOOL WINAPI TzSpecificLocalTimeToSystemTime(
487 LPTIME_ZONE_INFORMATION lpTimeZoneInformation,
488 LPSYSTEMTIME lpLocalTime, LPSYSTEMTIME lpUniversalTime)
493 TIME_ZONE_INFORMATION tzinfo;
495 if (lpTimeZoneInformation != NULL)
497 memcpy(&tzinfo, lpTimeZoneInformation, sizeof(TIME_ZONE_INFORMATION));
501 if (GetTimeZoneInformation(&tzinfo) == TIME_ZONE_ID_INVALID)
505 if (!SystemTimeToFileTime(lpLocalTime, &ft))
508 if (!TIME_GetTimezoneBias(&tzinfo, &ft, TRUE, &lBias))
510 /* convert minutes to 100-nanoseconds-ticks */
511 t += (LONGLONG)lBias * 600000000;
513 return FileTimeToSystemTime(&ft, lpUniversalTime);
517 /***********************************************************************
518 * GetSystemTimeAsFileTime (KERNEL32.@)
520 * Get the current time in utc format.
525 VOID WINAPI GetSystemTimeAsFileTime(
526 LPFILETIME time) /* [out] Destination for the current utc time */
529 NtQuerySystemTime( &t );
530 time->dwLowDateTime = t.u.LowPart;
531 time->dwHighDateTime = t.u.HighPart;
535 /*********************************************************************
536 * TIME_ClockTimeToFileTime (olorin@fandra.org, 20-Sep-1998)
538 * Used by GetProcessTimes to convert clock_t into FILETIME.
540 * Differences to UnixTimeToFileTime:
541 * 1) Divided by CLK_TCK
542 * 2) Time is relative. There is no 'starting date', so there is
543 * no need for offset correction, like in UnixTimeToFileTime
546 # define CLK_TCK CLOCKS_PER_SEC
548 static void TIME_ClockTimeToFileTime(clock_t unix_time, LPFILETIME filetime)
550 ULONGLONG secs = RtlEnlargedUnsignedMultiply( unix_time, 10000000 );
551 secs = RtlExtendedLargeIntegerDivide( secs, CLK_TCK, NULL );
552 filetime->dwLowDateTime = (DWORD)secs;
553 filetime->dwHighDateTime = (DWORD)(secs >> 32);
556 /*********************************************************************
557 * GetProcessTimes (KERNEL32.@)
559 * Get the user and kernel execution times of a process,
560 * along with the creation and exit times if known.
563 * hprocess [in] The process to be queried.
564 * lpCreationTime [out] The creation time of the process.
565 * lpExitTime [out] The exit time of the process if exited.
566 * lpKernelTime [out] The time spent in kernel routines in 100's of nanoseconds.
567 * lpUserTime [out] The time spent in user routines in 100's of nanoseconds.
574 * Would be nice to subtract the cpu time used by Wine at startup.
575 * Also, there is a need to separate times used by different applications.
578 * KernelTime and UserTime are always for the current process
580 BOOL WINAPI GetProcessTimes( HANDLE hprocess, LPFILETIME lpCreationTime,
581 LPFILETIME lpExitTime, LPFILETIME lpKernelTime, LPFILETIME lpUserTime )
584 KERNEL_USER_TIMES pti;
587 TIME_ClockTimeToFileTime(tms.tms_utime,lpUserTime);
588 TIME_ClockTimeToFileTime(tms.tms_stime,lpKernelTime);
589 if (NtQueryInformationProcess( hprocess, ProcessTimes, &pti, sizeof(pti), NULL))
591 LL2FILETIME( pti.CreateTime.QuadPart, lpCreationTime);
592 LL2FILETIME( pti.ExitTime.QuadPart, lpExitTime);
596 /*********************************************************************
597 * GetCalendarInfoA (KERNEL32.@)
600 int WINAPI GetCalendarInfoA(LCID lcid, CALID Calendar, CALTYPE CalType,
601 LPSTR lpCalData, int cchData, LPDWORD lpValue)
604 LPWSTR lpCalDataW = NULL;
606 lcid = ConvertDefaultLocale(lcid);
608 if (NLS_IsUnicodeOnlyLcid(lcid))
610 SetLastError(ERROR_INVALID_PARAMETER);
615 !(lpCalDataW = HeapAlloc(GetProcessHeap(), 0, cchData*sizeof(WCHAR))))
618 ret = GetCalendarInfoW(lcid, Calendar, CalType, lpCalDataW, cchData, lpValue);
619 if(ret && lpCalDataW && lpCalData)
620 WideCharToMultiByte(CP_ACP, 0, lpCalDataW, cchData, lpCalData, cchData, NULL, NULL);
621 HeapFree(GetProcessHeap(), 0, lpCalDataW);
626 /*********************************************************************
627 * GetCalendarInfoW (KERNEL32.@)
630 int WINAPI GetCalendarInfoW(LCID Locale, CALID Calendar, CALTYPE CalType,
631 LPWSTR lpCalData, int cchData, LPDWORD lpValue)
633 if (CalType & CAL_NOUSEROVERRIDE)
634 FIXME("flag CAL_NOUSEROVERRIDE used, not fully implemented\n");
635 if (CalType & CAL_USE_CP_ACP)
636 FIXME("flag CAL_USE_CP_ACP used, not fully implemented\n");
638 if (CalType & CAL_RETURN_NUMBER) {
639 if (lpCalData != NULL)
640 WARN("lpCalData not NULL (%p) when it should!\n", lpCalData);
642 WARN("cchData not 0 (%d) when it should!\n", cchData);
645 WARN("lpValue not NULL (%p) when it should!\n", lpValue);
648 /* FIXME: No verification is made yet wrt Locale
649 * for the CALTYPES not requiring GetLocaleInfoA */
650 switch (CalType & ~(CAL_NOUSEROVERRIDE|CAL_RETURN_NUMBER|CAL_USE_CP_ACP)) {
651 case CAL_ICALINTVALUE:
652 FIXME("Unimplemented caltype %d\n", CalType & 0xffff);
655 FIXME("Unimplemented caltype %d\n", CalType & 0xffff);
657 case CAL_IYEAROFFSETRANGE:
658 FIXME("Unimplemented caltype %d\n", CalType & 0xffff);
661 FIXME("Unimplemented caltype %d\n", CalType & 0xffff);
664 return GetLocaleInfoW(Locale, LOCALE_SSHORTDATE, lpCalData, cchData);
666 return GetLocaleInfoW(Locale, LOCALE_SLONGDATE, lpCalData, cchData);
668 return GetLocaleInfoW(Locale, LOCALE_SDAYNAME1, lpCalData, cchData);
670 return GetLocaleInfoW(Locale, LOCALE_SDAYNAME2, lpCalData, cchData);
672 return GetLocaleInfoW(Locale, LOCALE_SDAYNAME3, lpCalData, cchData);
674 return GetLocaleInfoW(Locale, LOCALE_SDAYNAME4, lpCalData, cchData);
676 return GetLocaleInfoW(Locale, LOCALE_SDAYNAME5, lpCalData, cchData);
678 return GetLocaleInfoW(Locale, LOCALE_SDAYNAME6, lpCalData, cchData);
680 return GetLocaleInfoW(Locale, LOCALE_SDAYNAME7, lpCalData, cchData);
681 case CAL_SABBREVDAYNAME1:
682 return GetLocaleInfoW(Locale, LOCALE_SABBREVDAYNAME1, lpCalData, cchData);
683 case CAL_SABBREVDAYNAME2:
684 return GetLocaleInfoW(Locale, LOCALE_SABBREVDAYNAME2, lpCalData, cchData);
685 case CAL_SABBREVDAYNAME3:
686 return GetLocaleInfoW(Locale, LOCALE_SABBREVDAYNAME3, lpCalData, cchData);
687 case CAL_SABBREVDAYNAME4:
688 return GetLocaleInfoW(Locale, LOCALE_SABBREVDAYNAME4, lpCalData, cchData);
689 case CAL_SABBREVDAYNAME5:
690 return GetLocaleInfoW(Locale, LOCALE_SABBREVDAYNAME5, lpCalData, cchData);
691 case CAL_SABBREVDAYNAME6:
692 return GetLocaleInfoW(Locale, LOCALE_SABBREVDAYNAME6, lpCalData, cchData);
693 case CAL_SABBREVDAYNAME7:
694 return GetLocaleInfoW(Locale, LOCALE_SABBREVDAYNAME7, lpCalData, cchData);
695 case CAL_SMONTHNAME1:
696 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME1, lpCalData, cchData);
697 case CAL_SMONTHNAME2:
698 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME2, lpCalData, cchData);
699 case CAL_SMONTHNAME3:
700 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME3, lpCalData, cchData);
701 case CAL_SMONTHNAME4:
702 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME4, lpCalData, cchData);
703 case CAL_SMONTHNAME5:
704 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME5, lpCalData, cchData);
705 case CAL_SMONTHNAME6:
706 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME6, lpCalData, cchData);
707 case CAL_SMONTHNAME7:
708 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME7, lpCalData, cchData);
709 case CAL_SMONTHNAME8:
710 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME8, lpCalData, cchData);
711 case CAL_SMONTHNAME9:
712 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME9, lpCalData, cchData);
713 case CAL_SMONTHNAME10:
714 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME10, lpCalData, cchData);
715 case CAL_SMONTHNAME11:
716 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME11, lpCalData, cchData);
717 case CAL_SMONTHNAME12:
718 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME12, lpCalData, cchData);
719 case CAL_SMONTHNAME13:
720 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME13, lpCalData, cchData);
721 case CAL_SABBREVMONTHNAME1:
722 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME1, lpCalData, cchData);
723 case CAL_SABBREVMONTHNAME2:
724 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME2, lpCalData, cchData);
725 case CAL_SABBREVMONTHNAME3:
726 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME3, lpCalData, cchData);
727 case CAL_SABBREVMONTHNAME4:
728 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME4, lpCalData, cchData);
729 case CAL_SABBREVMONTHNAME5:
730 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME5, lpCalData, cchData);
731 case CAL_SABBREVMONTHNAME6:
732 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME6, lpCalData, cchData);
733 case CAL_SABBREVMONTHNAME7:
734 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME7, lpCalData, cchData);
735 case CAL_SABBREVMONTHNAME8:
736 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME8, lpCalData, cchData);
737 case CAL_SABBREVMONTHNAME9:
738 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME9, lpCalData, cchData);
739 case CAL_SABBREVMONTHNAME10:
740 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME10, lpCalData, cchData);
741 case CAL_SABBREVMONTHNAME11:
742 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME11, lpCalData, cchData);
743 case CAL_SABBREVMONTHNAME12:
744 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME12, lpCalData, cchData);
745 case CAL_SABBREVMONTHNAME13:
746 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME13, lpCalData, cchData);
748 return GetLocaleInfoW(Locale, LOCALE_SYEARMONTH, lpCalData, cchData);
749 case CAL_ITWODIGITYEARMAX:
750 if (lpValue) *lpValue = CALINFO_MAX_YEAR;
752 default: MESSAGE("Unknown caltype %d\n",CalType & 0xffff);
758 /*********************************************************************
759 * SetCalendarInfoA (KERNEL32.@)
762 int WINAPI SetCalendarInfoA(LCID Locale, CALID Calendar, CALTYPE CalType, LPCSTR lpCalData)
764 FIXME("(%08x,%08x,%08x,%s): stub\n",
765 Locale, Calendar, CalType, debugstr_a(lpCalData));
769 /*********************************************************************
770 * SetCalendarInfoW (KERNEL32.@)
774 int WINAPI SetCalendarInfoW(LCID Locale, CALID Calendar, CALTYPE CalType, LPCWSTR lpCalData)
776 FIXME("(%08x,%08x,%08x,%s): stub\n",
777 Locale, Calendar, CalType, debugstr_w(lpCalData));
781 /*********************************************************************
782 * LocalFileTimeToFileTime (KERNEL32.@)
784 BOOL WINAPI LocalFileTimeToFileTime( const FILETIME *localft, LPFILETIME utcft )
787 LARGE_INTEGER local, utc;
789 local.u.LowPart = localft->dwLowDateTime;
790 local.u.HighPart = localft->dwHighDateTime;
791 if (!(status = RtlLocalTimeToSystemTime( &local, &utc )))
793 utcft->dwLowDateTime = utc.u.LowPart;
794 utcft->dwHighDateTime = utc.u.HighPart;
796 else SetLastError( RtlNtStatusToDosError(status) );
801 /*********************************************************************
802 * FileTimeToLocalFileTime (KERNEL32.@)
804 BOOL WINAPI FileTimeToLocalFileTime( const FILETIME *utcft, LPFILETIME localft )
807 LARGE_INTEGER local, utc;
809 utc.u.LowPart = utcft->dwLowDateTime;
810 utc.u.HighPart = utcft->dwHighDateTime;
811 if (!(status = RtlSystemTimeToLocalTime( &utc, &local )))
813 localft->dwLowDateTime = local.u.LowPart;
814 localft->dwHighDateTime = local.u.HighPart;
816 else SetLastError( RtlNtStatusToDosError(status) );
821 /*********************************************************************
822 * FileTimeToSystemTime (KERNEL32.@)
824 BOOL WINAPI FileTimeToSystemTime( const FILETIME *ft, LPSYSTEMTIME syst )
829 t.u.LowPart = ft->dwLowDateTime;
830 t.u.HighPart = ft->dwHighDateTime;
831 RtlTimeToTimeFields(&t, &tf);
833 syst->wYear = tf.Year;
834 syst->wMonth = tf.Month;
836 syst->wHour = tf.Hour;
837 syst->wMinute = tf.Minute;
838 syst->wSecond = tf.Second;
839 syst->wMilliseconds = tf.Milliseconds;
840 syst->wDayOfWeek = tf.Weekday;
844 /*********************************************************************
845 * SystemTimeToFileTime (KERNEL32.@)
847 BOOL WINAPI SystemTimeToFileTime( const SYSTEMTIME *syst, LPFILETIME ft )
852 tf.Year = syst->wYear;
853 tf.Month = syst->wMonth;
855 tf.Hour = syst->wHour;
856 tf.Minute = syst->wMinute;
857 tf.Second = syst->wSecond;
858 tf.Milliseconds = syst->wMilliseconds;
860 if( !RtlTimeFieldsToTime(&tf, &t)) {
861 SetLastError( ERROR_INVALID_PARAMETER);
864 ft->dwLowDateTime = t.u.LowPart;
865 ft->dwHighDateTime = t.u.HighPart;
869 /*********************************************************************
870 * CompareFileTime (KERNEL32.@)
872 * Compare two FILETIME's to each other.
876 * y [I] time to compare to x
879 * -1, 0, or 1 indicating that x is less than, equal to, or greater
880 * than y respectively.
882 INT WINAPI CompareFileTime( const FILETIME *x, const FILETIME *y )
884 if (!x || !y) return -1;
886 if (x->dwHighDateTime > y->dwHighDateTime)
888 if (x->dwHighDateTime < y->dwHighDateTime)
890 if (x->dwLowDateTime > y->dwLowDateTime)
892 if (x->dwLowDateTime < y->dwLowDateTime)
897 /*********************************************************************
898 * GetLocalTime (KERNEL32.@)
900 * Get the current local time.
903 * systime [O] Destination for current time.
908 VOID WINAPI GetLocalTime(LPSYSTEMTIME systime)
911 LARGE_INTEGER ft, ft2;
913 NtQuerySystemTime(&ft);
914 RtlSystemTimeToLocalTime(&ft, &ft2);
915 lft.dwLowDateTime = ft2.u.LowPart;
916 lft.dwHighDateTime = ft2.u.HighPart;
917 FileTimeToSystemTime(&lft, systime);
920 /*********************************************************************
921 * GetSystemTime (KERNEL32.@)
923 * Get the current system time.
926 * systime [O] Destination for current time.
931 VOID WINAPI GetSystemTime(LPSYSTEMTIME systime)
936 NtQuerySystemTime(&t);
937 ft.dwLowDateTime = t.u.LowPart;
938 ft.dwHighDateTime = t.u.HighPart;
939 FileTimeToSystemTime(&ft, systime);
942 /*********************************************************************
943 * GetDaylightFlag (KERNEL32.@)
945 * Specifies if daylight saving time is in operation.
948 * This function is called from the Win98's control applet timedate.cpl.
951 * TRUE if daylight saving time is in operation.
954 BOOL WINAPI GetDaylightFlag(void)
956 TIME_ZONE_INFORMATION tzinfo;
957 return GetTimeZoneInformation( &tzinfo) == TIME_ZONE_ID_DAYLIGHT;
960 /***********************************************************************
961 * DosDateTimeToFileTime (KERNEL32.@)
963 BOOL WINAPI DosDateTimeToFileTime( WORD fatdate, WORD fattime, LPFILETIME ft)
971 newtm.tm_sec = (fattime & 0x1f) * 2;
972 newtm.tm_min = (fattime >> 5) & 0x3f;
973 newtm.tm_hour = (fattime >> 11);
974 newtm.tm_mday = (fatdate & 0x1f);
975 newtm.tm_mon = ((fatdate >> 5) & 0x0f) - 1;
976 newtm.tm_year = (fatdate >> 9) + 80;
978 RtlSecondsSince1970ToTime( timegm(&newtm), (LARGE_INTEGER *)ft );
980 time1 = mktime(&newtm);
981 gtm = gmtime(&time1);
983 RtlSecondsSince1970ToTime( 2*time1-time2, (LARGE_INTEGER *)ft );
989 /***********************************************************************
990 * FileTimeToDosDateTime (KERNEL32.@)
992 BOOL WINAPI FileTimeToDosDateTime( const FILETIME *ft, LPWORD fatdate,
1000 li.u.LowPart = ft->dwLowDateTime;
1001 li.u.HighPart = ft->dwHighDateTime;
1002 RtlTimeToSecondsSince1970( &li, &t );
1004 tm = gmtime( &unixtime );
1006 *fattime = (tm->tm_hour << 11) + (tm->tm_min << 5) + (tm->tm_sec / 2);
1008 *fatdate = ((tm->tm_year - 80) << 9) + ((tm->tm_mon + 1) << 5)