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
46 #include "kernel_private.h"
47 #include "wine/unicode.h"
48 #include "wine/debug.h"
50 WINE_DEFAULT_DEBUG_CHANNEL(time);
52 /* maximum time adjustment in seconds for SetLocalTime and SetSystemTime */
53 #define SETTIME_MAX_ADJUST 120
54 #define CALINFO_MAX_YEAR 2029
56 #define LL2FILETIME( ll, pft )\
57 (pft)->dwLowDateTime = (UINT)(ll); \
58 (pft)->dwHighDateTime = (UINT)((ll) >> 32);
59 #define FILETIME2LL( pft, ll) \
60 ll = (((LONGLONG)((pft)->dwHighDateTime))<<32) + (pft)-> dwLowDateTime ;
62 /***********************************************************************
63 * SetLocalTime (KERNEL32.@)
65 * Set the local time using current time zone and daylight
69 * Success: TRUE. The time was set
70 * Failure: FALSE, if the time was invalid or caller does not have
71 * permission to change the time.
73 BOOL WINAPI SetLocalTime(
74 const SYSTEMTIME *systime) /* [in] The desired local time. */
77 LARGE_INTEGER st, st2;
80 SystemTimeToFileTime( systime, &ft );
81 st.u.LowPart = ft.dwLowDateTime;
82 st.u.HighPart = ft.dwHighDateTime;
83 RtlLocalTimeToSystemTime( &st, &st2 );
85 if ((status = NtSetSystemTime(&st2, NULL)))
86 SetLastError( RtlNtStatusToDosError(status) );
91 /***********************************************************************
92 * GetSystemTimeAdjustment (KERNEL32.@)
94 * Get the period between clock interrupts and the amount the clock
95 * is adjusted each interrupt so as to keep it in sync with an external source.
101 * Only the special case of disabled time adjustments is supported.
103 BOOL WINAPI GetSystemTimeAdjustment(
104 PDWORD lpTimeAdjustment, /* [out] The clock adjustment per interupt in 100's of nanoseconds. */
105 PDWORD lpTimeIncrement, /* [out] The time between clock interupts in 100's of nanoseconds. */
106 PBOOL lpTimeAdjustmentDisabled) /* [out] The clock synchonisation has been disabled. */
108 *lpTimeAdjustment = 0;
109 *lpTimeIncrement = 0;
110 *lpTimeAdjustmentDisabled = TRUE;
115 /***********************************************************************
116 * SetSystemTime (KERNEL32.@)
118 * Set the system time in utc.
121 * Success: TRUE. The time was set
122 * Failure: FALSE, if the time was invalid or caller does not have
123 * permission to change the time.
125 BOOL WINAPI SetSystemTime(
126 const SYSTEMTIME *systime) /* [in] The desired system time. */
132 SystemTimeToFileTime( systime, &ft );
133 t.u.LowPart = ft.dwLowDateTime;
134 t.u.HighPart = ft.dwHighDateTime;
135 if ((status = NtSetSystemTime(&t, NULL)))
136 SetLastError( RtlNtStatusToDosError(status) );
140 /***********************************************************************
141 * SetSystemTimeAdjustment (KERNEL32.@)
143 * Enables or disables the timing adjustments to the system's clock.
149 BOOL WINAPI SetSystemTimeAdjustment(
150 DWORD dwTimeAdjustment,
151 BOOL bTimeAdjustmentDisabled)
153 /* Fake function for now... */
154 FIXME("(%08lx,%d): stub !\n", dwTimeAdjustment, bTimeAdjustmentDisabled);
159 /***********************************************************************
160 * GetTimeZoneInformation (KERNEL32.@)
162 * Get information about the current local time zone.
165 * Success: TIME_ZONE_ID_STANDARD. tzinfo contains the time zone info.
166 * Failure: TIME_ZONE_ID_INVALID.
167 * FIXME: return TIME_ZONE_ID_DAYLIGHT when daylight saving is on.
169 DWORD WINAPI GetTimeZoneInformation(
170 LPTIME_ZONE_INFORMATION tzinfo) /* [out] Destination for time zone information */
173 if ((status = RtlQueryTimeZoneInformation(tzinfo)))
174 SetLastError( RtlNtStatusToDosError(status) );
175 return TIME_ZONE_ID_STANDARD;
179 /***********************************************************************
180 * SetTimeZoneInformation (KERNEL32.@)
182 * Change the settings of the current local time zone.
185 * Success: TRUE. The time zone was updated with the settings from tzinfo
188 BOOL WINAPI SetTimeZoneInformation(
189 const LPTIME_ZONE_INFORMATION tzinfo) /* [in] The new time zone. */
192 if ((status = RtlSetTimeZoneInformation(tzinfo)))
193 SetLastError( RtlNtStatusToDosError(status) );
198 /***********************************************************************
199 * _DayLightCompareDate
201 * Compares two dates without looking at the year
205 * -1 if date < compareDate
206 * 0 if date == compareDate
207 * 1 if date > compareDate
208 * -2 if an error occures
211 static int _DayLightCompareDate(
212 const LPSYSTEMTIME date, /* [in] The local time to compare. */
213 const LPSYSTEMTIME compareDate) /* [in] The daylight saving begin
216 int limit_day, dayinsecs;
218 if (date->wMonth < compareDate->wMonth)
219 return -1; /* We are in a month before the date limit. */
221 if (date->wMonth > compareDate->wMonth)
222 return 1; /* We are in a month after the date limit. */
224 if (compareDate->wDayOfWeek <= 6)
229 /* compareDate->wDay is interpreted as number of the week in the month
230 * 5 means: the last week in the month */
231 int weekofmonth = compareDate->wDay;
233 /* calculate day of week for the first day in the month */
234 memcpy(&tmp, date, sizeof(SYSTEMTIME));
238 if (weekofmonth == 5)
240 /* Go to the beginning of the next month. */
241 if (++tmp.wMonth > 12)
248 if (!SystemTimeToFileTime(&tmp, &tmp_ft))
251 if (weekofmonth == 5)
254 FILETIME2LL( &tmp_ft, t)
255 /* subtract one day */
256 t -= (LONGLONG) 24*60*60*10000000;
257 LL2FILETIME( t, &tmp_ft);
260 if (!FileTimeToSystemTime(&tmp_ft, &tmp))
263 if (weekofmonth == 5)
265 /* calculate the last matching day of the week in this month */
266 int dif = tmp.wDayOfWeek - compareDate->wDayOfWeek;
270 limit_day = tmp.wDay - dif;
274 /* calculate the matching day of the week in the given week */
275 int dif = compareDate->wDayOfWeek - tmp.wDayOfWeek;
279 limit_day = tmp.wDay + 7*(weekofmonth-1) + dif;
284 limit_day = compareDate->wDay;
287 /* convert to seconds */
288 limit_day = ((limit_day * 24 + compareDate->wHour) * 60 +
289 compareDate->wMinute ) * 60;
290 dayinsecs = ((date->wDay * 24 + date->wHour) * 60 +
291 date->wMinute ) * 60 + date->wSecond;
293 return dayinsecs < limit_day ? -1 :
294 dayinsecs > limit_day ? 1 :
295 0; /* date is equal to the date limit. */
299 /***********************************************************************
302 * Calculates the local time bias for a given time zone
306 * Returns TRUE when the time zone bias was calculated.
309 static BOOL _GetTimezoneBias(
310 const LPTIME_ZONE_INFORMATION
311 lpTimeZoneInformation, /* [in] The time zone data. */
312 LPSYSTEMTIME lpSysOrLocalTime, /* [in] The system or local time. */
313 BOOL islocal, /* [in] it is local time */
314 LONG* pBias /* [out] The calulated bias in minutes */
318 BOOL beforeStandardDate, afterDaylightDate;
319 BOOL daylightsaving = FALSE;
320 LONG bias = lpTimeZoneInformation->Bias;
322 LONGLONG llTime = 0; /* initialized to prevent gcc complaining */
324 LPSYSTEMTIME lpTime = lpSysOrLocalTime;
326 if (lpTimeZoneInformation->DaylightDate.wMonth != 0)
328 if (lpTimeZoneInformation->StandardDate.wMonth == 0 ||
329 lpTimeZoneInformation->StandardDate.wDay<1 ||
330 lpTimeZoneInformation->StandardDate.wDay>5 ||
331 lpTimeZoneInformation->DaylightDate.wDay<1 ||
332 lpTimeZoneInformation->DaylightDate.wDay>5)
334 SetLastError(ERROR_INVALID_PARAMETER);
339 if (!SystemTimeToFileTime(lpSysOrLocalTime, &ft)) return -2;
340 FILETIME2LL( &ft, llTime );
341 llTime -= ( lpTimeZoneInformation->Bias +
342 lpTimeZoneInformation->DaylightBias ) * (LONGLONG)600000000;
343 LL2FILETIME( llTime, &ft)
344 FileTimeToSystemTime(&ft, &stTemp);
348 /* check for daylight saving */
349 ret = _DayLightCompareDate(lpTime, &lpTimeZoneInformation->StandardDate);
353 beforeStandardDate = ret < 0;
356 llTime -= ( lpTimeZoneInformation->StandardBias -
357 lpTimeZoneInformation->DaylightBias ) * (LONGLONG)600000000;
358 LL2FILETIME( llTime, &ft)
359 FileTimeToSystemTime(&ft, &stTemp);
363 ret = _DayLightCompareDate(lpTime, &lpTimeZoneInformation->DaylightDate);
367 afterDaylightDate = ret >= 0;
369 if( lpTimeZoneInformation->DaylightDate.wMonth < /* Northern */
370 lpTimeZoneInformation->StandardDate.wMonth ) { /* hemisphere */
371 if( beforeStandardDate && afterDaylightDate )
372 daylightsaving = TRUE;
373 } else /* Down south */
374 if( beforeStandardDate || afterDaylightDate )
375 daylightsaving = TRUE;
379 bias += lpTimeZoneInformation->DaylightBias;
380 else if (lpTimeZoneInformation->StandardDate.wMonth != 0)
381 bias += lpTimeZoneInformation->StandardBias;
389 /***********************************************************************
390 * SystemTimeToTzSpecificLocalTime (KERNEL32.@)
392 * Convert a utc system time to a local time in a given time zone.
395 * Success: TRUE. lpLocalTime contains the converted time
399 BOOL WINAPI SystemTimeToTzSpecificLocalTime(
400 LPTIME_ZONE_INFORMATION
401 lpTimeZoneInformation, /* [in] The desired time zone. */
402 LPSYSTEMTIME lpUniversalTime, /* [in] The utc time to base local time on. */
403 LPSYSTEMTIME lpLocalTime) /* [out] The local time in the time zone. */
408 TIME_ZONE_INFORMATION tzinfo;
410 if (lpTimeZoneInformation != NULL)
412 memcpy(&tzinfo, lpTimeZoneInformation, sizeof(TIME_ZONE_INFORMATION));
416 if (GetTimeZoneInformation(&tzinfo) == TIME_ZONE_ID_INVALID)
420 if (!SystemTimeToFileTime(lpUniversalTime, &ft))
422 FILETIME2LL( &ft, llTime)
423 if (!_GetTimezoneBias(&tzinfo, lpUniversalTime, FALSE, &lBias))
425 /* convert minutes to 100-nanoseconds-ticks */
426 llTime -= (LONGLONG)lBias * 600000000;
427 LL2FILETIME( llTime, &ft)
429 return FileTimeToSystemTime(&ft, lpLocalTime);
433 /***********************************************************************
434 * TzSpecificLocalTimeToSystemTime (KERNEL32.@)
436 * Converts a local time to a time in utc.
439 * Success: TRUE. lpUniversalTime contains the converted time
442 BOOL WINAPI TzSpecificLocalTimeToSystemTime(
443 LPTIME_ZONE_INFORMATION lpTimeZoneInformation, /* [in] The desired time zone. */
444 LPSYSTEMTIME lpLocalTime, /* [in] The local time. */
445 LPSYSTEMTIME lpUniversalTime) /* [out] The calculated utc time. */
450 TIME_ZONE_INFORMATION tzinfo;
452 if (lpTimeZoneInformation != NULL)
454 memcpy(&tzinfo, lpTimeZoneInformation, sizeof(TIME_ZONE_INFORMATION));
458 if (GetTimeZoneInformation(&tzinfo) == TIME_ZONE_ID_INVALID)
462 if (!SystemTimeToFileTime(lpLocalTime, &ft))
465 if (!_GetTimezoneBias(&tzinfo, lpLocalTime, TRUE, &lBias))
467 /* convert minutes to 100-nanoseconds-ticks */
468 t += (LONGLONG)lBias * 600000000;
470 return FileTimeToSystemTime(&ft, lpUniversalTime);
474 /***********************************************************************
475 * GetSystemTimeAsFileTime (KERNEL32.@)
477 * Get the current time in utc format.
482 VOID WINAPI GetSystemTimeAsFileTime(
483 LPFILETIME time) /* [out] Destination for the current utc time */
486 NtQuerySystemTime( &t );
487 time->dwLowDateTime = t.u.LowPart;
488 time->dwHighDateTime = t.u.HighPart;
492 /*********************************************************************
493 * TIME_ClockTimeToFileTime (olorin@fandra.org, 20-Sep-1998)
495 * Used by GetProcessTimes to convert clock_t into FILETIME.
497 * Differences to UnixTimeToFileTime:
498 * 1) Divided by CLK_TCK
499 * 2) Time is relative. There is no 'starting date', so there is
500 * no need for offset correction, like in UnixTimeToFileTime
502 static void TIME_ClockTimeToFileTime(clock_t unix_time, LPFILETIME filetime)
504 ULONGLONG secs = RtlEnlargedUnsignedMultiply( unix_time, 10000000 );
505 secs = RtlExtendedLargeIntegerDivide( secs, CLK_TCK, NULL );
506 filetime->dwLowDateTime = (DWORD)secs;
507 filetime->dwHighDateTime = (DWORD)(secs >> 32);
510 /*********************************************************************
511 * GetProcessTimes (KERNEL32.@)
513 * Get the user and kernel execution times of a process,
514 * along with the creation and exit times if known.
521 * Would be nice to subtract the cpu time used by Wine at startup.
522 * Also, there is a need to separate times used by different applications.
525 * lpCreationTime and lpExitTime are not initialised in the Wine implementation.
527 BOOL WINAPI GetProcessTimes(
528 HANDLE hprocess, /* [in] The process to be queried (obtained from PROCESS_QUERY_INFORMATION). */
529 LPFILETIME lpCreationTime, /* [out] The creation time of the process. */
530 LPFILETIME lpExitTime, /* [out] The exit time of the process if exited. */
531 LPFILETIME lpKernelTime, /* [out] The time spent in kernal routines in 100's of nanoseconds. */
532 LPFILETIME lpUserTime) /* [out] The time spent in user routines in 100's of nanoseconds. */
537 TIME_ClockTimeToFileTime(tms.tms_utime,lpUserTime);
538 TIME_ClockTimeToFileTime(tms.tms_stime,lpKernelTime);
542 /*********************************************************************
543 * GetCalendarInfoA (KERNEL32.@)
546 int WINAPI GetCalendarInfoA(LCID lcid, CALID Calendar, CALTYPE CalType,
547 LPSTR lpCalData, int cchData, LPDWORD lpValue)
550 LPWSTR lpCalDataW = NULL;
552 FIXME("(%08lx,%08lx,%08lx,%p,%d,%p): quarter-stub\n",
553 lcid, Calendar, CalType, lpCalData, cchData, lpValue);
555 lcid = ConvertDefaultLocale(lcid);
557 if (NLS_IsUnicodeOnlyLcid(lcid))
559 SetLastError(ERROR_INVALID_PARAMETER);
564 !(lpCalDataW = HeapAlloc(GetProcessHeap(), 0, cchData*sizeof(WCHAR))))
567 ret = GetCalendarInfoW(lcid, Calendar, CalType, lpCalDataW, cchData, lpValue);
568 if(ret && lpCalDataW && lpCalData)
569 WideCharToMultiByte(CP_ACP, 0, lpCalDataW, cchData, lpCalData, cchData, NULL, NULL);
571 HeapFree(GetProcessHeap(), 0, lpCalDataW);
576 /*********************************************************************
577 * GetCalendarInfoW (KERNEL32.@)
579 * See GetCalendarInfoA.
581 int WINAPI GetCalendarInfoW(LCID Locale, CALID Calendar, CALTYPE CalType,
582 LPWSTR lpCalData, int cchData, LPDWORD lpValue)
584 FIXME("(%08lx,%08lx,%08lx,%p,%d,%p): quarter-stub\n",
585 Locale, Calendar, CalType, lpCalData, cchData, lpValue);
587 if (CalType & CAL_NOUSEROVERRIDE)
588 FIXME("flag CAL_NOUSEROVERRIDE used, not fully implemented\n");
589 if (CalType & CAL_USE_CP_ACP)
590 FIXME("flag CAL_USE_CP_ACP used, not fully implemented\n");
592 if (CalType & CAL_RETURN_NUMBER) {
593 if (lpCalData != NULL)
594 WARN("lpCalData not NULL (%p) when it should!\n", lpCalData);
596 WARN("cchData not 0 (%d) when it should!\n", cchData);
599 WARN("lpValue not NULL (%p) when it should!\n", lpValue);
602 /* FIXME: No verification is made yet wrt Locale
603 * for the CALTYPES not requiring GetLocaleInfoA */
604 switch (CalType & ~(CAL_NOUSEROVERRIDE|CAL_RETURN_NUMBER|CAL_USE_CP_ACP)) {
605 case CAL_ICALINTVALUE:
606 FIXME("Unimplemented caltype %ld\n", CalType & 0xffff);
609 FIXME("Unimplemented caltype %ld\n", CalType & 0xffff);
611 case CAL_IYEAROFFSETRANGE:
612 FIXME("Unimplemented caltype %ld\n", CalType & 0xffff);
615 FIXME("Unimplemented caltype %ld\n", CalType & 0xffff);
618 return GetLocaleInfoW(Locale, LOCALE_SSHORTDATE, lpCalData, cchData);
620 return GetLocaleInfoW(Locale, LOCALE_SLONGDATE, lpCalData, cchData);
622 return GetLocaleInfoW(Locale, LOCALE_SDAYNAME1, lpCalData, cchData);
624 return GetLocaleInfoW(Locale, LOCALE_SDAYNAME2, lpCalData, cchData);
626 return GetLocaleInfoW(Locale, LOCALE_SDAYNAME3, lpCalData, cchData);
628 return GetLocaleInfoW(Locale, LOCALE_SDAYNAME4, lpCalData, cchData);
630 return GetLocaleInfoW(Locale, LOCALE_SDAYNAME5, lpCalData, cchData);
632 return GetLocaleInfoW(Locale, LOCALE_SDAYNAME6, lpCalData, cchData);
634 return GetLocaleInfoW(Locale, LOCALE_SDAYNAME7, lpCalData, cchData);
635 case CAL_SABBREVDAYNAME1:
636 return GetLocaleInfoW(Locale, LOCALE_SABBREVDAYNAME1, lpCalData, cchData);
637 case CAL_SABBREVDAYNAME2:
638 return GetLocaleInfoW(Locale, LOCALE_SABBREVDAYNAME2, lpCalData, cchData);
639 case CAL_SABBREVDAYNAME3:
640 return GetLocaleInfoW(Locale, LOCALE_SABBREVDAYNAME3, lpCalData, cchData);
641 case CAL_SABBREVDAYNAME4:
642 return GetLocaleInfoW(Locale, LOCALE_SABBREVDAYNAME4, lpCalData, cchData);
643 case CAL_SABBREVDAYNAME5:
644 return GetLocaleInfoW(Locale, LOCALE_SABBREVDAYNAME5, lpCalData, cchData);
645 case CAL_SABBREVDAYNAME6:
646 return GetLocaleInfoW(Locale, LOCALE_SABBREVDAYNAME6, lpCalData, cchData);
647 case CAL_SABBREVDAYNAME7:
648 return GetLocaleInfoW(Locale, LOCALE_SABBREVDAYNAME7, lpCalData, cchData);
649 case CAL_SMONTHNAME1:
650 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME1, lpCalData, cchData);
651 case CAL_SMONTHNAME2:
652 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME2, lpCalData, cchData);
653 case CAL_SMONTHNAME3:
654 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME3, lpCalData, cchData);
655 case CAL_SMONTHNAME4:
656 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME4, lpCalData, cchData);
657 case CAL_SMONTHNAME5:
658 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME5, lpCalData, cchData);
659 case CAL_SMONTHNAME6:
660 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME6, lpCalData, cchData);
661 case CAL_SMONTHNAME7:
662 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME7, lpCalData, cchData);
663 case CAL_SMONTHNAME8:
664 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME8, lpCalData, cchData);
665 case CAL_SMONTHNAME9:
666 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME9, lpCalData, cchData);
667 case CAL_SMONTHNAME10:
668 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME10, lpCalData, cchData);
669 case CAL_SMONTHNAME11:
670 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME11, lpCalData, cchData);
671 case CAL_SMONTHNAME12:
672 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME12, lpCalData, cchData);
673 case CAL_SMONTHNAME13:
674 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME13, lpCalData, cchData);
675 case CAL_SABBREVMONTHNAME1:
676 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME1, lpCalData, cchData);
677 case CAL_SABBREVMONTHNAME2:
678 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME2, lpCalData, cchData);
679 case CAL_SABBREVMONTHNAME3:
680 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME3, lpCalData, cchData);
681 case CAL_SABBREVMONTHNAME4:
682 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME4, lpCalData, cchData);
683 case CAL_SABBREVMONTHNAME5:
684 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME5, lpCalData, cchData);
685 case CAL_SABBREVMONTHNAME6:
686 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME6, lpCalData, cchData);
687 case CAL_SABBREVMONTHNAME7:
688 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME7, lpCalData, cchData);
689 case CAL_SABBREVMONTHNAME8:
690 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME8, lpCalData, cchData);
691 case CAL_SABBREVMONTHNAME9:
692 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME9, lpCalData, cchData);
693 case CAL_SABBREVMONTHNAME10:
694 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME10, lpCalData, cchData);
695 case CAL_SABBREVMONTHNAME11:
696 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME11, lpCalData, cchData);
697 case CAL_SABBREVMONTHNAME12:
698 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME12, lpCalData, cchData);
699 case CAL_SABBREVMONTHNAME13:
700 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME13, lpCalData, cchData);
702 return GetLocaleInfoW(Locale, LOCALE_SYEARMONTH, lpCalData, cchData);
703 case CAL_ITWODIGITYEARMAX:
704 if (lpValue) *lpValue = CALINFO_MAX_YEAR;
706 default: MESSAGE("Unknown caltype %ld\n",CalType & 0xffff);
712 /*********************************************************************
713 * SetCalendarInfoA (KERNEL32.@)
716 int WINAPI SetCalendarInfoA(LCID Locale, CALID Calendar, CALTYPE CalType, LPCSTR lpCalData)
718 FIXME("(%08lx,%08lx,%08lx,%s): stub\n",
719 Locale, Calendar, CalType, debugstr_a(lpCalData));
723 /*********************************************************************
724 * SetCalendarInfoW (KERNEL32.@)
726 * See SetCalendarInfoA.
728 int WINAPI SetCalendarInfoW(LCID Locale, CALID Calendar, CALTYPE CalType, LPCWSTR lpCalData)
730 FIXME("(%08lx,%08lx,%08lx,%s): stub\n",
731 Locale, Calendar, CalType, debugstr_w(lpCalData));
735 /*********************************************************************
736 * LocalFileTimeToFileTime (KERNEL32.@)
738 BOOL WINAPI LocalFileTimeToFileTime( const FILETIME *localft, LPFILETIME utcft )
741 LARGE_INTEGER local, utc;
743 local.u.LowPart = localft->dwLowDateTime;
744 local.u.HighPart = localft->dwHighDateTime;
745 if (!(status = RtlLocalTimeToSystemTime( &local, &utc )))
747 utcft->dwLowDateTime = utc.u.LowPart;
748 utcft->dwHighDateTime = utc.u.HighPart;
750 else SetLastError( RtlNtStatusToDosError(status) );
755 /*********************************************************************
756 * FileTimeToLocalFileTime (KERNEL32.@)
758 BOOL WINAPI FileTimeToLocalFileTime( const FILETIME *utcft, LPFILETIME localft )
761 LARGE_INTEGER local, utc;
763 utc.u.LowPart = utcft->dwLowDateTime;
764 utc.u.HighPart = utcft->dwHighDateTime;
765 if (!(status = RtlSystemTimeToLocalTime( &utc, &local )))
767 localft->dwLowDateTime = local.u.LowPart;
768 localft->dwHighDateTime = local.u.HighPart;
770 else SetLastError( RtlNtStatusToDosError(status) );
775 /*********************************************************************
776 * FileTimeToSystemTime (KERNEL32.@)
778 BOOL WINAPI FileTimeToSystemTime( const FILETIME *ft, LPSYSTEMTIME syst )
783 t.u.LowPart = ft->dwLowDateTime;
784 t.u.HighPart = ft->dwHighDateTime;
785 RtlTimeToTimeFields(&t, &tf);
787 syst->wYear = tf.Year;
788 syst->wMonth = tf.Month;
790 syst->wHour = tf.Hour;
791 syst->wMinute = tf.Minute;
792 syst->wSecond = tf.Second;
793 syst->wMilliseconds = tf.Milliseconds;
794 syst->wDayOfWeek = tf.Weekday;
798 /*********************************************************************
799 * SystemTimeToFileTime (KERNEL32.@)
801 BOOL WINAPI SystemTimeToFileTime( const SYSTEMTIME *syst, LPFILETIME ft )
806 tf.Year = syst->wYear;
807 tf.Month = syst->wMonth;
809 tf.Hour = syst->wHour;
810 tf.Minute = syst->wMinute;
811 tf.Second = syst->wSecond;
812 tf.Milliseconds = syst->wMilliseconds;
814 RtlTimeFieldsToTime(&tf, &t);
815 ft->dwLowDateTime = t.u.LowPart;
816 ft->dwHighDateTime = t.u.HighPart;
820 /*********************************************************************
821 * CompareFileTime (KERNEL32.@)
823 * Compare two FILETIME's to each other.
827 * y [I] time to compare to x
830 * -1, 0, or 1 indicating that x is less than, equal to, or greater
831 * than y respectively.
833 INT WINAPI CompareFileTime( const FILETIME *x, const FILETIME *y )
835 if (!x || !y) return -1;
837 if (x->dwHighDateTime > y->dwHighDateTime)
839 if (x->dwHighDateTime < y->dwHighDateTime)
841 if (x->dwLowDateTime > y->dwLowDateTime)
843 if (x->dwLowDateTime < y->dwLowDateTime)
848 /*********************************************************************
849 * GetLocalTime (KERNEL32.@)
851 * Get the current local time.
856 VOID WINAPI GetLocalTime(LPSYSTEMTIME systime) /* [O] Destination for current time */
859 LARGE_INTEGER ft, ft2;
861 NtQuerySystemTime(&ft);
862 RtlSystemTimeToLocalTime(&ft, &ft2);
863 lft.dwLowDateTime = ft2.u.LowPart;
864 lft.dwHighDateTime = ft2.u.HighPart;
865 FileTimeToSystemTime(&lft, systime);
868 /*********************************************************************
869 * GetSystemTime (KERNEL32.@)
871 * Get the current system time.
876 VOID WINAPI GetSystemTime(LPSYSTEMTIME systime) /* [O] Destination for current time */
881 NtQuerySystemTime(&t);
882 ft.dwLowDateTime = t.u.LowPart;
883 ft.dwHighDateTime = t.u.HighPart;
884 FileTimeToSystemTime(&ft, systime);
887 /*********************************************************************
888 * GetDaylightFlag (KERNEL32.@)
890 * returns TRUE if daylight saving time is in operation
892 * Note: this function is called from the Win98's control applet
895 BOOL WINAPI GetDaylightFlag(void)
897 time_t t = time(NULL);
898 struct tm *ptm = localtime( &t);
899 return ptm->tm_isdst > 0;
903 /***********************************************************************
904 * DosDateTimeToFileTime (KERNEL32.@)
906 BOOL WINAPI DosDateTimeToFileTime( WORD fatdate, WORD fattime, LPFILETIME ft)
914 newtm.tm_sec = (fattime & 0x1f) * 2;
915 newtm.tm_min = (fattime >> 5) & 0x3f;
916 newtm.tm_hour = (fattime >> 11);
917 newtm.tm_mday = (fatdate & 0x1f);
918 newtm.tm_mon = ((fatdate >> 5) & 0x0f) - 1;
919 newtm.tm_year = (fatdate >> 9) + 80;
921 RtlSecondsSince1970ToTime( timegm(&newtm), (LARGE_INTEGER *)ft );
923 time1 = mktime(&newtm);
924 gtm = gmtime(&time1);
926 RtlSecondsSince1970ToTime( 2*time1-time2, (LARGE_INTEGER *)ft );
932 /***********************************************************************
933 * FileTimeToDosDateTime (KERNEL32.@)
935 BOOL WINAPI FileTimeToDosDateTime( const FILETIME *ft, LPWORD fatdate,
943 li.u.LowPart = ft->dwLowDateTime;
944 li.u.HighPart = ft->dwHighDateTime;
945 RtlTimeToSecondsSince1970( &li, &t );
947 tm = gmtime( &unixtime );
949 *fattime = (tm->tm_hour << 11) + (tm->tm_min << 5) + (tm->tm_sec / 2);
951 *fatdate = ((tm->tm_year - 80) << 9) + ((tm->tm_mon + 1) << 5)