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>
36 #ifdef HAVE_MACHINE_LIMITS_H
37 #include <machine/limits.h>
40 #define NONAMELESSUNION
41 #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 ;
63 static const int MonthLengths
[2][12] =
65 { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 },
66 { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }
69 static inline int IsLeapYear(int Year
)
71 return Year
% 4 == 0 && (Year
% 100 != 0 || Year
% 400 == 0) ? 1 : 0;
74 /***********************************************************************
75 * TIME_DayLightCompareDate
77 * Compares two dates without looking at the year
81 * -1 if date < compareDate
82 * 0 if date == compareDate
83 * 1 if date > compareDate
84 * -2 if an error occurs
86 static int TIME_DayLightCompareDate(
87 const SYSTEMTIME
*date
, /* [in] The local time to compare. */
88 const SYSTEMTIME
*compareDate
) /* [in] The daylight saving begin
91 int limit_day
, dayinsecs
;
93 if (date
->wMonth
< compareDate
->wMonth
)
94 return -1; /* We are in a month before the date limit. */
96 if (date
->wMonth
> compareDate
->wMonth
)
97 return 1; /* We are in a month after the date limit. */
99 if (compareDate
->wDayOfWeek
<= 6)
102 /* compareDate->wDay is interpreted as number of the week in the month
103 * 5 means: the last week in the month */
104 int weekofmonth
= compareDate
->wDay
;
105 /* calculate the day of the first DayOfWeek in the month */
106 First
= ( 6 + compareDate
->wDayOfWeek
- date
->wDayOfWeek
+ date
->wDay
108 limit_day
= First
+ 7 * (weekofmonth
- 1);
109 /* check needed for the 5th weekday of the month */
110 if(limit_day
> MonthLengths
[date
->wMonth
==2 && IsLeapYear(date
->wYear
)]
116 limit_day
= compareDate
->wDay
;
119 /* convert to seconds */
120 limit_day
= ((limit_day
* 24 + compareDate
->wHour
) * 60 +
121 compareDate
->wMinute
) * 60;
122 dayinsecs
= ((date
->wDay
* 24 + date
->wHour
) * 60 +
123 date
->wMinute
) * 60 + date
->wSecond
;
125 return dayinsecs
< limit_day
? -1 :
126 dayinsecs
> limit_day
? 1 :
127 0; /* date is equal to the date limit. */
130 /***********************************************************************
131 * TIME_CompTimeZoneID
133 * Computes the local time bias for a given time and time zone
136 * TIME_ZONE_ID_INVALID An error occurred
137 * TIME_ZONE_ID_UNKNOWN There are no transition time known
138 * TIME_ZONE_ID_STANDARD Current time is standard time
139 * TIME_ZONE_ID_DAYLIGHT Current time is dayligh saving time
141 static BOOL
TIME_CompTimeZoneID (
142 const TIME_ZONE_INFORMATION
*pTZinfo
, /* [in] The time zone data. */
143 FILETIME
*lpFileTime
, /* [in] The system or local time. */
144 BOOL islocal
/* [in] it is local time */
148 BOOL beforeStandardDate
, afterDaylightDate
;
149 DWORD retval
= TIME_ZONE_ID_INVALID
;
150 LONGLONG llTime
= 0; /* initialized to prevent gcc complaining */
154 if (pTZinfo
->DaylightDate
.wMonth
!= 0)
156 if (pTZinfo
->StandardDate
.wMonth
== 0 ||
157 pTZinfo
->StandardDate
.wDay
<1 ||
158 pTZinfo
->StandardDate
.wDay
>5 ||
159 pTZinfo
->DaylightDate
.wDay
<1 ||
160 pTZinfo
->DaylightDate
.wDay
>5)
162 SetLastError(ERROR_INVALID_PARAMETER
);
163 return TIME_ZONE_ID_INVALID
;
167 FILETIME2LL( lpFileTime
, llTime
);
168 llTime
-= ( pTZinfo
->Bias
+ pTZinfo
->DaylightBias
)
169 * (LONGLONG
)600000000;
170 LL2FILETIME( llTime
, &ftTemp
)
171 lpFileTime
= &ftTemp
;
174 FileTimeToSystemTime(lpFileTime
, &SysTime
);
176 /* check for daylight saving */
177 ret
= TIME_DayLightCompareDate( &SysTime
, &pTZinfo
->StandardDate
);
179 return TIME_ZONE_ID_INVALID
;
181 beforeStandardDate
= ret
< 0;
184 llTime
-= ( pTZinfo
->StandardBias
- pTZinfo
->DaylightBias
)
185 * (LONGLONG
)600000000;
186 LL2FILETIME( llTime
, &ftTemp
)
187 FileTimeToSystemTime(lpFileTime
, &SysTime
);
190 ret
= TIME_DayLightCompareDate( &SysTime
, &pTZinfo
->DaylightDate
);
192 return TIME_ZONE_ID_INVALID
;
194 afterDaylightDate
= ret
>= 0;
196 retval
= TIME_ZONE_ID_STANDARD
;
197 if( pTZinfo
->DaylightDate
.wMonth
< pTZinfo
->StandardDate
.wMonth
) {
198 /* Northern hemisphere */
199 if( beforeStandardDate
&& afterDaylightDate
)
200 retval
= TIME_ZONE_ID_DAYLIGHT
;
201 } else /* Down south */
202 if( beforeStandardDate
|| afterDaylightDate
)
203 retval
= TIME_ZONE_ID_DAYLIGHT
;
205 /* No transition date */
206 retval
= TIME_ZONE_ID_UNKNOWN
;
211 /***********************************************************************
214 * Calculates whether daylight saving is on now.
217 * TIME_ZONE_ID_INVALID An error occurred
218 * TIME_ZONE_ID_UNKNOWN There are no transition time known
219 * TIME_ZONE_ID_STANDARD Current time is standard time
220 * TIME_ZONE_ID_DAYLIGHT Current time is dayligh saving time
222 static DWORD
TIME_ZoneID(
223 const TIME_ZONE_INFORMATION
*pTzi
/* Timezone info */
227 GetSystemTimeAsFileTime( &ftTime
);
228 return TIME_CompTimeZoneID( pTzi
, &ftTime
, FALSE
);
231 /***********************************************************************
232 * TIME_GetTimezoneBias
234 * Calculates the local time bias for a given time zone
238 * Returns TRUE when the time zone bias was calculated.
240 static BOOL
TIME_GetTimezoneBias(
241 const TIME_ZONE_INFORMATION
242 *pTZinfo
, /* [in] The time zone data. */
243 FILETIME
*lpFileTime
, /* [in] The system or local time. */
244 BOOL islocal
, /* [in] it is local time */
245 LONG
*pBias
/* [out] The calculated bias in minutes */
248 LONG bias
= pTZinfo
->Bias
;
249 DWORD tzid
= TIME_CompTimeZoneID( pTZinfo
, lpFileTime
, islocal
);
251 if( tzid
== TIME_ZONE_ID_INVALID
)
253 if (tzid
== TIME_ZONE_ID_DAYLIGHT
)
254 bias
+= pTZinfo
->DaylightBias
;
255 else if (tzid
== TIME_ZONE_ID_STANDARD
)
256 bias
+= pTZinfo
->StandardBias
;
262 /***********************************************************************
263 * SetLocalTime (KERNEL32.@)
265 * Set the local time using current time zone and daylight
269 * Success: TRUE. The time was set
270 * Failure: FALSE, if the time was invalid or caller does not have
271 * permission to change the time.
273 BOOL WINAPI
SetLocalTime(
274 const SYSTEMTIME
*systime
) /* [in] The desired local time. */
277 LARGE_INTEGER st
, st2
;
280 if( !SystemTimeToFileTime( systime
, &ft
))
282 st
.u
.LowPart
= ft
.dwLowDateTime
;
283 st
.u
.HighPart
= ft
.dwHighDateTime
;
284 RtlLocalTimeToSystemTime( &st
, &st2
);
286 if ((status
= NtSetSystemTime(&st2
, NULL
)))
287 SetLastError( RtlNtStatusToDosError(status
) );
292 /***********************************************************************
293 * GetSystemTimeAdjustment (KERNEL32.@)
295 * Get the period between clock interrupts and the amount the clock
296 * is adjusted each interrupt so as to keep it in sync with an external source.
302 * Only the special case of disabled time adjustments is supported.
304 BOOL WINAPI
GetSystemTimeAdjustment(
305 PDWORD lpTimeAdjustment
, /* [out] The clock adjustment per interrupt in 100's of nanoseconds. */
306 PDWORD lpTimeIncrement
, /* [out] The time between clock interrupts in 100's of nanoseconds. */
307 PBOOL lpTimeAdjustmentDisabled
) /* [out] The clock synchronisation has been disabled. */
309 *lpTimeAdjustment
= 0;
310 *lpTimeIncrement
= 0;
311 *lpTimeAdjustmentDisabled
= TRUE
;
316 /***********************************************************************
317 * SetSystemTime (KERNEL32.@)
319 * Set the system time in utc.
322 * Success: TRUE. The time was set
323 * Failure: FALSE, if the time was invalid or caller does not have
324 * permission to change the time.
326 BOOL WINAPI
SetSystemTime(
327 const SYSTEMTIME
*systime
) /* [in] The desired system time. */
333 if( !SystemTimeToFileTime( systime
, &ft
))
335 t
.u
.LowPart
= ft
.dwLowDateTime
;
336 t
.u
.HighPart
= ft
.dwHighDateTime
;
337 if ((status
= NtSetSystemTime(&t
, NULL
)))
338 SetLastError( RtlNtStatusToDosError(status
) );
342 /***********************************************************************
343 * SetSystemTimeAdjustment (KERNEL32.@)
345 * Enables or disables the timing adjustments to the system's clock.
351 BOOL WINAPI
SetSystemTimeAdjustment(
352 DWORD dwTimeAdjustment
,
353 BOOL bTimeAdjustmentDisabled
)
355 /* Fake function for now... */
356 FIXME("(%08lx,%d): stub !\n", dwTimeAdjustment
, bTimeAdjustmentDisabled
);
360 /***********************************************************************
361 * GetTimeZoneInformation (KERNEL32.@)
363 * Get information about the current local time zone.
366 * TIME_ZONE_ID_INVALID An error occurred
367 * TIME_ZONE_ID_UNKNOWN There are no transition time known
368 * TIME_ZONE_ID_STANDARD Current time is standard time
369 * TIME_ZONE_ID_DAYLIGHT Current time is dayligh saving time
371 DWORD WINAPI
GetTimeZoneInformation(
372 LPTIME_ZONE_INFORMATION tzinfo
) /* [out] Destination for time zone information */
376 status
= RtlQueryTimeZoneInformation( (RTL_TIME_ZONE_INFORMATION
*)tzinfo
);
377 if ( status
!= STATUS_SUCCESS
)
379 SetLastError( RtlNtStatusToDosError(status
) );
380 return TIME_ZONE_ID_INVALID
;
382 return TIME_ZoneID( tzinfo
);
385 /***********************************************************************
386 * SetTimeZoneInformation (KERNEL32.@)
388 * Change the settings of the current local time zone.
391 * Success: TRUE. The time zone was updated with the settings from tzinfo
394 BOOL WINAPI
SetTimeZoneInformation(
395 const TIME_ZONE_INFORMATION
*tzinfo
) /* [in] The new time zone. */
398 status
= RtlSetTimeZoneInformation( (RTL_TIME_ZONE_INFORMATION
*) tzinfo
);
399 if ( status
!= STATUS_SUCCESS
)
400 SetLastError( RtlNtStatusToDosError(status
) );
404 /***********************************************************************
405 * SystemTimeToTzSpecificLocalTime (KERNEL32.@)
407 * Convert a utc system time to a local time in a given time zone.
410 * Success: TRUE. lpLocalTime contains the converted time
414 BOOL WINAPI
SystemTimeToTzSpecificLocalTime(
415 LPTIME_ZONE_INFORMATION
416 lpTimeZoneInformation
, /* [in] The desired time zone. */
417 LPSYSTEMTIME lpUniversalTime
, /* [in] The utc time to base local time on. */
418 LPSYSTEMTIME lpLocalTime
) /* [out] The local time in the time zone. */
423 TIME_ZONE_INFORMATION tzinfo
;
425 if (lpTimeZoneInformation
!= NULL
)
427 memcpy(&tzinfo
, lpTimeZoneInformation
, sizeof(TIME_ZONE_INFORMATION
));
431 if (GetTimeZoneInformation(&tzinfo
) == TIME_ZONE_ID_INVALID
)
435 if (!SystemTimeToFileTime(lpUniversalTime
, &ft
))
437 FILETIME2LL( &ft
, llTime
)
438 if (!TIME_GetTimezoneBias(&tzinfo
, &ft
, FALSE
, &lBias
))
440 /* convert minutes to 100-nanoseconds-ticks */
441 llTime
-= (LONGLONG
)lBias
* 600000000;
442 LL2FILETIME( llTime
, &ft
)
444 return FileTimeToSystemTime(&ft
, lpLocalTime
);
448 /***********************************************************************
449 * TzSpecificLocalTimeToSystemTime (KERNEL32.@)
451 * Converts a local time to a time in utc.
454 * Success: TRUE. lpUniversalTime contains the converted time
457 BOOL WINAPI
TzSpecificLocalTimeToSystemTime(
458 LPTIME_ZONE_INFORMATION lpTimeZoneInformation
, /* [in] The desired time zone. */
459 LPSYSTEMTIME lpLocalTime
, /* [in] The local time. */
460 LPSYSTEMTIME lpUniversalTime
) /* [out] The calculated utc time. */
465 TIME_ZONE_INFORMATION tzinfo
;
467 if (lpTimeZoneInformation
!= NULL
)
469 memcpy(&tzinfo
, lpTimeZoneInformation
, sizeof(TIME_ZONE_INFORMATION
));
473 if (GetTimeZoneInformation(&tzinfo
) == TIME_ZONE_ID_INVALID
)
477 if (!SystemTimeToFileTime(lpLocalTime
, &ft
))
480 if (!TIME_GetTimezoneBias(&tzinfo
, &ft
, TRUE
, &lBias
))
482 /* convert minutes to 100-nanoseconds-ticks */
483 t
+= (LONGLONG
)lBias
* 600000000;
485 return FileTimeToSystemTime(&ft
, lpUniversalTime
);
489 /***********************************************************************
490 * GetSystemTimeAsFileTime (KERNEL32.@)
492 * Get the current time in utc format.
497 VOID WINAPI
GetSystemTimeAsFileTime(
498 LPFILETIME time
) /* [out] Destination for the current utc time */
501 NtQuerySystemTime( &t
);
502 time
->dwLowDateTime
= t
.u
.LowPart
;
503 time
->dwHighDateTime
= t
.u
.HighPart
;
507 /*********************************************************************
508 * TIME_ClockTimeToFileTime (olorin@fandra.org, 20-Sep-1998)
510 * Used by GetProcessTimes to convert clock_t into FILETIME.
512 * Differences to UnixTimeToFileTime:
513 * 1) Divided by CLK_TCK
514 * 2) Time is relative. There is no 'starting date', so there is
515 * no need for offset correction, like in UnixTimeToFileTime
517 static void TIME_ClockTimeToFileTime(clock_t unix_time
, LPFILETIME filetime
)
519 ULONGLONG secs
= RtlEnlargedUnsignedMultiply( unix_time
, 10000000 );
520 secs
= RtlExtendedLargeIntegerDivide( secs
, CLK_TCK
, NULL
);
521 filetime
->dwLowDateTime
= (DWORD
)secs
;
522 filetime
->dwHighDateTime
= (DWORD
)(secs
>> 32);
525 /*********************************************************************
526 * GetProcessTimes (KERNEL32.@)
528 * Get the user and kernel execution times of a process,
529 * along with the creation and exit times if known.
536 * Would be nice to subtract the cpu time used by Wine at startup.
537 * Also, there is a need to separate times used by different applications.
540 * lpCreationTime and lpExitTime are not initialised in the Wine implementation.
542 BOOL WINAPI
GetProcessTimes(
543 HANDLE hprocess
, /* [in] The process to be queried (obtained from PROCESS_QUERY_INFORMATION). */
544 LPFILETIME lpCreationTime
, /* [out] The creation time of the process. */
545 LPFILETIME lpExitTime
, /* [out] The exit time of the process if exited. */
546 LPFILETIME lpKernelTime
, /* [out] The time spent in kernel routines in 100's of nanoseconds. */
547 LPFILETIME lpUserTime
) /* [out] The time spent in user routines in 100's of nanoseconds. */
552 TIME_ClockTimeToFileTime(tms
.tms_utime
,lpUserTime
);
553 TIME_ClockTimeToFileTime(tms
.tms_stime
,lpKernelTime
);
557 /*********************************************************************
558 * GetCalendarInfoA (KERNEL32.@)
561 int WINAPI
GetCalendarInfoA(LCID lcid
, CALID Calendar
, CALTYPE CalType
,
562 LPSTR lpCalData
, int cchData
, LPDWORD lpValue
)
565 LPWSTR lpCalDataW
= NULL
;
567 FIXME("(%08lx,%08lx,%08lx,%p,%d,%p): quarter-stub\n",
568 lcid
, Calendar
, CalType
, lpCalData
, cchData
, lpValue
);
570 lcid
= ConvertDefaultLocale(lcid
);
572 if (NLS_IsUnicodeOnlyLcid(lcid
))
574 SetLastError(ERROR_INVALID_PARAMETER
);
579 !(lpCalDataW
= HeapAlloc(GetProcessHeap(), 0, cchData
*sizeof(WCHAR
))))
582 ret
= GetCalendarInfoW(lcid
, Calendar
, CalType
, lpCalDataW
, cchData
, lpValue
);
583 if(ret
&& lpCalDataW
&& lpCalData
)
584 WideCharToMultiByte(CP_ACP
, 0, lpCalDataW
, cchData
, lpCalData
, cchData
, NULL
, NULL
);
585 HeapFree(GetProcessHeap(), 0, lpCalDataW
);
590 /*********************************************************************
591 * GetCalendarInfoW (KERNEL32.@)
593 * See GetCalendarInfoA.
595 int WINAPI
GetCalendarInfoW(LCID Locale
, CALID Calendar
, CALTYPE CalType
,
596 LPWSTR lpCalData
, int cchData
, LPDWORD lpValue
)
598 FIXME("(%08lx,%08lx,%08lx,%p,%d,%p): quarter-stub\n",
599 Locale
, Calendar
, CalType
, lpCalData
, cchData
, lpValue
);
601 if (CalType
& CAL_NOUSEROVERRIDE
)
602 FIXME("flag CAL_NOUSEROVERRIDE used, not fully implemented\n");
603 if (CalType
& CAL_USE_CP_ACP
)
604 FIXME("flag CAL_USE_CP_ACP used, not fully implemented\n");
606 if (CalType
& CAL_RETURN_NUMBER
) {
607 if (lpCalData
!= NULL
)
608 WARN("lpCalData not NULL (%p) when it should!\n", lpCalData
);
610 WARN("cchData not 0 (%d) when it should!\n", cchData
);
613 WARN("lpValue not NULL (%p) when it should!\n", lpValue
);
616 /* FIXME: No verification is made yet wrt Locale
617 * for the CALTYPES not requiring GetLocaleInfoA */
618 switch (CalType
& ~(CAL_NOUSEROVERRIDE
|CAL_RETURN_NUMBER
|CAL_USE_CP_ACP
)) {
619 case CAL_ICALINTVALUE
:
620 FIXME("Unimplemented caltype %ld\n", CalType
& 0xffff);
623 FIXME("Unimplemented caltype %ld\n", CalType
& 0xffff);
625 case CAL_IYEAROFFSETRANGE
:
626 FIXME("Unimplemented caltype %ld\n", CalType
& 0xffff);
629 FIXME("Unimplemented caltype %ld\n", CalType
& 0xffff);
632 return GetLocaleInfoW(Locale
, LOCALE_SSHORTDATE
, lpCalData
, cchData
);
634 return GetLocaleInfoW(Locale
, LOCALE_SLONGDATE
, lpCalData
, cchData
);
636 return GetLocaleInfoW(Locale
, LOCALE_SDAYNAME1
, lpCalData
, cchData
);
638 return GetLocaleInfoW(Locale
, LOCALE_SDAYNAME2
, lpCalData
, cchData
);
640 return GetLocaleInfoW(Locale
, LOCALE_SDAYNAME3
, lpCalData
, cchData
);
642 return GetLocaleInfoW(Locale
, LOCALE_SDAYNAME4
, lpCalData
, cchData
);
644 return GetLocaleInfoW(Locale
, LOCALE_SDAYNAME5
, lpCalData
, cchData
);
646 return GetLocaleInfoW(Locale
, LOCALE_SDAYNAME6
, lpCalData
, cchData
);
648 return GetLocaleInfoW(Locale
, LOCALE_SDAYNAME7
, lpCalData
, cchData
);
649 case CAL_SABBREVDAYNAME1
:
650 return GetLocaleInfoW(Locale
, LOCALE_SABBREVDAYNAME1
, lpCalData
, cchData
);
651 case CAL_SABBREVDAYNAME2
:
652 return GetLocaleInfoW(Locale
, LOCALE_SABBREVDAYNAME2
, lpCalData
, cchData
);
653 case CAL_SABBREVDAYNAME3
:
654 return GetLocaleInfoW(Locale
, LOCALE_SABBREVDAYNAME3
, lpCalData
, cchData
);
655 case CAL_SABBREVDAYNAME4
:
656 return GetLocaleInfoW(Locale
, LOCALE_SABBREVDAYNAME4
, lpCalData
, cchData
);
657 case CAL_SABBREVDAYNAME5
:
658 return GetLocaleInfoW(Locale
, LOCALE_SABBREVDAYNAME5
, lpCalData
, cchData
);
659 case CAL_SABBREVDAYNAME6
:
660 return GetLocaleInfoW(Locale
, LOCALE_SABBREVDAYNAME6
, lpCalData
, cchData
);
661 case CAL_SABBREVDAYNAME7
:
662 return GetLocaleInfoW(Locale
, LOCALE_SABBREVDAYNAME7
, lpCalData
, cchData
);
663 case CAL_SMONTHNAME1
:
664 return GetLocaleInfoW(Locale
, LOCALE_SMONTHNAME1
, lpCalData
, cchData
);
665 case CAL_SMONTHNAME2
:
666 return GetLocaleInfoW(Locale
, LOCALE_SMONTHNAME2
, lpCalData
, cchData
);
667 case CAL_SMONTHNAME3
:
668 return GetLocaleInfoW(Locale
, LOCALE_SMONTHNAME3
, lpCalData
, cchData
);
669 case CAL_SMONTHNAME4
:
670 return GetLocaleInfoW(Locale
, LOCALE_SMONTHNAME4
, lpCalData
, cchData
);
671 case CAL_SMONTHNAME5
:
672 return GetLocaleInfoW(Locale
, LOCALE_SMONTHNAME5
, lpCalData
, cchData
);
673 case CAL_SMONTHNAME6
:
674 return GetLocaleInfoW(Locale
, LOCALE_SMONTHNAME6
, lpCalData
, cchData
);
675 case CAL_SMONTHNAME7
:
676 return GetLocaleInfoW(Locale
, LOCALE_SMONTHNAME7
, lpCalData
, cchData
);
677 case CAL_SMONTHNAME8
:
678 return GetLocaleInfoW(Locale
, LOCALE_SMONTHNAME8
, lpCalData
, cchData
);
679 case CAL_SMONTHNAME9
:
680 return GetLocaleInfoW(Locale
, LOCALE_SMONTHNAME9
, lpCalData
, cchData
);
681 case CAL_SMONTHNAME10
:
682 return GetLocaleInfoW(Locale
, LOCALE_SMONTHNAME10
, lpCalData
, cchData
);
683 case CAL_SMONTHNAME11
:
684 return GetLocaleInfoW(Locale
, LOCALE_SMONTHNAME11
, lpCalData
, cchData
);
685 case CAL_SMONTHNAME12
:
686 return GetLocaleInfoW(Locale
, LOCALE_SMONTHNAME12
, lpCalData
, cchData
);
687 case CAL_SMONTHNAME13
:
688 return GetLocaleInfoW(Locale
, LOCALE_SMONTHNAME13
, lpCalData
, cchData
);
689 case CAL_SABBREVMONTHNAME1
:
690 return GetLocaleInfoW(Locale
, LOCALE_SABBREVMONTHNAME1
, lpCalData
, cchData
);
691 case CAL_SABBREVMONTHNAME2
:
692 return GetLocaleInfoW(Locale
, LOCALE_SABBREVMONTHNAME2
, lpCalData
, cchData
);
693 case CAL_SABBREVMONTHNAME3
:
694 return GetLocaleInfoW(Locale
, LOCALE_SABBREVMONTHNAME3
, lpCalData
, cchData
);
695 case CAL_SABBREVMONTHNAME4
:
696 return GetLocaleInfoW(Locale
, LOCALE_SABBREVMONTHNAME4
, lpCalData
, cchData
);
697 case CAL_SABBREVMONTHNAME5
:
698 return GetLocaleInfoW(Locale
, LOCALE_SABBREVMONTHNAME5
, lpCalData
, cchData
);
699 case CAL_SABBREVMONTHNAME6
:
700 return GetLocaleInfoW(Locale
, LOCALE_SABBREVMONTHNAME6
, lpCalData
, cchData
);
701 case CAL_SABBREVMONTHNAME7
:
702 return GetLocaleInfoW(Locale
, LOCALE_SABBREVMONTHNAME7
, lpCalData
, cchData
);
703 case CAL_SABBREVMONTHNAME8
:
704 return GetLocaleInfoW(Locale
, LOCALE_SABBREVMONTHNAME8
, lpCalData
, cchData
);
705 case CAL_SABBREVMONTHNAME9
:
706 return GetLocaleInfoW(Locale
, LOCALE_SABBREVMONTHNAME9
, lpCalData
, cchData
);
707 case CAL_SABBREVMONTHNAME10
:
708 return GetLocaleInfoW(Locale
, LOCALE_SABBREVMONTHNAME10
, lpCalData
, cchData
);
709 case CAL_SABBREVMONTHNAME11
:
710 return GetLocaleInfoW(Locale
, LOCALE_SABBREVMONTHNAME11
, lpCalData
, cchData
);
711 case CAL_SABBREVMONTHNAME12
:
712 return GetLocaleInfoW(Locale
, LOCALE_SABBREVMONTHNAME12
, lpCalData
, cchData
);
713 case CAL_SABBREVMONTHNAME13
:
714 return GetLocaleInfoW(Locale
, LOCALE_SABBREVMONTHNAME13
, lpCalData
, cchData
);
716 return GetLocaleInfoW(Locale
, LOCALE_SYEARMONTH
, lpCalData
, cchData
);
717 case CAL_ITWODIGITYEARMAX
:
718 if (lpValue
) *lpValue
= CALINFO_MAX_YEAR
;
720 default: MESSAGE("Unknown caltype %ld\n",CalType
& 0xffff);
726 /*********************************************************************
727 * SetCalendarInfoA (KERNEL32.@)
730 int WINAPI
SetCalendarInfoA(LCID Locale
, CALID Calendar
, CALTYPE CalType
, LPCSTR lpCalData
)
732 FIXME("(%08lx,%08lx,%08lx,%s): stub\n",
733 Locale
, Calendar
, CalType
, debugstr_a(lpCalData
));
737 /*********************************************************************
738 * SetCalendarInfoW (KERNEL32.@)
740 * See SetCalendarInfoA.
742 int WINAPI
SetCalendarInfoW(LCID Locale
, CALID Calendar
, CALTYPE CalType
, LPCWSTR lpCalData
)
744 FIXME("(%08lx,%08lx,%08lx,%s): stub\n",
745 Locale
, Calendar
, CalType
, debugstr_w(lpCalData
));
749 /*********************************************************************
750 * LocalFileTimeToFileTime (KERNEL32.@)
752 BOOL WINAPI
LocalFileTimeToFileTime( const FILETIME
*localft
, LPFILETIME utcft
)
755 LARGE_INTEGER local
, utc
;
757 local
.u
.LowPart
= localft
->dwLowDateTime
;
758 local
.u
.HighPart
= localft
->dwHighDateTime
;
759 if (!(status
= RtlLocalTimeToSystemTime( &local
, &utc
)))
761 utcft
->dwLowDateTime
= utc
.u
.LowPart
;
762 utcft
->dwHighDateTime
= utc
.u
.HighPart
;
764 else SetLastError( RtlNtStatusToDosError(status
) );
769 /*********************************************************************
770 * FileTimeToLocalFileTime (KERNEL32.@)
772 BOOL WINAPI
FileTimeToLocalFileTime( const FILETIME
*utcft
, LPFILETIME localft
)
775 LARGE_INTEGER local
, utc
;
777 utc
.u
.LowPart
= utcft
->dwLowDateTime
;
778 utc
.u
.HighPart
= utcft
->dwHighDateTime
;
779 if (!(status
= RtlSystemTimeToLocalTime( &utc
, &local
)))
781 localft
->dwLowDateTime
= local
.u
.LowPart
;
782 localft
->dwHighDateTime
= local
.u
.HighPart
;
784 else SetLastError( RtlNtStatusToDosError(status
) );
789 /*********************************************************************
790 * FileTimeToSystemTime (KERNEL32.@)
792 BOOL WINAPI
FileTimeToSystemTime( const FILETIME
*ft
, LPSYSTEMTIME syst
)
797 t
.u
.LowPart
= ft
->dwLowDateTime
;
798 t
.u
.HighPart
= ft
->dwHighDateTime
;
799 RtlTimeToTimeFields(&t
, &tf
);
801 syst
->wYear
= tf
.Year
;
802 syst
->wMonth
= tf
.Month
;
804 syst
->wHour
= tf
.Hour
;
805 syst
->wMinute
= tf
.Minute
;
806 syst
->wSecond
= tf
.Second
;
807 syst
->wMilliseconds
= tf
.Milliseconds
;
808 syst
->wDayOfWeek
= tf
.Weekday
;
812 /*********************************************************************
813 * SystemTimeToFileTime (KERNEL32.@)
815 BOOL WINAPI
SystemTimeToFileTime( const SYSTEMTIME
*syst
, LPFILETIME ft
)
820 tf
.Year
= syst
->wYear
;
821 tf
.Month
= syst
->wMonth
;
823 tf
.Hour
= syst
->wHour
;
824 tf
.Minute
= syst
->wMinute
;
825 tf
.Second
= syst
->wSecond
;
826 tf
.Milliseconds
= syst
->wMilliseconds
;
828 if( !RtlTimeFieldsToTime(&tf
, &t
)) {
829 SetLastError( ERROR_INVALID_PARAMETER
);
832 ft
->dwLowDateTime
= t
.u
.LowPart
;
833 ft
->dwHighDateTime
= t
.u
.HighPart
;
837 /*********************************************************************
838 * CompareFileTime (KERNEL32.@)
840 * Compare two FILETIME's to each other.
844 * y [I] time to compare to x
847 * -1, 0, or 1 indicating that x is less than, equal to, or greater
848 * than y respectively.
850 INT WINAPI
CompareFileTime( const FILETIME
*x
, const FILETIME
*y
)
852 if (!x
|| !y
) return -1;
854 if (x
->dwHighDateTime
> y
->dwHighDateTime
)
856 if (x
->dwHighDateTime
< y
->dwHighDateTime
)
858 if (x
->dwLowDateTime
> y
->dwLowDateTime
)
860 if (x
->dwLowDateTime
< y
->dwLowDateTime
)
865 /*********************************************************************
866 * GetLocalTime (KERNEL32.@)
868 * Get the current local time.
873 VOID WINAPI
GetLocalTime(LPSYSTEMTIME systime
) /* [O] Destination for current time */
876 LARGE_INTEGER ft
, ft2
;
878 NtQuerySystemTime(&ft
);
879 RtlSystemTimeToLocalTime(&ft
, &ft2
);
880 lft
.dwLowDateTime
= ft2
.u
.LowPart
;
881 lft
.dwHighDateTime
= ft2
.u
.HighPart
;
882 FileTimeToSystemTime(&lft
, systime
);
885 /*********************************************************************
886 * GetSystemTime (KERNEL32.@)
888 * Get the current system time.
893 VOID WINAPI
GetSystemTime(LPSYSTEMTIME systime
) /* [O] Destination for current time */
898 NtQuerySystemTime(&t
);
899 ft
.dwLowDateTime
= t
.u
.LowPart
;
900 ft
.dwHighDateTime
= t
.u
.HighPart
;
901 FileTimeToSystemTime(&ft
, systime
);
904 /*********************************************************************
905 * GetDaylightFlag (KERNEL32.@)
907 * returns TRUE if daylight saving time is in operation
909 * Note: this function is called from the Win98's control applet
912 BOOL WINAPI
GetDaylightFlag(void)
914 TIME_ZONE_INFORMATION tzinfo
;
915 return GetTimeZoneInformation( &tzinfo
) == TIME_ZONE_ID_DAYLIGHT
;
918 /***********************************************************************
919 * DosDateTimeToFileTime (KERNEL32.@)
921 BOOL WINAPI
DosDateTimeToFileTime( WORD fatdate
, WORD fattime
, LPFILETIME ft
)
929 newtm
.tm_sec
= (fattime
& 0x1f) * 2;
930 newtm
.tm_min
= (fattime
>> 5) & 0x3f;
931 newtm
.tm_hour
= (fattime
>> 11);
932 newtm
.tm_mday
= (fatdate
& 0x1f);
933 newtm
.tm_mon
= ((fatdate
>> 5) & 0x0f) - 1;
934 newtm
.tm_year
= (fatdate
>> 9) + 80;
936 RtlSecondsSince1970ToTime( timegm(&newtm
), (LARGE_INTEGER
*)ft
);
938 time1
= mktime(&newtm
);
939 gtm
= gmtime(&time1
);
941 RtlSecondsSince1970ToTime( 2*time1
-time2
, (LARGE_INTEGER
*)ft
);
947 /***********************************************************************
948 * FileTimeToDosDateTime (KERNEL32.@)
950 BOOL WINAPI
FileTimeToDosDateTime( const FILETIME
*ft
, LPWORD fatdate
,
958 li
.u
.LowPart
= ft
->dwLowDateTime
;
959 li
.u
.HighPart
= ft
->dwHighDateTime
;
960 RtlTimeToSecondsSince1970( &li
, &t
);
962 tm
= gmtime( &unixtime
);
964 *fattime
= (tm
->tm_hour
<< 11) + (tm
->tm_min
<< 5) + (tm
->tm_sec
/ 2);
966 *fatdate
= ((tm
->tm_year
- 80) << 9) + ((tm
->tm_mon
+ 1) << 5)