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 occures
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 calulated 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 interupt in 100's of nanoseconds. */
303 PDWORD lpTimeIncrement, /* [out] The time between clock interupts in 100's of nanoseconds. */
304 PBOOL lpTimeAdjustmentDisabled) /* [out] The clock synchonisation 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 kernal 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);
579 HeapFree(GetProcessHeap(), 0, lpCalDataW);
584 /*********************************************************************
585 * GetCalendarInfoW (KERNEL32.@)
587 * See GetCalendarInfoA.
589 int WINAPI GetCalendarInfoW(LCID Locale, CALID Calendar, CALTYPE CalType,
590 LPWSTR lpCalData, int cchData, LPDWORD lpValue)
592 FIXME("(%08lx,%08lx,%08lx,%p,%d,%p): quarter-stub\n",
593 Locale, Calendar, CalType, lpCalData, cchData, lpValue);
595 if (CalType & CAL_NOUSEROVERRIDE)
596 FIXME("flag CAL_NOUSEROVERRIDE used, not fully implemented\n");
597 if (CalType & CAL_USE_CP_ACP)
598 FIXME("flag CAL_USE_CP_ACP used, not fully implemented\n");
600 if (CalType & CAL_RETURN_NUMBER) {
601 if (lpCalData != NULL)
602 WARN("lpCalData not NULL (%p) when it should!\n", lpCalData);
604 WARN("cchData not 0 (%d) when it should!\n", cchData);
607 WARN("lpValue not NULL (%p) when it should!\n", lpValue);
610 /* FIXME: No verification is made yet wrt Locale
611 * for the CALTYPES not requiring GetLocaleInfoA */
612 switch (CalType & ~(CAL_NOUSEROVERRIDE|CAL_RETURN_NUMBER|CAL_USE_CP_ACP)) {
613 case CAL_ICALINTVALUE:
614 FIXME("Unimplemented caltype %ld\n", CalType & 0xffff);
617 FIXME("Unimplemented caltype %ld\n", CalType & 0xffff);
619 case CAL_IYEAROFFSETRANGE:
620 FIXME("Unimplemented caltype %ld\n", CalType & 0xffff);
623 FIXME("Unimplemented caltype %ld\n", CalType & 0xffff);
626 return GetLocaleInfoW(Locale, LOCALE_SSHORTDATE, lpCalData, cchData);
628 return GetLocaleInfoW(Locale, LOCALE_SLONGDATE, lpCalData, cchData);
630 return GetLocaleInfoW(Locale, LOCALE_SDAYNAME1, lpCalData, cchData);
632 return GetLocaleInfoW(Locale, LOCALE_SDAYNAME2, lpCalData, cchData);
634 return GetLocaleInfoW(Locale, LOCALE_SDAYNAME3, lpCalData, cchData);
636 return GetLocaleInfoW(Locale, LOCALE_SDAYNAME4, lpCalData, cchData);
638 return GetLocaleInfoW(Locale, LOCALE_SDAYNAME5, lpCalData, cchData);
640 return GetLocaleInfoW(Locale, LOCALE_SDAYNAME6, lpCalData, cchData);
642 return GetLocaleInfoW(Locale, LOCALE_SDAYNAME7, lpCalData, cchData);
643 case CAL_SABBREVDAYNAME1:
644 return GetLocaleInfoW(Locale, LOCALE_SABBREVDAYNAME1, lpCalData, cchData);
645 case CAL_SABBREVDAYNAME2:
646 return GetLocaleInfoW(Locale, LOCALE_SABBREVDAYNAME2, lpCalData, cchData);
647 case CAL_SABBREVDAYNAME3:
648 return GetLocaleInfoW(Locale, LOCALE_SABBREVDAYNAME3, lpCalData, cchData);
649 case CAL_SABBREVDAYNAME4:
650 return GetLocaleInfoW(Locale, LOCALE_SABBREVDAYNAME4, lpCalData, cchData);
651 case CAL_SABBREVDAYNAME5:
652 return GetLocaleInfoW(Locale, LOCALE_SABBREVDAYNAME5, lpCalData, cchData);
653 case CAL_SABBREVDAYNAME6:
654 return GetLocaleInfoW(Locale, LOCALE_SABBREVDAYNAME6, lpCalData, cchData);
655 case CAL_SABBREVDAYNAME7:
656 return GetLocaleInfoW(Locale, LOCALE_SABBREVDAYNAME7, lpCalData, cchData);
657 case CAL_SMONTHNAME1:
658 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME1, lpCalData, cchData);
659 case CAL_SMONTHNAME2:
660 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME2, lpCalData, cchData);
661 case CAL_SMONTHNAME3:
662 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME3, lpCalData, cchData);
663 case CAL_SMONTHNAME4:
664 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME4, lpCalData, cchData);
665 case CAL_SMONTHNAME5:
666 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME5, lpCalData, cchData);
667 case CAL_SMONTHNAME6:
668 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME6, lpCalData, cchData);
669 case CAL_SMONTHNAME7:
670 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME7, lpCalData, cchData);
671 case CAL_SMONTHNAME8:
672 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME8, lpCalData, cchData);
673 case CAL_SMONTHNAME9:
674 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME9, lpCalData, cchData);
675 case CAL_SMONTHNAME10:
676 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME10, lpCalData, cchData);
677 case CAL_SMONTHNAME11:
678 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME11, lpCalData, cchData);
679 case CAL_SMONTHNAME12:
680 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME12, lpCalData, cchData);
681 case CAL_SMONTHNAME13:
682 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME13, lpCalData, cchData);
683 case CAL_SABBREVMONTHNAME1:
684 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME1, lpCalData, cchData);
685 case CAL_SABBREVMONTHNAME2:
686 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME2, lpCalData, cchData);
687 case CAL_SABBREVMONTHNAME3:
688 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME3, lpCalData, cchData);
689 case CAL_SABBREVMONTHNAME4:
690 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME4, lpCalData, cchData);
691 case CAL_SABBREVMONTHNAME5:
692 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME5, lpCalData, cchData);
693 case CAL_SABBREVMONTHNAME6:
694 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME6, lpCalData, cchData);
695 case CAL_SABBREVMONTHNAME7:
696 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME7, lpCalData, cchData);
697 case CAL_SABBREVMONTHNAME8:
698 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME8, lpCalData, cchData);
699 case CAL_SABBREVMONTHNAME9:
700 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME9, lpCalData, cchData);
701 case CAL_SABBREVMONTHNAME10:
702 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME10, lpCalData, cchData);
703 case CAL_SABBREVMONTHNAME11:
704 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME11, lpCalData, cchData);
705 case CAL_SABBREVMONTHNAME12:
706 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME12, lpCalData, cchData);
707 case CAL_SABBREVMONTHNAME13:
708 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME13, lpCalData, cchData);
710 return GetLocaleInfoW(Locale, LOCALE_SYEARMONTH, lpCalData, cchData);
711 case CAL_ITWODIGITYEARMAX:
712 if (lpValue) *lpValue = CALINFO_MAX_YEAR;
714 default: MESSAGE("Unknown caltype %ld\n",CalType & 0xffff);
720 /*********************************************************************
721 * SetCalendarInfoA (KERNEL32.@)
724 int WINAPI SetCalendarInfoA(LCID Locale, CALID Calendar, CALTYPE CalType, LPCSTR lpCalData)
726 FIXME("(%08lx,%08lx,%08lx,%s): stub\n",
727 Locale, Calendar, CalType, debugstr_a(lpCalData));
731 /*********************************************************************
732 * SetCalendarInfoW (KERNEL32.@)
734 * See SetCalendarInfoA.
736 int WINAPI SetCalendarInfoW(LCID Locale, CALID Calendar, CALTYPE CalType, LPCWSTR lpCalData)
738 FIXME("(%08lx,%08lx,%08lx,%s): stub\n",
739 Locale, Calendar, CalType, debugstr_w(lpCalData));
743 /*********************************************************************
744 * LocalFileTimeToFileTime (KERNEL32.@)
746 BOOL WINAPI LocalFileTimeToFileTime( const FILETIME *localft, LPFILETIME utcft )
749 LARGE_INTEGER local, utc;
751 local.u.LowPart = localft->dwLowDateTime;
752 local.u.HighPart = localft->dwHighDateTime;
753 if (!(status = RtlLocalTimeToSystemTime( &local, &utc )))
755 utcft->dwLowDateTime = utc.u.LowPart;
756 utcft->dwHighDateTime = utc.u.HighPart;
758 else SetLastError( RtlNtStatusToDosError(status) );
763 /*********************************************************************
764 * FileTimeToLocalFileTime (KERNEL32.@)
766 BOOL WINAPI FileTimeToLocalFileTime( const FILETIME *utcft, LPFILETIME localft )
769 LARGE_INTEGER local, utc;
771 utc.u.LowPart = utcft->dwLowDateTime;
772 utc.u.HighPart = utcft->dwHighDateTime;
773 if (!(status = RtlSystemTimeToLocalTime( &utc, &local )))
775 localft->dwLowDateTime = local.u.LowPart;
776 localft->dwHighDateTime = local.u.HighPart;
778 else SetLastError( RtlNtStatusToDosError(status) );
783 /*********************************************************************
784 * FileTimeToSystemTime (KERNEL32.@)
786 BOOL WINAPI FileTimeToSystemTime( const FILETIME *ft, LPSYSTEMTIME syst )
791 t.u.LowPart = ft->dwLowDateTime;
792 t.u.HighPart = ft->dwHighDateTime;
793 RtlTimeToTimeFields(&t, &tf);
795 syst->wYear = tf.Year;
796 syst->wMonth = tf.Month;
798 syst->wHour = tf.Hour;
799 syst->wMinute = tf.Minute;
800 syst->wSecond = tf.Second;
801 syst->wMilliseconds = tf.Milliseconds;
802 syst->wDayOfWeek = tf.Weekday;
806 /*********************************************************************
807 * SystemTimeToFileTime (KERNEL32.@)
809 BOOL WINAPI SystemTimeToFileTime( const SYSTEMTIME *syst, LPFILETIME ft )
814 tf.Year = syst->wYear;
815 tf.Month = syst->wMonth;
817 tf.Hour = syst->wHour;
818 tf.Minute = syst->wMinute;
819 tf.Second = syst->wSecond;
820 tf.Milliseconds = syst->wMilliseconds;
822 if( !RtlTimeFieldsToTime(&tf, &t)) {
823 SetLastError( ERROR_INVALID_PARAMETER);
826 ft->dwLowDateTime = t.u.LowPart;
827 ft->dwHighDateTime = t.u.HighPart;
831 /*********************************************************************
832 * CompareFileTime (KERNEL32.@)
834 * Compare two FILETIME's to each other.
838 * y [I] time to compare to x
841 * -1, 0, or 1 indicating that x is less than, equal to, or greater
842 * than y respectively.
844 INT WINAPI CompareFileTime( const FILETIME *x, const FILETIME *y )
846 if (!x || !y) return -1;
848 if (x->dwHighDateTime > y->dwHighDateTime)
850 if (x->dwHighDateTime < y->dwHighDateTime)
852 if (x->dwLowDateTime > y->dwLowDateTime)
854 if (x->dwLowDateTime < y->dwLowDateTime)
859 /*********************************************************************
860 * GetLocalTime (KERNEL32.@)
862 * Get the current local time.
867 VOID WINAPI GetLocalTime(LPSYSTEMTIME systime) /* [O] Destination for current time */
870 LARGE_INTEGER ft, ft2;
872 NtQuerySystemTime(&ft);
873 RtlSystemTimeToLocalTime(&ft, &ft2);
874 lft.dwLowDateTime = ft2.u.LowPart;
875 lft.dwHighDateTime = ft2.u.HighPart;
876 FileTimeToSystemTime(&lft, systime);
879 /*********************************************************************
880 * GetSystemTime (KERNEL32.@)
882 * Get the current system time.
887 VOID WINAPI GetSystemTime(LPSYSTEMTIME systime) /* [O] Destination for current time */
892 NtQuerySystemTime(&t);
893 ft.dwLowDateTime = t.u.LowPart;
894 ft.dwHighDateTime = t.u.HighPart;
895 FileTimeToSystemTime(&ft, systime);
898 /*********************************************************************
899 * GetDaylightFlag (KERNEL32.@)
901 * returns TRUE if daylight saving time is in operation
903 * Note: this function is called from the Win98's control applet
906 BOOL WINAPI GetDaylightFlag(void)
908 TIME_ZONE_INFORMATION tzinfo;
909 return GetTimeZoneInformation( &tzinfo) == TIME_ZONE_ID_DAYLIGHT;
912 /***********************************************************************
913 * DosDateTimeToFileTime (KERNEL32.@)
915 BOOL WINAPI DosDateTimeToFileTime( WORD fatdate, WORD fattime, LPFILETIME ft)
923 newtm.tm_sec = (fattime & 0x1f) * 2;
924 newtm.tm_min = (fattime >> 5) & 0x3f;
925 newtm.tm_hour = (fattime >> 11);
926 newtm.tm_mday = (fatdate & 0x1f);
927 newtm.tm_mon = ((fatdate >> 5) & 0x0f) - 1;
928 newtm.tm_year = (fatdate >> 9) + 80;
930 RtlSecondsSince1970ToTime( timegm(&newtm), (LARGE_INTEGER *)ft );
932 time1 = mktime(&newtm);
933 gtm = gmtime(&time1);
935 RtlSecondsSince1970ToTime( 2*time1-time2, (LARGE_INTEGER *)ft );
941 /***********************************************************************
942 * FileTimeToDosDateTime (KERNEL32.@)
944 BOOL WINAPI FileTimeToDosDateTime( const FILETIME *ft, LPWORD fatdate,
952 li.u.LowPart = ft->dwLowDateTime;
953 li.u.HighPart = ft->dwHighDateTime;
954 RtlTimeToSecondsSince1970( &li, &t );
956 tm = gmtime( &unixtime );
958 *fattime = (tm->tm_hour << 11) + (tm->tm_min << 5) + (tm->tm_sec / 2);
960 *fatdate = ((tm->tm_year - 80) << 9) + ((tm->tm_mon + 1) << 5)