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 #define CALINFO_MAX_YEAR 2029
57 #define LL2FILETIME( ll, pft )\
58 (pft)->dwLowDateTime = (UINT)(ll); \
59 (pft)->dwHighDateTime = (UINT)((ll) >> 32);
60 #define FILETIME2LL( pft, ll) \
61 ll = (((LONGLONG)((pft)->dwHighDateTime))<<32) + (pft)-> dwLowDateTime ;
64 static const int MonthLengths
[2][12] =
66 { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 },
67 { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }
70 static inline BOOL
IsLeapYear(int Year
)
72 return Year
% 4 == 0 && (Year
% 100 != 0 || Year
% 400 == 0);
75 /***********************************************************************
76 * TIME_DayLightCompareDate
78 * Compares two dates without looking at the year.
81 * date [in] The local time to compare.
82 * compareDate [in] The daylight savings begin or end date.
86 * -1 if date < compareDate
87 * 0 if date == compareDate
88 * 1 if date > compareDate
89 * -2 if an error occurs
91 static int TIME_DayLightCompareDate( const SYSTEMTIME
*date
,
92 const SYSTEMTIME
*compareDate
)
94 int limit_day
, dayinsecs
;
96 if (date
->wMonth
< compareDate
->wMonth
)
97 return -1; /* We are in a month before the date limit. */
99 if (date
->wMonth
> compareDate
->wMonth
)
100 return 1; /* We are in a month after the date limit. */
102 /* if year is 0 then date is in day-of-week format, otherwise
103 * it's absolute date.
105 if (compareDate
->wYear
== 0)
108 /* compareDate->wDay is interpreted as number of the week in the month
109 * 5 means: the last week in the month */
110 int weekofmonth
= compareDate
->wDay
;
111 /* calculate the day of the first DayOfWeek in the month */
112 First
= ( 6 + compareDate
->wDayOfWeek
- date
->wDayOfWeek
+ date
->wDay
114 limit_day
= First
+ 7 * (weekofmonth
- 1);
115 /* check needed for the 5th weekday of the month */
116 if(limit_day
> MonthLengths
[date
->wMonth
==2 && IsLeapYear(date
->wYear
)]
122 limit_day
= compareDate
->wDay
;
125 /* convert to seconds */
126 limit_day
= ((limit_day
* 24 + compareDate
->wHour
) * 60 +
127 compareDate
->wMinute
) * 60;
128 dayinsecs
= ((date
->wDay
* 24 + date
->wHour
) * 60 +
129 date
->wMinute
) * 60 + date
->wSecond
;
131 return dayinsecs
< limit_day
? -1 :
132 dayinsecs
> limit_day
? 1 :
133 0; /* date is equal to the date limit. */
136 /***********************************************************************
137 * TIME_CompTimeZoneID
139 * Computes the local time bias for a given time and time zone.
142 * pTZinfo [in] The time zone data.
143 * lpFileTime [in] The system or local time.
144 * islocal [in] it is local time.
147 * TIME_ZONE_ID_INVALID An error occurred
148 * TIME_ZONE_ID_UNKNOWN There are no transition time known
149 * TIME_ZONE_ID_STANDARD Current time is standard time
150 * TIME_ZONE_ID_DAYLIGHT Current time is daylight savings time
152 static DWORD
TIME_CompTimeZoneID ( const TIME_ZONE_INFORMATION
*pTZinfo
,
153 FILETIME
*lpFileTime
, BOOL islocal
)
156 BOOL beforeStandardDate
, afterDaylightDate
;
157 DWORD retval
= TIME_ZONE_ID_INVALID
;
158 LONGLONG llTime
= 0; /* initialized to prevent gcc complaining */
162 if (pTZinfo
->DaylightDate
.wMonth
!= 0)
164 /* if year is 0 then date is in day-of-week format, otherwise
165 * it's absolute date.
167 if (pTZinfo
->StandardDate
.wMonth
== 0 ||
168 (pTZinfo
->StandardDate
.wYear
== 0 &&
169 (pTZinfo
->StandardDate
.wDay
<1 ||
170 pTZinfo
->StandardDate
.wDay
>5 ||
171 pTZinfo
->DaylightDate
.wDay
<1 ||
172 pTZinfo
->DaylightDate
.wDay
>5)))
174 SetLastError(ERROR_INVALID_PARAMETER
);
175 return TIME_ZONE_ID_INVALID
;
179 FILETIME2LL( lpFileTime
, llTime
);
180 llTime
-= pTZinfo
->Bias
* (LONGLONG
)600000000;
181 LL2FILETIME( llTime
, &ftTemp
)
182 lpFileTime
= &ftTemp
;
185 FileTimeToSystemTime(lpFileTime
, &SysTime
);
186 year
= SysTime
.wYear
;
189 llTime
-= pTZinfo
->DaylightBias
* (LONGLONG
)600000000;
190 LL2FILETIME( llTime
, &ftTemp
)
191 FileTimeToSystemTime(lpFileTime
, &SysTime
);
194 /* check for daylight savings */
195 if(year
== SysTime
.wYear
) {
196 ret
= TIME_DayLightCompareDate( &SysTime
, &pTZinfo
->StandardDate
);
198 return TIME_ZONE_ID_INVALID
;
200 beforeStandardDate
= ret
< 0;
202 beforeStandardDate
= SysTime
.wYear
< year
;
205 llTime
-= ( pTZinfo
->StandardBias
- pTZinfo
->DaylightBias
)
206 * (LONGLONG
)600000000;
207 LL2FILETIME( llTime
, &ftTemp
)
208 FileTimeToSystemTime(lpFileTime
, &SysTime
);
211 if(year
== SysTime
.wYear
) {
212 ret
= TIME_DayLightCompareDate( &SysTime
, &pTZinfo
->DaylightDate
);
214 return TIME_ZONE_ID_INVALID
;
216 afterDaylightDate
= ret
>= 0;
218 afterDaylightDate
= SysTime
.wYear
> year
;
220 retval
= TIME_ZONE_ID_STANDARD
;
221 if( pTZinfo
->DaylightDate
.wMonth
< pTZinfo
->StandardDate
.wMonth
) {
222 /* Northern hemisphere */
223 if( beforeStandardDate
&& afterDaylightDate
)
224 retval
= TIME_ZONE_ID_DAYLIGHT
;
225 } else /* Down south */
226 if( beforeStandardDate
|| afterDaylightDate
)
227 retval
= TIME_ZONE_ID_DAYLIGHT
;
229 /* No transition date */
230 retval
= TIME_ZONE_ID_UNKNOWN
;
235 /***********************************************************************
238 * Calculates whether daylight savings is on now.
241 * pTzi [in] Timezone info.
244 * TIME_ZONE_ID_INVALID An error occurred
245 * TIME_ZONE_ID_UNKNOWN There are no transition time known
246 * TIME_ZONE_ID_STANDARD Current time is standard time
247 * TIME_ZONE_ID_DAYLIGHT Current time is daylight savings time
249 static DWORD
TIME_ZoneID( const TIME_ZONE_INFORMATION
*pTzi
)
252 GetSystemTimeAsFileTime( &ftTime
);
253 return TIME_CompTimeZoneID( pTzi
, &ftTime
, FALSE
);
256 /***********************************************************************
257 * TIME_GetTimezoneBias
259 * Calculates the local time bias for a given time zone.
262 * pTZinfo [in] The time zone data.
263 * lpFileTime [in] The system or local time.
264 * islocal [in] It is local time.
265 * pBias [out] The calculated bias in minutes.
268 * TRUE when the time zone bias was calculated.
270 static BOOL
TIME_GetTimezoneBias( const TIME_ZONE_INFORMATION
*pTZinfo
,
271 FILETIME
*lpFileTime
, BOOL islocal
, LONG
*pBias
)
273 LONG bias
= pTZinfo
->Bias
;
274 DWORD tzid
= TIME_CompTimeZoneID( pTZinfo
, lpFileTime
, islocal
);
276 if( tzid
== TIME_ZONE_ID_INVALID
)
278 if (tzid
== TIME_ZONE_ID_DAYLIGHT
)
279 bias
+= pTZinfo
->DaylightBias
;
280 else if (tzid
== TIME_ZONE_ID_STANDARD
)
281 bias
+= pTZinfo
->StandardBias
;
287 /***********************************************************************
288 * SetLocalTime (KERNEL32.@)
290 * Set the local time using current time zone and daylight
294 * systime [in] The desired local time.
297 * Success: TRUE. The time was set.
298 * Failure: FALSE, if the time was invalid or caller does not have
299 * permission to change the time.
301 BOOL WINAPI
SetLocalTime( const SYSTEMTIME
*systime
)
304 LARGE_INTEGER st
, st2
;
307 if( !SystemTimeToFileTime( systime
, &ft
))
309 st
.u
.LowPart
= ft
.dwLowDateTime
;
310 st
.u
.HighPart
= ft
.dwHighDateTime
;
311 RtlLocalTimeToSystemTime( &st
, &st2
);
313 if ((status
= NtSetSystemTime(&st2
, NULL
)))
314 SetLastError( RtlNtStatusToDosError(status
) );
319 /***********************************************************************
320 * GetSystemTimeAdjustment (KERNEL32.@)
322 * Get the period between clock interrupts and the amount the clock
323 * is adjusted each interrupt so as to keep it in sync with an external source.
326 * lpTimeAdjustment [out] The clock adjustment per interrupt in 100's of nanoseconds.
327 * lpTimeIncrement [out] The time between clock interrupts in 100's of nanoseconds.
328 * lpTimeAdjustmentDisabled [out] The clock synchronisation has been disabled.
334 * Only the special case of disabled time adjustments is supported.
336 BOOL WINAPI
GetSystemTimeAdjustment( PDWORD lpTimeAdjustment
, PDWORD lpTimeIncrement
,
337 PBOOL lpTimeAdjustmentDisabled
)
339 *lpTimeAdjustment
= 0;
340 *lpTimeIncrement
= 10000000 / sysconf(_SC_CLK_TCK
);
341 *lpTimeAdjustmentDisabled
= TRUE
;
346 /***********************************************************************
347 * SetSystemTime (KERNEL32.@)
349 * Set the system time in utc.
352 * systime [in] The desired system time.
355 * Success: TRUE. The time was set.
356 * Failure: FALSE, if the time was invalid or caller does not have
357 * permission to change the time.
359 BOOL WINAPI
SetSystemTime( const SYSTEMTIME
*systime
)
365 if( !SystemTimeToFileTime( systime
, &ft
))
367 t
.u
.LowPart
= ft
.dwLowDateTime
;
368 t
.u
.HighPart
= ft
.dwHighDateTime
;
369 if ((status
= NtSetSystemTime(&t
, NULL
)))
370 SetLastError( RtlNtStatusToDosError(status
) );
374 /***********************************************************************
375 * SetSystemTimeAdjustment (KERNEL32.@)
377 * Enables or disables the timing adjustments to the system's clock.
380 * dwTimeAdjustment [in] Number of units to add per clock interrupt.
381 * bTimeAdjustmentDisabled [in] Adjustment mode.
387 BOOL WINAPI
SetSystemTimeAdjustment( DWORD dwTimeAdjustment
, BOOL bTimeAdjustmentDisabled
)
389 /* Fake function for now... */
390 FIXME("(%08x,%d): stub !\n", dwTimeAdjustment
, bTimeAdjustmentDisabled
);
394 /***********************************************************************
395 * GetTimeZoneInformation (KERNEL32.@)
397 * Get information about the current local time zone.
400 * tzinfo [out] Destination for time zone information.
403 * TIME_ZONE_ID_INVALID An error occurred
404 * TIME_ZONE_ID_UNKNOWN There are no transition time known
405 * TIME_ZONE_ID_STANDARD Current time is standard time
406 * TIME_ZONE_ID_DAYLIGHT Current time is daylight savings time
408 DWORD WINAPI
GetTimeZoneInformation( LPTIME_ZONE_INFORMATION tzinfo
)
412 status
= RtlQueryTimeZoneInformation( (RTL_TIME_ZONE_INFORMATION
*)tzinfo
);
413 if ( status
!= STATUS_SUCCESS
)
415 SetLastError( RtlNtStatusToDosError(status
) );
416 return TIME_ZONE_ID_INVALID
;
418 return TIME_ZoneID( tzinfo
);
421 /***********************************************************************
422 * SetTimeZoneInformation (KERNEL32.@)
424 * Change the settings of the current local time zone.
427 * tzinfo [in] The new time zone.
430 * Success: TRUE. The time zone was updated with the settings from tzinfo.
433 BOOL WINAPI
SetTimeZoneInformation( const TIME_ZONE_INFORMATION
*tzinfo
)
436 status
= RtlSetTimeZoneInformation( (const RTL_TIME_ZONE_INFORMATION
*)tzinfo
);
437 if ( status
!= STATUS_SUCCESS
)
438 SetLastError( RtlNtStatusToDosError(status
) );
442 /***********************************************************************
443 * SystemTimeToTzSpecificLocalTime (KERNEL32.@)
445 * Convert a utc system time to a local time in a given time zone.
448 * lpTimeZoneInformation [in] The desired time zone.
449 * lpUniversalTime [in] The utc time to base local time on.
450 * lpLocalTime [out] The local time in the time zone.
453 * Success: TRUE. lpLocalTime contains the converted time
457 BOOL WINAPI
SystemTimeToTzSpecificLocalTime(
458 const TIME_ZONE_INFORMATION
*lpTimeZoneInformation
,
459 const SYSTEMTIME
*lpUniversalTime
, LPSYSTEMTIME lpLocalTime
)
464 TIME_ZONE_INFORMATION tzinfo
;
466 if (lpTimeZoneInformation
!= NULL
)
468 tzinfo
= *lpTimeZoneInformation
;
472 if (GetTimeZoneInformation(&tzinfo
) == TIME_ZONE_ID_INVALID
)
476 if (!SystemTimeToFileTime(lpUniversalTime
, &ft
))
478 FILETIME2LL( &ft
, llTime
)
479 if (!TIME_GetTimezoneBias(&tzinfo
, &ft
, FALSE
, &lBias
))
481 /* convert minutes to 100-nanoseconds-ticks */
482 llTime
-= (LONGLONG
)lBias
* 600000000;
483 LL2FILETIME( llTime
, &ft
)
485 return FileTimeToSystemTime(&ft
, lpLocalTime
);
489 /***********************************************************************
490 * TzSpecificLocalTimeToSystemTime (KERNEL32.@)
492 * Converts a local time to a time in utc.
495 * lpTimeZoneInformation [in] The desired time zone.
496 * lpLocalTime [in] The local time.
497 * lpUniversalTime [out] The calculated utc time.
500 * Success: TRUE. lpUniversalTime contains the converted time.
503 BOOL WINAPI
TzSpecificLocalTimeToSystemTime(
504 const TIME_ZONE_INFORMATION
*lpTimeZoneInformation
,
505 const SYSTEMTIME
*lpLocalTime
, LPSYSTEMTIME lpUniversalTime
)
510 TIME_ZONE_INFORMATION tzinfo
;
512 if (lpTimeZoneInformation
!= NULL
)
514 tzinfo
= *lpTimeZoneInformation
;
518 if (GetTimeZoneInformation(&tzinfo
) == TIME_ZONE_ID_INVALID
)
522 if (!SystemTimeToFileTime(lpLocalTime
, &ft
))
525 if (!TIME_GetTimezoneBias(&tzinfo
, &ft
, TRUE
, &lBias
))
527 /* convert minutes to 100-nanoseconds-ticks */
528 t
+= (LONGLONG
)lBias
* 600000000;
530 return FileTimeToSystemTime(&ft
, lpUniversalTime
);
534 /***********************************************************************
535 * GetSystemTimeAsFileTime (KERNEL32.@)
537 * Get the current time in utc format.
542 VOID WINAPI
GetSystemTimeAsFileTime(
543 LPFILETIME time
) /* [out] Destination for the current utc time */
546 NtQuerySystemTime( &t
);
547 time
->dwLowDateTime
= t
.u
.LowPart
;
548 time
->dwHighDateTime
= t
.u
.HighPart
;
552 /*********************************************************************
553 * TIME_ClockTimeToFileTime (olorin@fandra.org, 20-Sep-1998)
555 * Used by GetProcessTimes to convert clock_t into FILETIME.
557 * Differences to UnixTimeToFileTime:
558 * 1) Divided by CLK_TCK
559 * 2) Time is relative. There is no 'starting date', so there is
560 * no need for offset correction, like in UnixTimeToFileTime
562 static void TIME_ClockTimeToFileTime(clock_t unix_time
, LPFILETIME filetime
)
564 long clocksPerSec
= sysconf(_SC_CLK_TCK
);
565 ULONGLONG secs
= (ULONGLONG
)unix_time
* 10000000 / clocksPerSec
;
566 filetime
->dwLowDateTime
= (DWORD
)secs
;
567 filetime
->dwHighDateTime
= (DWORD
)(secs
>> 32);
570 /*********************************************************************
571 * GetProcessTimes (KERNEL32.@)
573 * Get the user and kernel execution times of a process,
574 * along with the creation and exit times if known.
577 * hprocess [in] The process to be queried.
578 * lpCreationTime [out] The creation time of the process.
579 * lpExitTime [out] The exit time of the process if exited.
580 * lpKernelTime [out] The time spent in kernel routines in 100's of nanoseconds.
581 * lpUserTime [out] The time spent in user routines in 100's of nanoseconds.
588 * Would be nice to subtract the cpu time used by Wine at startup.
589 * Also, there is a need to separate times used by different applications.
592 * KernelTime and UserTime are always for the current process
594 BOOL WINAPI
GetProcessTimes( HANDLE hprocess
, LPFILETIME lpCreationTime
,
595 LPFILETIME lpExitTime
, LPFILETIME lpKernelTime
, LPFILETIME lpUserTime
)
598 KERNEL_USER_TIMES pti
;
601 TIME_ClockTimeToFileTime(tms
.tms_utime
,lpUserTime
);
602 TIME_ClockTimeToFileTime(tms
.tms_stime
,lpKernelTime
);
603 if (NtQueryInformationProcess( hprocess
, ProcessTimes
, &pti
, sizeof(pti
), NULL
))
605 LL2FILETIME( pti
.CreateTime
.QuadPart
, lpCreationTime
);
606 LL2FILETIME( pti
.ExitTime
.QuadPart
, lpExitTime
);
610 /*********************************************************************
611 * GetCalendarInfoA (KERNEL32.@)
614 int WINAPI
GetCalendarInfoA(LCID lcid
, CALID Calendar
, CALTYPE CalType
,
615 LPSTR lpCalData
, int cchData
, LPDWORD lpValue
)
618 LPWSTR lpCalDataW
= NULL
;
620 if (NLS_IsUnicodeOnlyLcid(lcid
))
622 SetLastError(ERROR_INVALID_PARAMETER
);
627 !(lpCalDataW
= HeapAlloc(GetProcessHeap(), 0, cchData
*sizeof(WCHAR
))))
630 ret
= GetCalendarInfoW(lcid
, Calendar
, CalType
, lpCalDataW
, cchData
, lpValue
);
631 if(ret
&& lpCalDataW
&& lpCalData
)
632 WideCharToMultiByte(CP_ACP
, 0, lpCalDataW
, cchData
, lpCalData
, cchData
, NULL
, NULL
);
633 else if (CalType
& CAL_RETURN_NUMBER
)
634 ret
*= sizeof(WCHAR
);
635 HeapFree(GetProcessHeap(), 0, lpCalDataW
);
640 /*********************************************************************
641 * GetCalendarInfoW (KERNEL32.@)
644 int WINAPI
GetCalendarInfoW(LCID Locale
, CALID Calendar
, CALTYPE CalType
,
645 LPWSTR lpCalData
, int cchData
, LPDWORD lpValue
)
647 if (CalType
& CAL_NOUSEROVERRIDE
)
648 FIXME("flag CAL_NOUSEROVERRIDE used, not fully implemented\n");
649 if (CalType
& CAL_USE_CP_ACP
)
650 FIXME("flag CAL_USE_CP_ACP used, not fully implemented\n");
652 if (CalType
& CAL_RETURN_NUMBER
) {
655 SetLastError( ERROR_INVALID_PARAMETER
);
658 if (lpCalData
!= NULL
)
659 WARN("lpCalData not NULL (%p) when it should!\n", lpCalData
);
661 WARN("cchData not 0 (%d) when it should!\n", cchData
);
664 WARN("lpValue not NULL (%p) when it should!\n", lpValue
);
667 /* FIXME: No verification is made yet wrt Locale
668 * for the CALTYPES not requiring GetLocaleInfoA */
669 switch (CalType
& ~(CAL_NOUSEROVERRIDE
|CAL_RETURN_NUMBER
|CAL_USE_CP_ACP
)) {
670 case CAL_ICALINTVALUE
:
671 if (CalType
& CAL_RETURN_NUMBER
)
672 return GetLocaleInfoW(Locale
, LOCALE_RETURN_NUMBER
| LOCALE_ICALENDARTYPE
,
674 return GetLocaleInfoW(Locale
, LOCALE_ICALENDARTYPE
, lpCalData
, cchData
);
676 FIXME("Unimplemented caltype %d\n", CalType
& 0xffff);
677 if (lpCalData
) *lpCalData
= 0;
679 case CAL_IYEAROFFSETRANGE
:
680 FIXME("Unimplemented caltype %d\n", CalType
& 0xffff);
683 FIXME("Unimplemented caltype %d\n", CalType
& 0xffff);
686 return GetLocaleInfoW(Locale
, LOCALE_SSHORTDATE
, lpCalData
, cchData
);
688 return GetLocaleInfoW(Locale
, LOCALE_SLONGDATE
, lpCalData
, cchData
);
690 return GetLocaleInfoW(Locale
, LOCALE_SDAYNAME1
, lpCalData
, cchData
);
692 return GetLocaleInfoW(Locale
, LOCALE_SDAYNAME2
, lpCalData
, cchData
);
694 return GetLocaleInfoW(Locale
, LOCALE_SDAYNAME3
, lpCalData
, cchData
);
696 return GetLocaleInfoW(Locale
, LOCALE_SDAYNAME4
, lpCalData
, cchData
);
698 return GetLocaleInfoW(Locale
, LOCALE_SDAYNAME5
, lpCalData
, cchData
);
700 return GetLocaleInfoW(Locale
, LOCALE_SDAYNAME6
, lpCalData
, cchData
);
702 return GetLocaleInfoW(Locale
, LOCALE_SDAYNAME7
, lpCalData
, cchData
);
703 case CAL_SABBREVDAYNAME1
:
704 return GetLocaleInfoW(Locale
, LOCALE_SABBREVDAYNAME1
, lpCalData
, cchData
);
705 case CAL_SABBREVDAYNAME2
:
706 return GetLocaleInfoW(Locale
, LOCALE_SABBREVDAYNAME2
, lpCalData
, cchData
);
707 case CAL_SABBREVDAYNAME3
:
708 return GetLocaleInfoW(Locale
, LOCALE_SABBREVDAYNAME3
, lpCalData
, cchData
);
709 case CAL_SABBREVDAYNAME4
:
710 return GetLocaleInfoW(Locale
, LOCALE_SABBREVDAYNAME4
, lpCalData
, cchData
);
711 case CAL_SABBREVDAYNAME5
:
712 return GetLocaleInfoW(Locale
, LOCALE_SABBREVDAYNAME5
, lpCalData
, cchData
);
713 case CAL_SABBREVDAYNAME6
:
714 return GetLocaleInfoW(Locale
, LOCALE_SABBREVDAYNAME6
, lpCalData
, cchData
);
715 case CAL_SABBREVDAYNAME7
:
716 return GetLocaleInfoW(Locale
, LOCALE_SABBREVDAYNAME7
, lpCalData
, cchData
);
717 case CAL_SMONTHNAME1
:
718 return GetLocaleInfoW(Locale
, LOCALE_SMONTHNAME1
, lpCalData
, cchData
);
719 case CAL_SMONTHNAME2
:
720 return GetLocaleInfoW(Locale
, LOCALE_SMONTHNAME2
, lpCalData
, cchData
);
721 case CAL_SMONTHNAME3
:
722 return GetLocaleInfoW(Locale
, LOCALE_SMONTHNAME3
, lpCalData
, cchData
);
723 case CAL_SMONTHNAME4
:
724 return GetLocaleInfoW(Locale
, LOCALE_SMONTHNAME4
, lpCalData
, cchData
);
725 case CAL_SMONTHNAME5
:
726 return GetLocaleInfoW(Locale
, LOCALE_SMONTHNAME5
, lpCalData
, cchData
);
727 case CAL_SMONTHNAME6
:
728 return GetLocaleInfoW(Locale
, LOCALE_SMONTHNAME6
, lpCalData
, cchData
);
729 case CAL_SMONTHNAME7
:
730 return GetLocaleInfoW(Locale
, LOCALE_SMONTHNAME7
, lpCalData
, cchData
);
731 case CAL_SMONTHNAME8
:
732 return GetLocaleInfoW(Locale
, LOCALE_SMONTHNAME8
, lpCalData
, cchData
);
733 case CAL_SMONTHNAME9
:
734 return GetLocaleInfoW(Locale
, LOCALE_SMONTHNAME9
, lpCalData
, cchData
);
735 case CAL_SMONTHNAME10
:
736 return GetLocaleInfoW(Locale
, LOCALE_SMONTHNAME10
, lpCalData
, cchData
);
737 case CAL_SMONTHNAME11
:
738 return GetLocaleInfoW(Locale
, LOCALE_SMONTHNAME11
, lpCalData
, cchData
);
739 case CAL_SMONTHNAME12
:
740 return GetLocaleInfoW(Locale
, LOCALE_SMONTHNAME12
, lpCalData
, cchData
);
741 case CAL_SMONTHNAME13
:
742 return GetLocaleInfoW(Locale
, LOCALE_SMONTHNAME13
, lpCalData
, cchData
);
743 case CAL_SABBREVMONTHNAME1
:
744 return GetLocaleInfoW(Locale
, LOCALE_SABBREVMONTHNAME1
, lpCalData
, cchData
);
745 case CAL_SABBREVMONTHNAME2
:
746 return GetLocaleInfoW(Locale
, LOCALE_SABBREVMONTHNAME2
, lpCalData
, cchData
);
747 case CAL_SABBREVMONTHNAME3
:
748 return GetLocaleInfoW(Locale
, LOCALE_SABBREVMONTHNAME3
, lpCalData
, cchData
);
749 case CAL_SABBREVMONTHNAME4
:
750 return GetLocaleInfoW(Locale
, LOCALE_SABBREVMONTHNAME4
, lpCalData
, cchData
);
751 case CAL_SABBREVMONTHNAME5
:
752 return GetLocaleInfoW(Locale
, LOCALE_SABBREVMONTHNAME5
, lpCalData
, cchData
);
753 case CAL_SABBREVMONTHNAME6
:
754 return GetLocaleInfoW(Locale
, LOCALE_SABBREVMONTHNAME6
, lpCalData
, cchData
);
755 case CAL_SABBREVMONTHNAME7
:
756 return GetLocaleInfoW(Locale
, LOCALE_SABBREVMONTHNAME7
, lpCalData
, cchData
);
757 case CAL_SABBREVMONTHNAME8
:
758 return GetLocaleInfoW(Locale
, LOCALE_SABBREVMONTHNAME8
, lpCalData
, cchData
);
759 case CAL_SABBREVMONTHNAME9
:
760 return GetLocaleInfoW(Locale
, LOCALE_SABBREVMONTHNAME9
, lpCalData
, cchData
);
761 case CAL_SABBREVMONTHNAME10
:
762 return GetLocaleInfoW(Locale
, LOCALE_SABBREVMONTHNAME10
, lpCalData
, cchData
);
763 case CAL_SABBREVMONTHNAME11
:
764 return GetLocaleInfoW(Locale
, LOCALE_SABBREVMONTHNAME11
, lpCalData
, cchData
);
765 case CAL_SABBREVMONTHNAME12
:
766 return GetLocaleInfoW(Locale
, LOCALE_SABBREVMONTHNAME12
, lpCalData
, cchData
);
767 case CAL_SABBREVMONTHNAME13
:
768 return GetLocaleInfoW(Locale
, LOCALE_SABBREVMONTHNAME13
, lpCalData
, cchData
);
770 return GetLocaleInfoW(Locale
, LOCALE_SYEARMONTH
, lpCalData
, cchData
);
771 case CAL_ITWODIGITYEARMAX
:
772 if (CalType
& CAL_RETURN_NUMBER
)
774 *lpValue
= CALINFO_MAX_YEAR
;
775 return sizeof(DWORD
) / sizeof(WCHAR
);
779 static const WCHAR fmtW
[] = {'%','u',0};
781 int ret
= snprintfW( buffer
, 10, fmtW
, CALINFO_MAX_YEAR
) + 1;
782 if (!lpCalData
) return ret
;
785 strcpyW( lpCalData
, buffer
);
788 SetLastError( ERROR_INSUFFICIENT_BUFFER
);
793 FIXME("Unknown caltype %d\n",CalType
& 0xffff);
794 SetLastError(ERROR_INVALID_FLAGS
);
800 /*********************************************************************
801 * GetCalendarInfoEx (KERNEL32.@)
803 int WINAPI
GetCalendarInfoEx(LPCWSTR locale
, CALID calendar
, LPCWSTR lpReserved
, CALTYPE caltype
,
804 LPWSTR data
, int len
, DWORD
*value
)
806 LCID lcid
= LocaleNameToLCID(locale
, 0);
807 FIXME("(%s, %d, %p, 0x%08x, %p, %d, %p): semi-stub\n", debugstr_w(locale
), calendar
, lpReserved
, caltype
,
809 return GetCalendarInfoW(lcid
, calendar
, caltype
, data
, len
, value
);
812 /*********************************************************************
813 * SetCalendarInfoA (KERNEL32.@)
816 int WINAPI
SetCalendarInfoA(LCID Locale
, CALID Calendar
, CALTYPE CalType
, LPCSTR lpCalData
)
818 FIXME("(%08x,%08x,%08x,%s): stub\n",
819 Locale
, Calendar
, CalType
, debugstr_a(lpCalData
));
823 /*********************************************************************
824 * SetCalendarInfoW (KERNEL32.@)
828 int WINAPI
SetCalendarInfoW(LCID Locale
, CALID Calendar
, CALTYPE CalType
, LPCWSTR lpCalData
)
830 FIXME("(%08x,%08x,%08x,%s): stub\n",
831 Locale
, Calendar
, CalType
, debugstr_w(lpCalData
));
835 /*********************************************************************
836 * LocalFileTimeToFileTime (KERNEL32.@)
838 BOOL WINAPI
LocalFileTimeToFileTime( const FILETIME
*localft
, LPFILETIME utcft
)
841 LARGE_INTEGER local
, utc
;
843 local
.u
.LowPart
= localft
->dwLowDateTime
;
844 local
.u
.HighPart
= localft
->dwHighDateTime
;
845 if (!(status
= RtlLocalTimeToSystemTime( &local
, &utc
)))
847 utcft
->dwLowDateTime
= utc
.u
.LowPart
;
848 utcft
->dwHighDateTime
= utc
.u
.HighPart
;
850 else SetLastError( RtlNtStatusToDosError(status
) );
855 /*********************************************************************
856 * FileTimeToLocalFileTime (KERNEL32.@)
858 BOOL WINAPI
FileTimeToLocalFileTime( const FILETIME
*utcft
, LPFILETIME localft
)
861 LARGE_INTEGER local
, utc
;
863 utc
.u
.LowPart
= utcft
->dwLowDateTime
;
864 utc
.u
.HighPart
= utcft
->dwHighDateTime
;
865 if (!(status
= RtlSystemTimeToLocalTime( &utc
, &local
)))
867 localft
->dwLowDateTime
= local
.u
.LowPart
;
868 localft
->dwHighDateTime
= local
.u
.HighPart
;
870 else SetLastError( RtlNtStatusToDosError(status
) );
875 /*********************************************************************
876 * FileTimeToSystemTime (KERNEL32.@)
878 BOOL WINAPI
FileTimeToSystemTime( const FILETIME
*ft
, LPSYSTEMTIME syst
)
883 t
.u
.LowPart
= ft
->dwLowDateTime
;
884 t
.u
.HighPart
= ft
->dwHighDateTime
;
885 RtlTimeToTimeFields(&t
, &tf
);
887 syst
->wYear
= tf
.Year
;
888 syst
->wMonth
= tf
.Month
;
890 syst
->wHour
= tf
.Hour
;
891 syst
->wMinute
= tf
.Minute
;
892 syst
->wSecond
= tf
.Second
;
893 syst
->wMilliseconds
= tf
.Milliseconds
;
894 syst
->wDayOfWeek
= tf
.Weekday
;
898 /*********************************************************************
899 * SystemTimeToFileTime (KERNEL32.@)
901 BOOL WINAPI
SystemTimeToFileTime( const SYSTEMTIME
*syst
, LPFILETIME ft
)
906 tf
.Year
= syst
->wYear
;
907 tf
.Month
= syst
->wMonth
;
909 tf
.Hour
= syst
->wHour
;
910 tf
.Minute
= syst
->wMinute
;
911 tf
.Second
= syst
->wSecond
;
912 tf
.Milliseconds
= syst
->wMilliseconds
;
914 if( !RtlTimeFieldsToTime(&tf
, &t
)) {
915 SetLastError( ERROR_INVALID_PARAMETER
);
918 ft
->dwLowDateTime
= t
.u
.LowPart
;
919 ft
->dwHighDateTime
= t
.u
.HighPart
;
923 /*********************************************************************
924 * CompareFileTime (KERNEL32.@)
926 * Compare two FILETIME's to each other.
930 * y [I] time to compare to x
933 * -1, 0, or 1 indicating that x is less than, equal to, or greater
934 * than y respectively.
936 INT WINAPI
CompareFileTime( const FILETIME
*x
, const FILETIME
*y
)
938 if (!x
|| !y
) return -1;
940 if (x
->dwHighDateTime
> y
->dwHighDateTime
)
942 if (x
->dwHighDateTime
< y
->dwHighDateTime
)
944 if (x
->dwLowDateTime
> y
->dwLowDateTime
)
946 if (x
->dwLowDateTime
< y
->dwLowDateTime
)
951 /*********************************************************************
952 * GetLocalTime (KERNEL32.@)
954 * Get the current local time.
957 * systime [O] Destination for current time.
962 VOID WINAPI
GetLocalTime(LPSYSTEMTIME systime
)
965 LARGE_INTEGER ft
, ft2
;
967 NtQuerySystemTime(&ft
);
968 RtlSystemTimeToLocalTime(&ft
, &ft2
);
969 lft
.dwLowDateTime
= ft2
.u
.LowPart
;
970 lft
.dwHighDateTime
= ft2
.u
.HighPart
;
971 FileTimeToSystemTime(&lft
, systime
);
974 /*********************************************************************
975 * GetSystemTime (KERNEL32.@)
977 * Get the current system time.
980 * systime [O] Destination for current time.
985 VOID WINAPI
GetSystemTime(LPSYSTEMTIME systime
)
990 NtQuerySystemTime(&t
);
991 ft
.dwLowDateTime
= t
.u
.LowPart
;
992 ft
.dwHighDateTime
= t
.u
.HighPart
;
993 FileTimeToSystemTime(&ft
, systime
);
996 /*********************************************************************
997 * GetDaylightFlag (KERNEL32.@)
999 * Specifies if daylight savings time is in operation.
1002 * This function is called from the Win98's control applet timedate.cpl.
1005 * TRUE if daylight savings time is in operation.
1008 BOOL WINAPI
GetDaylightFlag(void)
1010 TIME_ZONE_INFORMATION tzinfo
;
1011 return GetTimeZoneInformation( &tzinfo
) == TIME_ZONE_ID_DAYLIGHT
;
1014 /***********************************************************************
1015 * DosDateTimeToFileTime (KERNEL32.@)
1017 BOOL WINAPI
DosDateTimeToFileTime( WORD fatdate
, WORD fattime
, LPFILETIME ft
)
1022 time_t time1
, time2
;
1025 newtm
.tm_sec
= (fattime
& 0x1f) * 2;
1026 newtm
.tm_min
= (fattime
>> 5) & 0x3f;
1027 newtm
.tm_hour
= (fattime
>> 11);
1028 newtm
.tm_mday
= (fatdate
& 0x1f);
1029 newtm
.tm_mon
= ((fatdate
>> 5) & 0x0f) - 1;
1030 newtm
.tm_year
= (fatdate
>> 9) + 80;
1031 newtm
.tm_isdst
= -1;
1033 RtlSecondsSince1970ToTime( timegm(&newtm
), (LARGE_INTEGER
*)ft
);
1035 time1
= mktime(&newtm
);
1036 gtm
= gmtime(&time1
);
1037 time2
= mktime(gtm
);
1038 RtlSecondsSince1970ToTime( 2*time1
-time2
, (LARGE_INTEGER
*)ft
);
1044 /***********************************************************************
1045 * FileTimeToDosDateTime (KERNEL32.@)
1047 BOOL WINAPI
FileTimeToDosDateTime( const FILETIME
*ft
, LPWORD fatdate
,
1055 if (!fatdate
|| !fattime
)
1057 SetLastError(ERROR_INVALID_PARAMETER
);
1060 li
.u
.LowPart
= ft
->dwLowDateTime
;
1061 li
.u
.HighPart
= ft
->dwHighDateTime
;
1062 if (!RtlTimeToSecondsSince1970( &li
, &t
))
1064 SetLastError(ERROR_INVALID_PARAMETER
);
1068 tm
= gmtime( &unixtime
);
1070 *fattime
= (tm
->tm_hour
<< 11) + (tm
->tm_min
<< 5) + (tm
->tm_sec
/ 2);
1072 *fatdate
= ((tm
->tm_year
- 80) << 9) + ((tm
->tm_mon
+ 1) << 5)
1077 /*********************************************************************
1078 * GetSystemTimes (KERNEL32.@)
1080 * Retrieves system timing information
1083 * lpIdleTime [O] Destination for idle time.
1084 * lpKernelTime [O] Destination for kernel time.
1085 * lpUserTime [O] Destination for user time.
1088 * TRUE if success, FALSE otherwise.
1090 BOOL WINAPI
GetSystemTimes(LPFILETIME lpIdleTime
, LPFILETIME lpKernelTime
, LPFILETIME lpUserTime
)
1092 FIXME("(%p,%p,%p): Stub!\n", lpIdleTime
, lpKernelTime
, lpUserTime
);
1097 /***********************************************************************
1098 * GetDynamicTimeZoneInformation (KERNEL32.@)
1100 DWORD WINAPI
GetDynamicTimeZoneInformation(PDYNAMIC_TIME_ZONE_INFORMATION info
)
1102 FIXME("(%p) stub!\n", info
);
1103 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1104 return TIME_ZONE_ID_INVALID
;
1107 /***********************************************************************
1108 * QueryUnbiasedInterruptTime (KERNEL32.@)
1110 BOOL WINAPI
QueryUnbiasedInterruptTime(ULONGLONG
*time
)
1112 TRACE("(%p)\n", time
);
1113 if (!time
) return FALSE
;
1114 RtlQueryUnbiasedInterruptTime(time
);