2 * Win32 kernel time functions
4 * Copyright 1995 Martin von Loewis and Cameron Heide
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30 #ifdef HAVE_SYS_TIME_H
31 # include <sys/time.h>
33 #ifdef HAVE_SYS_TIMES_H
34 # include <sys/times.h>
37 #define NONAMELESSUNION
38 #define NONAMELESSSTRUCT
43 #include "kernel_private.h"
44 #include "wine/unicode.h"
45 #include "wine/debug.h"
47 WINE_DEFAULT_DEBUG_CHANNEL(time);
49 /* maximum time adjustment in seconds for SetLocalTime and SetSystemTime */
50 #define SETTIME_MAX_ADJUST 120
51 #define CALINFO_MAX_YEAR 2029
53 #define LL2FILETIME( ll, pft )\
54 (pft)->dwLowDateTime = (UINT)(ll); \
55 (pft)->dwHighDateTime = (UINT)((ll) >> 32);
56 #define FILETIME2LL( pft, ll) \
57 ll = (((LONGLONG)((pft)->dwHighDateTime))<<32) + (pft)-> dwLowDateTime ;
60 static const int MonthLengths[2][12] =
62 { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 },
63 { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }
66 static inline int IsLeapYear(int Year)
68 return Year % 4 == 0 && (Year % 100 != 0 || Year % 400 == 0) ? 1 : 0;
71 /***********************************************************************
72 * TIME_DayLightCompareDate
74 * Compares two dates without looking at the year
78 * -1 if date < compareDate
79 * 0 if date == compareDate
80 * 1 if date > compareDate
81 * -2 if an error occurs
83 static int TIME_DayLightCompareDate(
84 const SYSTEMTIME *date, /* [in] The local time to compare. */
85 const SYSTEMTIME *compareDate) /* [in] The daylight saving begin
88 int limit_day, dayinsecs;
90 if (date->wMonth < compareDate->wMonth)
91 return -1; /* We are in a month before the date limit. */
93 if (date->wMonth > compareDate->wMonth)
94 return 1; /* We are in a month after the date limit. */
96 if (compareDate->wDayOfWeek <= 6)
99 /* compareDate->wDay is interpreted as number of the week in the month
100 * 5 means: the last week in the month */
101 int weekofmonth = compareDate->wDay;
102 /* calculate the day of the first DayOfWeek in the month */
103 First = ( 6 + compareDate->wDayOfWeek - date->wDayOfWeek + date->wDay
105 limit_day = First + 7 * (weekofmonth - 1);
106 /* check needed for the 5th weekday of the month */
107 if(limit_day > MonthLengths[date->wMonth==2 && IsLeapYear(date->wYear)]
113 limit_day = compareDate->wDay;
116 /* convert to seconds */
117 limit_day = ((limit_day * 24 + compareDate->wHour) * 60 +
118 compareDate->wMinute ) * 60;
119 dayinsecs = ((date->wDay * 24 + date->wHour) * 60 +
120 date->wMinute ) * 60 + date->wSecond;
122 return dayinsecs < limit_day ? -1 :
123 dayinsecs > limit_day ? 1 :
124 0; /* date is equal to the date limit. */
127 /***********************************************************************
128 * TIME_CompTimeZoneID
130 * Computes the local time bias for a given time and time zone
133 * TIME_ZONE_ID_INVALID An error occurred
134 * TIME_ZONE_ID_UNKNOWN There are no transition time known
135 * TIME_ZONE_ID_STANDARD Current time is standard time
136 * TIME_ZONE_ID_DAYLIGHT Current time is dayligh saving time
138 static BOOL TIME_CompTimeZoneID (
139 const TIME_ZONE_INFORMATION *pTZinfo, /* [in] The time zone data. */
140 FILETIME *lpFileTime, /* [in] The system or local time. */
141 BOOL islocal /* [in] it is local time */
145 BOOL beforeStandardDate, afterDaylightDate;
146 DWORD retval = TIME_ZONE_ID_INVALID;
147 LONGLONG llTime = 0; /* initialized to prevent gcc complaining */
151 if (pTZinfo->DaylightDate.wMonth != 0)
153 if (pTZinfo->StandardDate.wMonth == 0 ||
154 pTZinfo->StandardDate.wDay<1 ||
155 pTZinfo->StandardDate.wDay>5 ||
156 pTZinfo->DaylightDate.wDay<1 ||
157 pTZinfo->DaylightDate.wDay>5)
159 SetLastError(ERROR_INVALID_PARAMETER);
160 return TIME_ZONE_ID_INVALID;
164 FILETIME2LL( lpFileTime, llTime );
165 llTime -= ( pTZinfo->Bias + pTZinfo->DaylightBias )
166 * (LONGLONG)600000000;
167 LL2FILETIME( llTime, &ftTemp)
168 lpFileTime = &ftTemp;
171 FileTimeToSystemTime(lpFileTime, &SysTime);
173 /* check for daylight saving */
174 ret = TIME_DayLightCompareDate( &SysTime, &pTZinfo->StandardDate);
176 return TIME_ZONE_ID_INVALID;
178 beforeStandardDate = ret < 0;
181 llTime -= ( pTZinfo->StandardBias - pTZinfo->DaylightBias )
182 * (LONGLONG)600000000;
183 LL2FILETIME( llTime, &ftTemp)
184 FileTimeToSystemTime(lpFileTime, &SysTime);
187 ret = TIME_DayLightCompareDate( &SysTime, &pTZinfo->DaylightDate);
189 return TIME_ZONE_ID_INVALID;
191 afterDaylightDate = ret >= 0;
193 retval = TIME_ZONE_ID_STANDARD;
194 if( pTZinfo->DaylightDate.wMonth < pTZinfo->StandardDate.wMonth ) {
195 /* Northern hemisphere */
196 if( beforeStandardDate && afterDaylightDate )
197 retval = TIME_ZONE_ID_DAYLIGHT;
198 } else /* Down south */
199 if( beforeStandardDate || afterDaylightDate )
200 retval = TIME_ZONE_ID_DAYLIGHT;
202 /* No transition date */
203 retval = TIME_ZONE_ID_UNKNOWN;
208 /***********************************************************************
211 * Calculates whether daylight saving is on now.
214 * TIME_ZONE_ID_INVALID An error occurred
215 * TIME_ZONE_ID_UNKNOWN There are no transition time known
216 * TIME_ZONE_ID_STANDARD Current time is standard time
217 * TIME_ZONE_ID_DAYLIGHT Current time is dayligh saving time
219 static DWORD TIME_ZoneID(
220 const TIME_ZONE_INFORMATION *pTzi /* Timezone info */
224 GetSystemTimeAsFileTime( &ftTime);
225 return TIME_CompTimeZoneID( pTzi, &ftTime, FALSE);
228 /***********************************************************************
229 * TIME_GetTimezoneBias
231 * Calculates the local time bias for a given time zone
235 * Returns TRUE when the time zone bias was calculated.
237 static BOOL TIME_GetTimezoneBias(
238 const TIME_ZONE_INFORMATION
239 *pTZinfo, /* [in] The time zone data. */
240 FILETIME *lpFileTime, /* [in] The system or local time. */
241 BOOL islocal, /* [in] it is local time */
242 LONG *pBias /* [out] The calculated bias in minutes */
245 LONG bias = pTZinfo->Bias;
246 DWORD tzid = TIME_CompTimeZoneID( pTZinfo, lpFileTime, islocal);
248 if( tzid == TIME_ZONE_ID_INVALID)
250 if (tzid == TIME_ZONE_ID_DAYLIGHT)
251 bias += pTZinfo->DaylightBias;
252 else if (tzid == TIME_ZONE_ID_STANDARD)
253 bias += pTZinfo->StandardBias;
259 /***********************************************************************
260 * SetLocalTime (KERNEL32.@)
262 * Set the local time using current time zone and daylight
266 * Success: TRUE. The time was set
267 * Failure: FALSE, if the time was invalid or caller does not have
268 * permission to change the time.
270 BOOL WINAPI SetLocalTime(
271 const SYSTEMTIME *systime) /* [in] The desired local time. */
274 LARGE_INTEGER st, st2;
277 if( !SystemTimeToFileTime( systime, &ft ))
279 st.u.LowPart = ft.dwLowDateTime;
280 st.u.HighPart = ft.dwHighDateTime;
281 RtlLocalTimeToSystemTime( &st, &st2 );
283 if ((status = NtSetSystemTime(&st2, NULL)))
284 SetLastError( RtlNtStatusToDosError(status) );
289 /***********************************************************************
290 * GetSystemTimeAdjustment (KERNEL32.@)
292 * Get the period between clock interrupts and the amount the clock
293 * is adjusted each interrupt so as to keep it in sync with an external source.
299 * Only the special case of disabled time adjustments is supported.
301 BOOL WINAPI GetSystemTimeAdjustment(
302 PDWORD lpTimeAdjustment, /* [out] The clock adjustment per interrupt in 100's of nanoseconds. */
303 PDWORD lpTimeIncrement, /* [out] The time between clock interrupts in 100's of nanoseconds. */
304 PBOOL lpTimeAdjustmentDisabled) /* [out] The clock synchronisation has been disabled. */
306 *lpTimeAdjustment = 0;
307 *lpTimeIncrement = 0;
308 *lpTimeAdjustmentDisabled = TRUE;
313 /***********************************************************************
314 * SetSystemTime (KERNEL32.@)
316 * Set the system time in utc.
319 * Success: TRUE. The time was set
320 * Failure: FALSE, if the time was invalid or caller does not have
321 * permission to change the time.
323 BOOL WINAPI SetSystemTime(
324 const SYSTEMTIME *systime) /* [in] The desired system time. */
330 if( !SystemTimeToFileTime( systime, &ft ))
332 t.u.LowPart = ft.dwLowDateTime;
333 t.u.HighPart = ft.dwHighDateTime;
334 if ((status = NtSetSystemTime(&t, NULL)))
335 SetLastError( RtlNtStatusToDosError(status) );
339 /***********************************************************************
340 * SetSystemTimeAdjustment (KERNEL32.@)
342 * Enables or disables the timing adjustments to the system's clock.
348 BOOL WINAPI SetSystemTimeAdjustment(
349 DWORD dwTimeAdjustment,
350 BOOL bTimeAdjustmentDisabled)
352 /* Fake function for now... */
353 FIXME("(%08lx,%d): stub !\n", dwTimeAdjustment, bTimeAdjustmentDisabled);
357 /***********************************************************************
358 * GetTimeZoneInformation (KERNEL32.@)
360 * Get information about the current local time zone.
363 * TIME_ZONE_ID_INVALID An error occurred
364 * TIME_ZONE_ID_UNKNOWN There are no transition time known
365 * TIME_ZONE_ID_STANDARD Current time is standard time
366 * TIME_ZONE_ID_DAYLIGHT Current time is dayligh saving time
368 DWORD WINAPI GetTimeZoneInformation(
369 LPTIME_ZONE_INFORMATION tzinfo) /* [out] Destination for time zone information */
372 if ((status = RtlQueryTimeZoneInformation(tzinfo))) {
373 SetLastError( RtlNtStatusToDosError(status) );
374 return TIME_ZONE_ID_INVALID;
376 return TIME_ZoneID( tzinfo );
379 /***********************************************************************
380 * SetTimeZoneInformation (KERNEL32.@)
382 * Change the settings of the current local time zone.
385 * Success: TRUE. The time zone was updated with the settings from tzinfo
388 BOOL WINAPI SetTimeZoneInformation(
389 const TIME_ZONE_INFORMATION *tzinfo) /* [in] The new time zone. */
392 if ((status = RtlSetTimeZoneInformation(tzinfo)))
393 SetLastError( RtlNtStatusToDosError(status) );
397 /***********************************************************************
398 * SystemTimeToTzSpecificLocalTime (KERNEL32.@)
400 * Convert a utc system time to a local time in a given time zone.
403 * Success: TRUE. lpLocalTime contains the converted time
407 BOOL WINAPI SystemTimeToTzSpecificLocalTime(
408 LPTIME_ZONE_INFORMATION
409 lpTimeZoneInformation, /* [in] The desired time zone. */
410 LPSYSTEMTIME lpUniversalTime, /* [in] The utc time to base local time on. */
411 LPSYSTEMTIME lpLocalTime) /* [out] The local time in the time zone. */
416 TIME_ZONE_INFORMATION tzinfo;
418 if (lpTimeZoneInformation != NULL)
420 memcpy(&tzinfo, lpTimeZoneInformation, sizeof(TIME_ZONE_INFORMATION));
424 if (GetTimeZoneInformation(&tzinfo) == TIME_ZONE_ID_INVALID)
428 if (!SystemTimeToFileTime(lpUniversalTime, &ft))
430 FILETIME2LL( &ft, llTime)
431 if (!TIME_GetTimezoneBias(&tzinfo, &ft, FALSE, &lBias))
433 /* convert minutes to 100-nanoseconds-ticks */
434 llTime -= (LONGLONG)lBias * 600000000;
435 LL2FILETIME( llTime, &ft)
437 return FileTimeToSystemTime(&ft, lpLocalTime);
441 /***********************************************************************
442 * TzSpecificLocalTimeToSystemTime (KERNEL32.@)
444 * Converts a local time to a time in utc.
447 * Success: TRUE. lpUniversalTime contains the converted time
450 BOOL WINAPI TzSpecificLocalTimeToSystemTime(
451 LPTIME_ZONE_INFORMATION lpTimeZoneInformation, /* [in] The desired time zone. */
452 LPSYSTEMTIME lpLocalTime, /* [in] The local time. */
453 LPSYSTEMTIME lpUniversalTime) /* [out] The calculated utc time. */
458 TIME_ZONE_INFORMATION tzinfo;
460 if (lpTimeZoneInformation != NULL)
462 memcpy(&tzinfo, lpTimeZoneInformation, sizeof(TIME_ZONE_INFORMATION));
466 if (GetTimeZoneInformation(&tzinfo) == TIME_ZONE_ID_INVALID)
470 if (!SystemTimeToFileTime(lpLocalTime, &ft))
473 if (!TIME_GetTimezoneBias(&tzinfo, &ft, TRUE, &lBias))
475 /* convert minutes to 100-nanoseconds-ticks */
476 t += (LONGLONG)lBias * 600000000;
478 return FileTimeToSystemTime(&ft, lpUniversalTime);
482 /***********************************************************************
483 * GetSystemTimeAsFileTime (KERNEL32.@)
485 * Get the current time in utc format.
490 VOID WINAPI GetSystemTimeAsFileTime(
491 LPFILETIME time) /* [out] Destination for the current utc time */
494 NtQuerySystemTime( &t );
495 time->dwLowDateTime = t.u.LowPart;
496 time->dwHighDateTime = t.u.HighPart;
500 /*********************************************************************
501 * TIME_ClockTimeToFileTime (olorin@fandra.org, 20-Sep-1998)
503 * Used by GetProcessTimes to convert clock_t into FILETIME.
505 * Differences to UnixTimeToFileTime:
506 * 1) Divided by CLK_TCK
507 * 2) Time is relative. There is no 'starting date', so there is
508 * no need for offset correction, like in UnixTimeToFileTime
510 static void TIME_ClockTimeToFileTime(clock_t unix_time, LPFILETIME filetime)
512 ULONGLONG secs = RtlEnlargedUnsignedMultiply( unix_time, 10000000 );
513 secs = RtlExtendedLargeIntegerDivide( secs, CLK_TCK, NULL );
514 filetime->dwLowDateTime = (DWORD)secs;
515 filetime->dwHighDateTime = (DWORD)(secs >> 32);
518 /*********************************************************************
519 * GetProcessTimes (KERNEL32.@)
521 * Get the user and kernel execution times of a process,
522 * along with the creation and exit times if known.
529 * Would be nice to subtract the cpu time used by Wine at startup.
530 * Also, there is a need to separate times used by different applications.
533 * lpCreationTime and lpExitTime are not initialised in the Wine implementation.
535 BOOL WINAPI GetProcessTimes(
536 HANDLE hprocess, /* [in] The process to be queried (obtained from PROCESS_QUERY_INFORMATION). */
537 LPFILETIME lpCreationTime, /* [out] The creation time of the process. */
538 LPFILETIME lpExitTime, /* [out] The exit time of the process if exited. */
539 LPFILETIME lpKernelTime, /* [out] The time spent in kernel routines in 100's of nanoseconds. */
540 LPFILETIME lpUserTime) /* [out] The time spent in user routines in 100's of nanoseconds. */
545 TIME_ClockTimeToFileTime(tms.tms_utime,lpUserTime);
546 TIME_ClockTimeToFileTime(tms.tms_stime,lpKernelTime);
550 /*********************************************************************
551 * GetCalendarInfoA (KERNEL32.@)
554 int WINAPI GetCalendarInfoA(LCID lcid, CALID Calendar, CALTYPE CalType,
555 LPSTR lpCalData, int cchData, LPDWORD lpValue)
558 LPWSTR lpCalDataW = NULL;
560 FIXME("(%08lx,%08lx,%08lx,%p,%d,%p): quarter-stub\n",
561 lcid, Calendar, CalType, lpCalData, cchData, lpValue);
563 lcid = ConvertDefaultLocale(lcid);
565 if (NLS_IsUnicodeOnlyLcid(lcid))
567 SetLastError(ERROR_INVALID_PARAMETER);
572 !(lpCalDataW = HeapAlloc(GetProcessHeap(), 0, cchData*sizeof(WCHAR))))
575 ret = GetCalendarInfoW(lcid, Calendar, CalType, lpCalDataW, cchData, lpValue);
576 if(ret && lpCalDataW && lpCalData)
577 WideCharToMultiByte(CP_ACP, 0, lpCalDataW, cchData, lpCalData, cchData, NULL, NULL);
578 HeapFree(GetProcessHeap(), 0, lpCalDataW);
583 /*********************************************************************
584 * GetCalendarInfoW (KERNEL32.@)
586 * See GetCalendarInfoA.
588 int WINAPI GetCalendarInfoW(LCID Locale, CALID Calendar, CALTYPE CalType,
589 LPWSTR lpCalData, int cchData, LPDWORD lpValue)
591 FIXME("(%08lx,%08lx,%08lx,%p,%d,%p): quarter-stub\n",
592 Locale, Calendar, CalType, lpCalData, cchData, lpValue);
594 if (CalType & CAL_NOUSEROVERRIDE)
595 FIXME("flag CAL_NOUSEROVERRIDE used, not fully implemented\n");
596 if (CalType & CAL_USE_CP_ACP)
597 FIXME("flag CAL_USE_CP_ACP used, not fully implemented\n");
599 if (CalType & CAL_RETURN_NUMBER) {
600 if (lpCalData != NULL)
601 WARN("lpCalData not NULL (%p) when it should!\n", lpCalData);
603 WARN("cchData not 0 (%d) when it should!\n", cchData);
606 WARN("lpValue not NULL (%p) when it should!\n", lpValue);
609 /* FIXME: No verification is made yet wrt Locale
610 * for the CALTYPES not requiring GetLocaleInfoA */
611 switch (CalType & ~(CAL_NOUSEROVERRIDE|CAL_RETURN_NUMBER|CAL_USE_CP_ACP)) {
612 case CAL_ICALINTVALUE:
613 FIXME("Unimplemented caltype %ld\n", CalType & 0xffff);
616 FIXME("Unimplemented caltype %ld\n", CalType & 0xffff);
618 case CAL_IYEAROFFSETRANGE:
619 FIXME("Unimplemented caltype %ld\n", CalType & 0xffff);
622 FIXME("Unimplemented caltype %ld\n", CalType & 0xffff);
625 return GetLocaleInfoW(Locale, LOCALE_SSHORTDATE, lpCalData, cchData);
627 return GetLocaleInfoW(Locale, LOCALE_SLONGDATE, lpCalData, cchData);
629 return GetLocaleInfoW(Locale, LOCALE_SDAYNAME1, lpCalData, cchData);
631 return GetLocaleInfoW(Locale, LOCALE_SDAYNAME2, lpCalData, cchData);
633 return GetLocaleInfoW(Locale, LOCALE_SDAYNAME3, lpCalData, cchData);
635 return GetLocaleInfoW(Locale, LOCALE_SDAYNAME4, lpCalData, cchData);
637 return GetLocaleInfoW(Locale, LOCALE_SDAYNAME5, lpCalData, cchData);
639 return GetLocaleInfoW(Locale, LOCALE_SDAYNAME6, lpCalData, cchData);
641 return GetLocaleInfoW(Locale, LOCALE_SDAYNAME7, lpCalData, cchData);
642 case CAL_SABBREVDAYNAME1:
643 return GetLocaleInfoW(Locale, LOCALE_SABBREVDAYNAME1, lpCalData, cchData);
644 case CAL_SABBREVDAYNAME2:
645 return GetLocaleInfoW(Locale, LOCALE_SABBREVDAYNAME2, lpCalData, cchData);
646 case CAL_SABBREVDAYNAME3:
647 return GetLocaleInfoW(Locale, LOCALE_SABBREVDAYNAME3, lpCalData, cchData);
648 case CAL_SABBREVDAYNAME4:
649 return GetLocaleInfoW(Locale, LOCALE_SABBREVDAYNAME4, lpCalData, cchData);
650 case CAL_SABBREVDAYNAME5:
651 return GetLocaleInfoW(Locale, LOCALE_SABBREVDAYNAME5, lpCalData, cchData);
652 case CAL_SABBREVDAYNAME6:
653 return GetLocaleInfoW(Locale, LOCALE_SABBREVDAYNAME6, lpCalData, cchData);
654 case CAL_SABBREVDAYNAME7:
655 return GetLocaleInfoW(Locale, LOCALE_SABBREVDAYNAME7, lpCalData, cchData);
656 case CAL_SMONTHNAME1:
657 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME1, lpCalData, cchData);
658 case CAL_SMONTHNAME2:
659 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME2, lpCalData, cchData);
660 case CAL_SMONTHNAME3:
661 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME3, lpCalData, cchData);
662 case CAL_SMONTHNAME4:
663 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME4, lpCalData, cchData);
664 case CAL_SMONTHNAME5:
665 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME5, lpCalData, cchData);
666 case CAL_SMONTHNAME6:
667 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME6, lpCalData, cchData);
668 case CAL_SMONTHNAME7:
669 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME7, lpCalData, cchData);
670 case CAL_SMONTHNAME8:
671 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME8, lpCalData, cchData);
672 case CAL_SMONTHNAME9:
673 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME9, lpCalData, cchData);
674 case CAL_SMONTHNAME10:
675 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME10, lpCalData, cchData);
676 case CAL_SMONTHNAME11:
677 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME11, lpCalData, cchData);
678 case CAL_SMONTHNAME12:
679 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME12, lpCalData, cchData);
680 case CAL_SMONTHNAME13:
681 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME13, lpCalData, cchData);
682 case CAL_SABBREVMONTHNAME1:
683 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME1, lpCalData, cchData);
684 case CAL_SABBREVMONTHNAME2:
685 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME2, lpCalData, cchData);
686 case CAL_SABBREVMONTHNAME3:
687 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME3, lpCalData, cchData);
688 case CAL_SABBREVMONTHNAME4:
689 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME4, lpCalData, cchData);
690 case CAL_SABBREVMONTHNAME5:
691 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME5, lpCalData, cchData);
692 case CAL_SABBREVMONTHNAME6:
693 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME6, lpCalData, cchData);
694 case CAL_SABBREVMONTHNAME7:
695 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME7, lpCalData, cchData);
696 case CAL_SABBREVMONTHNAME8:
697 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME8, lpCalData, cchData);
698 case CAL_SABBREVMONTHNAME9:
699 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME9, lpCalData, cchData);
700 case CAL_SABBREVMONTHNAME10:
701 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME10, lpCalData, cchData);
702 case CAL_SABBREVMONTHNAME11:
703 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME11, lpCalData, cchData);
704 case CAL_SABBREVMONTHNAME12:
705 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME12, lpCalData, cchData);
706 case CAL_SABBREVMONTHNAME13:
707 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME13, lpCalData, cchData);
709 return GetLocaleInfoW(Locale, LOCALE_SYEARMONTH, lpCalData, cchData);
710 case CAL_ITWODIGITYEARMAX:
711 if (lpValue) *lpValue = CALINFO_MAX_YEAR;
713 default: MESSAGE("Unknown caltype %ld\n",CalType & 0xffff);
719 /*********************************************************************
720 * SetCalendarInfoA (KERNEL32.@)
723 int WINAPI SetCalendarInfoA(LCID Locale, CALID Calendar, CALTYPE CalType, LPCSTR lpCalData)
725 FIXME("(%08lx,%08lx,%08lx,%s): stub\n",
726 Locale, Calendar, CalType, debugstr_a(lpCalData));
730 /*********************************************************************
731 * SetCalendarInfoW (KERNEL32.@)
733 * See SetCalendarInfoA.
735 int WINAPI SetCalendarInfoW(LCID Locale, CALID Calendar, CALTYPE CalType, LPCWSTR lpCalData)
737 FIXME("(%08lx,%08lx,%08lx,%s): stub\n",
738 Locale, Calendar, CalType, debugstr_w(lpCalData));
742 /*********************************************************************
743 * LocalFileTimeToFileTime (KERNEL32.@)
745 BOOL WINAPI LocalFileTimeToFileTime( const FILETIME *localft, LPFILETIME utcft )
748 LARGE_INTEGER local, utc;
750 local.u.LowPart = localft->dwLowDateTime;
751 local.u.HighPart = localft->dwHighDateTime;
752 if (!(status = RtlLocalTimeToSystemTime( &local, &utc )))
754 utcft->dwLowDateTime = utc.u.LowPart;
755 utcft->dwHighDateTime = utc.u.HighPart;
757 else SetLastError( RtlNtStatusToDosError(status) );
762 /*********************************************************************
763 * FileTimeToLocalFileTime (KERNEL32.@)
765 BOOL WINAPI FileTimeToLocalFileTime( const FILETIME *utcft, LPFILETIME localft )
768 LARGE_INTEGER local, utc;
770 utc.u.LowPart = utcft->dwLowDateTime;
771 utc.u.HighPart = utcft->dwHighDateTime;
772 if (!(status = RtlSystemTimeToLocalTime( &utc, &local )))
774 localft->dwLowDateTime = local.u.LowPart;
775 localft->dwHighDateTime = local.u.HighPart;
777 else SetLastError( RtlNtStatusToDosError(status) );
782 /*********************************************************************
783 * FileTimeToSystemTime (KERNEL32.@)
785 BOOL WINAPI FileTimeToSystemTime( const FILETIME *ft, LPSYSTEMTIME syst )
790 t.u.LowPart = ft->dwLowDateTime;
791 t.u.HighPart = ft->dwHighDateTime;
792 RtlTimeToTimeFields(&t, &tf);
794 syst->wYear = tf.Year;
795 syst->wMonth = tf.Month;
797 syst->wHour = tf.Hour;
798 syst->wMinute = tf.Minute;
799 syst->wSecond = tf.Second;
800 syst->wMilliseconds = tf.Milliseconds;
801 syst->wDayOfWeek = tf.Weekday;
805 /*********************************************************************
806 * SystemTimeToFileTime (KERNEL32.@)
808 BOOL WINAPI SystemTimeToFileTime( const SYSTEMTIME *syst, LPFILETIME ft )
813 tf.Year = syst->wYear;
814 tf.Month = syst->wMonth;
816 tf.Hour = syst->wHour;
817 tf.Minute = syst->wMinute;
818 tf.Second = syst->wSecond;
819 tf.Milliseconds = syst->wMilliseconds;
821 if( !RtlTimeFieldsToTime(&tf, &t)) {
822 SetLastError( ERROR_INVALID_PARAMETER);
825 ft->dwLowDateTime = t.u.LowPart;
826 ft->dwHighDateTime = t.u.HighPart;
830 /*********************************************************************
831 * CompareFileTime (KERNEL32.@)
833 * Compare two FILETIME's to each other.
837 * y [I] time to compare to x
840 * -1, 0, or 1 indicating that x is less than, equal to, or greater
841 * than y respectively.
843 INT WINAPI CompareFileTime( const FILETIME *x, const FILETIME *y )
845 if (!x || !y) return -1;
847 if (x->dwHighDateTime > y->dwHighDateTime)
849 if (x->dwHighDateTime < y->dwHighDateTime)
851 if (x->dwLowDateTime > y->dwLowDateTime)
853 if (x->dwLowDateTime < y->dwLowDateTime)
858 /*********************************************************************
859 * GetLocalTime (KERNEL32.@)
861 * Get the current local time.
866 VOID WINAPI GetLocalTime(LPSYSTEMTIME systime) /* [O] Destination for current time */
869 LARGE_INTEGER ft, ft2;
871 NtQuerySystemTime(&ft);
872 RtlSystemTimeToLocalTime(&ft, &ft2);
873 lft.dwLowDateTime = ft2.u.LowPart;
874 lft.dwHighDateTime = ft2.u.HighPart;
875 FileTimeToSystemTime(&lft, systime);
878 /*********************************************************************
879 * GetSystemTime (KERNEL32.@)
881 * Get the current system time.
886 VOID WINAPI GetSystemTime(LPSYSTEMTIME systime) /* [O] Destination for current time */
891 NtQuerySystemTime(&t);
892 ft.dwLowDateTime = t.u.LowPart;
893 ft.dwHighDateTime = t.u.HighPart;
894 FileTimeToSystemTime(&ft, systime);
897 /*********************************************************************
898 * GetDaylightFlag (KERNEL32.@)
900 * returns TRUE if daylight saving time is in operation
902 * Note: this function is called from the Win98's control applet
905 BOOL WINAPI GetDaylightFlag(void)
907 TIME_ZONE_INFORMATION tzinfo;
908 return GetTimeZoneInformation( &tzinfo) == TIME_ZONE_ID_DAYLIGHT;
911 /***********************************************************************
912 * DosDateTimeToFileTime (KERNEL32.@)
914 BOOL WINAPI DosDateTimeToFileTime( WORD fatdate, WORD fattime, LPFILETIME ft)
922 newtm.tm_sec = (fattime & 0x1f) * 2;
923 newtm.tm_min = (fattime >> 5) & 0x3f;
924 newtm.tm_hour = (fattime >> 11);
925 newtm.tm_mday = (fatdate & 0x1f);
926 newtm.tm_mon = ((fatdate >> 5) & 0x0f) - 1;
927 newtm.tm_year = (fatdate >> 9) + 80;
929 RtlSecondsSince1970ToTime( timegm(&newtm), (LARGE_INTEGER *)ft );
931 time1 = mktime(&newtm);
932 gtm = gmtime(&time1);
934 RtlSecondsSince1970ToTime( 2*time1-time2, (LARGE_INTEGER *)ft );
940 /***********************************************************************
941 * FileTimeToDosDateTime (KERNEL32.@)
943 BOOL WINAPI FileTimeToDosDateTime( const FILETIME *ft, LPWORD fatdate,
951 li.u.LowPart = ft->dwLowDateTime;
952 li.u.HighPart = ft->dwHighDateTime;
953 RtlTimeToSecondsSince1970( &li, &t );
955 tm = gmtime( &unixtime );
957 *fattime = (tm->tm_hour << 11) + (tm->tm_min << 5) + (tm->tm_sec / 2);
959 *fatdate = ((tm->tm_year - 80) << 9) + ((tm->tm_mon + 1) << 5)