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
28 #ifdef HAVE_SYS_TIME_H
29 # include <sys/time.h>
31 #ifdef HAVE_SYS_TIMES_H
32 # include <sys/times.h>
35 #define NONAMELESSUNION
36 #define NONAMELESSSTRUCT
42 #include "wine/unicode.h"
43 #include "wine/debug.h"
45 WINE_DEFAULT_DEBUG_CHANNEL(win32
);
47 /* maximum time adjustment in seconds for SetLocalTime and SetSystemTime */
48 #define SETTIME_MAX_ADJUST 120
49 #define CALINFO_MAX_YEAR 2029
52 /***********************************************************************
53 * SetLocalTime (KERNEL32.@)
55 * Set the local time using current time zone and daylight
59 * Success: TRUE. The time was set
60 * Failure: FALSE, if the time was invalid or caller does not have
61 * permission to change the time.
63 BOOL WINAPI
SetLocalTime(
64 const SYSTEMTIME
*systime
) /* [in] The desired local time. */
67 LARGE_INTEGER st
, st2
;
70 SystemTimeToFileTime( systime
, &ft
);
71 st
.s
.LowPart
= ft
.dwLowDateTime
;
72 st
.s
.HighPart
= ft
.dwHighDateTime
;
73 RtlLocalTimeToSystemTime( &st
, &st2
);
75 if ((status
= NtSetSystemTime(&st2
, NULL
)))
76 SetLastError( RtlNtStatusToDosError(status
) );
81 /***********************************************************************
82 * GetSystemTimeAdjustment (KERNEL32.@)
84 * Get the period between clock interrupts and the amount the clock
85 * is adjusted each interrupt so as to keep it in sync with an external source.
91 * Only the special case of disabled time adjustments is supported.
93 BOOL WINAPI
GetSystemTimeAdjustment(
94 PDWORD lpTimeAdjustment
, /* [out] The clock adjustment per interupt in 100's of nanoseconds. */
95 PDWORD lpTimeIncrement
, /* [out] The time between clock interupts in 100's of nanoseconds. */
96 PBOOL lpTimeAdjustmentDisabled
) /* [out] The clock synchonisation has been disabled. */
98 *lpTimeAdjustment
= 0;
100 *lpTimeAdjustmentDisabled
= TRUE
;
105 /***********************************************************************
106 * SetSystemTime (KERNEL32.@)
108 * Set the system time in utc.
111 * Success: TRUE. The time was set
112 * Failure: FALSE, if the time was invalid or caller does not have
113 * permission to change the time.
115 BOOL WINAPI
SetSystemTime(
116 const SYSTEMTIME
*systime
) /* [in] The desired system time. */
122 SystemTimeToFileTime( systime
, &ft
);
123 t
.s
.LowPart
= ft
.dwLowDateTime
;
124 t
.s
.HighPart
= ft
.dwHighDateTime
;
125 if ((status
= NtSetSystemTime(&t
, NULL
)))
126 SetLastError( RtlNtStatusToDosError(status
) );
130 /***********************************************************************
131 * SetSystemTimeAdjustment (KERNEL32.@)
133 * Enables or disables the timing adjustments to the system's clock.
139 BOOL WINAPI
SetSystemTimeAdjustment(
140 DWORD dwTimeAdjustment
,
141 BOOL bTimeAdjustmentDisabled
)
143 /* Fake function for now... */
144 FIXME("(%08lx,%d): stub !\n", dwTimeAdjustment
, bTimeAdjustmentDisabled
);
149 /***********************************************************************
150 * GetTimeZoneInformation (KERNEL32.@)
152 * Get information about the current local time zone.
155 * Success: TIME_ZONE_ID_STANDARD. tzinfo contains the time zone info.
156 * Failure: TIME_ZONE_ID_INVALID.
158 DWORD WINAPI
GetTimeZoneInformation(
159 LPTIME_ZONE_INFORMATION tzinfo
) /* [out] Destination for time zone information */
162 if ((status
= RtlQueryTimeZoneInformation(tzinfo
)))
163 SetLastError( RtlNtStatusToDosError(status
) );
164 return TIME_ZONE_ID_STANDARD
;
168 /***********************************************************************
169 * SetTimeZoneInformation (KERNEL32.@)
171 * Change the settings of the current local time zone.
174 * Success: TRUE. The time zone was updated with the settings from tzinfo
177 BOOL WINAPI
SetTimeZoneInformation(
178 const LPTIME_ZONE_INFORMATION tzinfo
) /* [in] The new time zone. */
181 if ((status
= RtlSetTimeZoneInformation(tzinfo
)))
182 SetLastError( RtlNtStatusToDosError(status
) );
187 /***********************************************************************
188 * _DayLightCompareDate
190 * Compares two dates without looking at the year
194 * -1 if date < compareDate
195 * 0 if date == compareDate
196 * 1 if date > compareDate
197 * -2 if an error occures
200 static int _DayLightCompareDate(
201 const LPSYSTEMTIME date
, /* [in] The date to compare. */
202 const LPSYSTEMTIME compareDate
) /* [in] The daylight saving begin or end date */
206 if (compareDate
->wYear
!= 0)
208 if (date
->wMonth
< compareDate
->wMonth
)
209 return -1; /* We are in a year before the date limit. */
211 if (date
->wMonth
> compareDate
->wMonth
)
212 return 1; /* We are in a year after the date limit. */
215 if (date
->wMonth
< compareDate
->wMonth
)
216 return -1; /* We are in a month before the date limit. */
218 if (date
->wMonth
> compareDate
->wMonth
)
219 return 1; /* We are in a month after the date limit. */
221 if (compareDate
->wDayOfWeek
<= 6)
226 /* compareDate->wDay is interpreted as number of the week in the month. */
227 /* 5 means: the last week in the month */
228 int weekofmonth
= compareDate
->wDay
;
230 /* calculate day of week for the first day in the month */
231 memcpy(&tmp
, date
, sizeof(SYSTEMTIME
));
235 if (weekofmonth
== 5)
237 /* Go to the beginning of the next month. */
238 if (++tmp
.wMonth
> 12)
245 if (!SystemTimeToFileTime(&tmp
, &tmp_ft
))
248 if (weekofmonth
== 5)
252 t
= tmp_ft
.dwHighDateTime
;
254 t
+= (UINT
)tmp_ft
.dwLowDateTime
;
256 /* subtract one day */
261 tmp_ft
.dwLowDateTime
= (UINT
)t
;
262 tmp_ft
.dwHighDateTime
= (UINT
)(t
>> 32);
265 if (!FileTimeToSystemTime(&tmp_ft
, &tmp
))
268 if (weekofmonth
== 5)
270 /* calculate the last matching day of the week in this month */
271 int dif
= tmp
.wDayOfWeek
- compareDate
->wDayOfWeek
;
275 limit_day
= tmp
.wDay
- dif
;
279 /* calculate the matching day of the week in the given week */
280 int dif
= compareDate
->wDayOfWeek
- tmp
.wDayOfWeek
;
284 limit_day
= tmp
.wDay
+ 7*(weekofmonth
-1) + dif
;
289 limit_day
= compareDate
->wDay
;
292 if (date
->wDay
< limit_day
)
295 if (date
->wDay
> limit_day
)
298 return 0; /* date is equal to the date limit. */
302 /***********************************************************************
305 * Calculates the local time bias for a given time zone
309 * Returns TRUE when the time zone bias was calculated.
312 static BOOL
_GetTimezoneBias(
313 const LPTIME_ZONE_INFORMATION lpTimeZoneInformation
, /* [in] The time zone data. */
314 LPSYSTEMTIME lpSystemTime
, /* [in] The system time. */
315 LONG
* pBias
) /* [out] The calulated bias in minutes */
318 BOOL beforeStandardDate
, afterDaylightDate
;
319 BOOL daylightsaving
= FALSE
;
320 LONG bias
= lpTimeZoneInformation
->Bias
;
322 if (lpTimeZoneInformation
->DaylightDate
.wMonth
!= 0)
324 if (lpTimeZoneInformation
->StandardDate
.wMonth
== 0 ||
325 lpTimeZoneInformation
->StandardDate
.wDay
<1 ||
326 lpTimeZoneInformation
->StandardDate
.wDay
>5 ||
327 lpTimeZoneInformation
->DaylightDate
.wDay
<1 ||
328 lpTimeZoneInformation
->DaylightDate
.wDay
>5)
330 SetLastError(ERROR_INVALID_PARAMETER
);
334 /* check for daylight saving */
335 ret
= _DayLightCompareDate(lpSystemTime
, &lpTimeZoneInformation
->StandardDate
);
339 beforeStandardDate
= ret
< 0;
341 ret
= _DayLightCompareDate(lpSystemTime
, &lpTimeZoneInformation
->DaylightDate
);
345 afterDaylightDate
= ret
>= 0;
347 if (beforeStandardDate
&& afterDaylightDate
)
348 daylightsaving
= TRUE
;
352 bias
+= lpTimeZoneInformation
->DaylightBias
;
353 else if (lpTimeZoneInformation
->StandardDate
.wMonth
!= 0)
354 bias
+= lpTimeZoneInformation
->StandardBias
;
362 /***********************************************************************
363 * SystemTimeToTzSpecificLocalTime (KERNEL32.@)
365 * Convert a utc system time to a local time in a given time zone.
368 * Success: TRUE. lpLocalTime contains the converted time
372 BOOL WINAPI
SystemTimeToTzSpecificLocalTime(
373 LPTIME_ZONE_INFORMATION lpTimeZoneInformation
, /* [in] The desired time zone. */
374 LPSYSTEMTIME lpUniversalTime
, /* [in] The utc time to base local time on. */
375 LPSYSTEMTIME lpLocalTime
) /* [out] The local time in the time zone. */
380 TIME_ZONE_INFORMATION tzinfo
;
382 if (lpTimeZoneInformation
!= NULL
)
384 memcpy(&tzinfo
, lpTimeZoneInformation
, sizeof(TIME_ZONE_INFORMATION
));
388 if (GetTimeZoneInformation(&tzinfo
) == TIME_ZONE_ID_INVALID
)
392 if (!SystemTimeToFileTime(lpUniversalTime
, &ft
))
395 t
= ft
.dwHighDateTime
;
397 t
+= (UINT
)ft
.dwLowDateTime
;
399 if (!_GetTimezoneBias(&tzinfo
, lpUniversalTime
, &lBias
))
402 bias
= (LONGLONG
)lBias
* 600000000; /* 60 seconds per minute, 100000 [100-nanoseconds-ticks] per second */
405 ft
.dwLowDateTime
= (UINT
)t
;
406 ft
.dwHighDateTime
= (UINT
)(t
>> 32);
408 return FileTimeToSystemTime(&ft
, lpLocalTime
);
412 /***********************************************************************
413 * TzSpecificLocalTimeToSystemTime (KERNEL32.@)
415 * Converts a local time to a time in utc.
418 * Success: TRUE. lpUniversalTime contains the converted time
421 BOOL WINAPI
TzSpecificLocalTimeToSystemTime(
422 LPTIME_ZONE_INFORMATION lpTimeZoneInformation
, /* [in] The desired time zone. */
423 LPSYSTEMTIME lpLocalTime
, /* [in] The local time. */
424 LPSYSTEMTIME lpUniversalTime
) /* [out] The calculated utc time. */
429 TIME_ZONE_INFORMATION tzinfo
;
431 if (lpTimeZoneInformation
!= NULL
)
433 memcpy(&tzinfo
, lpTimeZoneInformation
, sizeof(TIME_ZONE_INFORMATION
));
437 if (GetTimeZoneInformation(&tzinfo
) == TIME_ZONE_ID_INVALID
)
441 if (!SystemTimeToFileTime(lpLocalTime
, &ft
))
444 t
= ft
.dwHighDateTime
;
446 t
+= (UINT
)ft
.dwLowDateTime
;
448 if (!_GetTimezoneBias(&tzinfo
, lpLocalTime
, &lBias
))
451 bias
= (LONGLONG
)lBias
* 600000000; /* 60 seconds per minute, 100000 [100-nanoseconds-ticks] per second */
454 ft
.dwLowDateTime
= (UINT
)t
;
455 ft
.dwHighDateTime
= (UINT
)(t
>> 32);
457 return FileTimeToSystemTime(&ft
, lpUniversalTime
);
461 /***********************************************************************
462 * GetSystemTimeAsFileTime (KERNEL32.@)
464 * Get the current time in utc format.
469 VOID WINAPI
GetSystemTimeAsFileTime(
470 LPFILETIME time
) /* [out] Destination for the current utc time */
473 NtQuerySystemTime( &t
);
474 time
->dwLowDateTime
= t
.s
.LowPart
;
475 time
->dwHighDateTime
= t
.s
.HighPart
;
479 /*********************************************************************
480 * TIME_ClockTimeToFileTime (olorin@fandra.org, 20-Sep-1998)
482 * Used by GetProcessTimes to convert clock_t into FILETIME.
484 * Differences to UnixTimeToFileTime:
485 * 1) Divided by CLK_TCK
486 * 2) Time is relative. There is no 'starting date', so there is
487 * no need for offset correction, like in UnixTimeToFileTime
489 static void TIME_ClockTimeToFileTime(clock_t unix_time
, LPFILETIME filetime
)
491 ULONGLONG secs
= RtlEnlargedUnsignedMultiply( unix_time
, 10000000 );
492 secs
= RtlExtendedLargeIntegerDivide( secs
, CLK_TCK
, NULL
);
493 filetime
->dwLowDateTime
= (DWORD
)secs
;
494 filetime
->dwHighDateTime
= (DWORD
)(secs
>> 32);
497 /*********************************************************************
498 * GetProcessTimes (KERNEL32.@)
500 * Get the user and kernel execution times of a process,
501 * along with the creation and exit times if known.
508 * Would be nice to subtract the cpu time used by Wine at startup.
509 * Also, there is a need to separate times used by different applications.
512 * lpCreationTime and lpExitTime are not initialised in the Wine implementation.
514 BOOL WINAPI
GetProcessTimes(
515 HANDLE hprocess
, /* [in] The process to be queried (obtained from PROCESS_QUERY_INFORMATION). */
516 LPFILETIME lpCreationTime
, /* [out] The creation time of the process. */
517 LPFILETIME lpExitTime
, /* [out] The exit time of the process if exited. */
518 LPFILETIME lpKernelTime
, /* [out] The time spent in kernal routines in 100's of nanoseconds. */
519 LPFILETIME lpUserTime
) /* [out] The time spent in user routines in 100's of nanoseconds. */
524 TIME_ClockTimeToFileTime(tms
.tms_utime
,lpUserTime
);
525 TIME_ClockTimeToFileTime(tms
.tms_stime
,lpKernelTime
);
529 /*********************************************************************
530 * GetCalendarInfoA (KERNEL32.@)
533 int WINAPI
GetCalendarInfoA(LCID Locale
, CALID Calendar
, CALTYPE CalType
,
534 LPSTR lpCalData
, int cchData
, LPDWORD lpValue
)
537 LPWSTR lpCalDataW
= NULL
;
539 FIXME("(%08lx,%08lx,%08lx,%p,%d,%p): quarter-stub\n",
540 Locale
, Calendar
, CalType
, lpCalData
, cchData
, lpValue
);
541 /* FIXME: Should verify if Locale is allowable in ANSI, as per MSDN */
544 if(!(lpCalDataW
= HeapAlloc(GetProcessHeap(), 0, cchData
*sizeof(WCHAR
)))) return 0;
546 ret
= GetCalendarInfoW(Locale
, Calendar
, CalType
, lpCalDataW
, cchData
, lpValue
);
547 if(ret
&& lpCalDataW
&& lpCalData
)
548 WideCharToMultiByte(CP_ACP
, 0, lpCalDataW
, cchData
, lpCalData
, cchData
, NULL
, NULL
);
550 HeapFree(GetProcessHeap(), 0, lpCalDataW
);
555 /*********************************************************************
556 * GetCalendarInfoW (KERNEL32.@)
558 * See GetCalendarInfoA.
560 int WINAPI
GetCalendarInfoW(LCID Locale
, CALID Calendar
, CALTYPE CalType
,
561 LPWSTR lpCalData
, int cchData
, LPDWORD lpValue
)
563 FIXME("(%08lx,%08lx,%08lx,%p,%d,%p): quarter-stub\n",
564 Locale
, Calendar
, CalType
, lpCalData
, cchData
, lpValue
);
566 if (CalType
& CAL_NOUSEROVERRIDE
)
567 FIXME("flag CAL_NOUSEROVERRIDE used, not fully implemented\n");
568 if (CalType
& CAL_USE_CP_ACP
)
569 FIXME("flag CAL_USE_CP_ACP used, not fully implemented\n");
571 if (CalType
& CAL_RETURN_NUMBER
) {
572 if (lpCalData
!= NULL
)
573 WARN("lpCalData not NULL (%p) when it should!\n", lpCalData
);
575 WARN("cchData not 0 (%d) when it should!\n", cchData
);
578 WARN("lpValue not NULL (%p) when it should!\n", lpValue
);
581 /* FIXME: No verification is made yet wrt Locale
582 * for the CALTYPES not requiring GetLocaleInfoA */
583 switch (CalType
& ~(CAL_NOUSEROVERRIDE
|CAL_RETURN_NUMBER
|CAL_USE_CP_ACP
)) {
584 case CAL_ICALINTVALUE
:
585 FIXME("Unimplemented caltype %ld\n", CalType
& 0xffff);
588 FIXME("Unimplemented caltype %ld\n", CalType
& 0xffff);
590 case CAL_IYEAROFFSETRANGE
:
591 FIXME("Unimplemented caltype %ld\n", CalType
& 0xffff);
594 FIXME("Unimplemented caltype %ld\n", CalType
& 0xffff);
597 return GetLocaleInfoW(Locale
, LOCALE_SSHORTDATE
, lpCalData
, cchData
);
599 return GetLocaleInfoW(Locale
, LOCALE_SLONGDATE
, lpCalData
, cchData
);
601 return GetLocaleInfoW(Locale
, LOCALE_SDAYNAME1
, lpCalData
, cchData
);
603 return GetLocaleInfoW(Locale
, LOCALE_SDAYNAME2
, lpCalData
, cchData
);
605 return GetLocaleInfoW(Locale
, LOCALE_SDAYNAME3
, lpCalData
, cchData
);
607 return GetLocaleInfoW(Locale
, LOCALE_SDAYNAME4
, lpCalData
, cchData
);
609 return GetLocaleInfoW(Locale
, LOCALE_SDAYNAME5
, lpCalData
, cchData
);
611 return GetLocaleInfoW(Locale
, LOCALE_SDAYNAME6
, lpCalData
, cchData
);
613 return GetLocaleInfoW(Locale
, LOCALE_SDAYNAME7
, lpCalData
, cchData
);
614 case CAL_SABBREVDAYNAME1
:
615 return GetLocaleInfoW(Locale
, LOCALE_SABBREVDAYNAME1
, lpCalData
, cchData
);
616 case CAL_SABBREVDAYNAME2
:
617 return GetLocaleInfoW(Locale
, LOCALE_SABBREVDAYNAME2
, lpCalData
, cchData
);
618 case CAL_SABBREVDAYNAME3
:
619 return GetLocaleInfoW(Locale
, LOCALE_SABBREVDAYNAME3
, lpCalData
, cchData
);
620 case CAL_SABBREVDAYNAME4
:
621 return GetLocaleInfoW(Locale
, LOCALE_SABBREVDAYNAME4
, lpCalData
, cchData
);
622 case CAL_SABBREVDAYNAME5
:
623 return GetLocaleInfoW(Locale
, LOCALE_SABBREVDAYNAME5
, lpCalData
, cchData
);
624 case CAL_SABBREVDAYNAME6
:
625 return GetLocaleInfoW(Locale
, LOCALE_SABBREVDAYNAME6
, lpCalData
, cchData
);
626 case CAL_SABBREVDAYNAME7
:
627 return GetLocaleInfoW(Locale
, LOCALE_SABBREVDAYNAME7
, lpCalData
, cchData
);
628 case CAL_SMONTHNAME1
:
629 return GetLocaleInfoW(Locale
, LOCALE_SMONTHNAME1
, lpCalData
, cchData
);
630 case CAL_SMONTHNAME2
:
631 return GetLocaleInfoW(Locale
, LOCALE_SMONTHNAME2
, lpCalData
, cchData
);
632 case CAL_SMONTHNAME3
:
633 return GetLocaleInfoW(Locale
, LOCALE_SMONTHNAME3
, lpCalData
, cchData
);
634 case CAL_SMONTHNAME4
:
635 return GetLocaleInfoW(Locale
, LOCALE_SMONTHNAME4
, lpCalData
, cchData
);
636 case CAL_SMONTHNAME5
:
637 return GetLocaleInfoW(Locale
, LOCALE_SMONTHNAME5
, lpCalData
, cchData
);
638 case CAL_SMONTHNAME6
:
639 return GetLocaleInfoW(Locale
, LOCALE_SMONTHNAME6
, lpCalData
, cchData
);
640 case CAL_SMONTHNAME7
:
641 return GetLocaleInfoW(Locale
, LOCALE_SMONTHNAME7
, lpCalData
, cchData
);
642 case CAL_SMONTHNAME8
:
643 return GetLocaleInfoW(Locale
, LOCALE_SMONTHNAME8
, lpCalData
, cchData
);
644 case CAL_SMONTHNAME9
:
645 return GetLocaleInfoW(Locale
, LOCALE_SMONTHNAME9
, lpCalData
, cchData
);
646 case CAL_SMONTHNAME10
:
647 return GetLocaleInfoW(Locale
, LOCALE_SMONTHNAME10
, lpCalData
, cchData
);
648 case CAL_SMONTHNAME11
:
649 return GetLocaleInfoW(Locale
, LOCALE_SMONTHNAME11
, lpCalData
, cchData
);
650 case CAL_SMONTHNAME12
:
651 return GetLocaleInfoW(Locale
, LOCALE_SMONTHNAME12
, lpCalData
, cchData
);
652 case CAL_SMONTHNAME13
:
653 return GetLocaleInfoW(Locale
, LOCALE_SMONTHNAME13
, lpCalData
, cchData
);
654 case CAL_SABBREVMONTHNAME1
:
655 return GetLocaleInfoW(Locale
, LOCALE_SABBREVMONTHNAME1
, lpCalData
, cchData
);
656 case CAL_SABBREVMONTHNAME2
:
657 return GetLocaleInfoW(Locale
, LOCALE_SABBREVMONTHNAME2
, lpCalData
, cchData
);
658 case CAL_SABBREVMONTHNAME3
:
659 return GetLocaleInfoW(Locale
, LOCALE_SABBREVMONTHNAME3
, lpCalData
, cchData
);
660 case CAL_SABBREVMONTHNAME4
:
661 return GetLocaleInfoW(Locale
, LOCALE_SABBREVMONTHNAME4
, lpCalData
, cchData
);
662 case CAL_SABBREVMONTHNAME5
:
663 return GetLocaleInfoW(Locale
, LOCALE_SABBREVMONTHNAME5
, lpCalData
, cchData
);
664 case CAL_SABBREVMONTHNAME6
:
665 return GetLocaleInfoW(Locale
, LOCALE_SABBREVMONTHNAME6
, lpCalData
, cchData
);
666 case CAL_SABBREVMONTHNAME7
:
667 return GetLocaleInfoW(Locale
, LOCALE_SABBREVMONTHNAME7
, lpCalData
, cchData
);
668 case CAL_SABBREVMONTHNAME8
:
669 return GetLocaleInfoW(Locale
, LOCALE_SABBREVMONTHNAME8
, lpCalData
, cchData
);
670 case CAL_SABBREVMONTHNAME9
:
671 return GetLocaleInfoW(Locale
, LOCALE_SABBREVMONTHNAME9
, lpCalData
, cchData
);
672 case CAL_SABBREVMONTHNAME10
:
673 return GetLocaleInfoW(Locale
, LOCALE_SABBREVMONTHNAME10
, lpCalData
, cchData
);
674 case CAL_SABBREVMONTHNAME11
:
675 return GetLocaleInfoW(Locale
, LOCALE_SABBREVMONTHNAME11
, lpCalData
, cchData
);
676 case CAL_SABBREVMONTHNAME12
:
677 return GetLocaleInfoW(Locale
, LOCALE_SABBREVMONTHNAME12
, lpCalData
, cchData
);
678 case CAL_SABBREVMONTHNAME13
:
679 return GetLocaleInfoW(Locale
, LOCALE_SABBREVMONTHNAME13
, lpCalData
, cchData
);
681 return GetLocaleInfoW(Locale
, LOCALE_SYEARMONTH
, lpCalData
, cchData
);
682 case CAL_ITWODIGITYEARMAX
:
683 if (lpValue
) *lpValue
= CALINFO_MAX_YEAR
;
685 default: MESSAGE("Unknown caltype %ld\n",CalType
& 0xffff);
691 /*********************************************************************
692 * SetCalendarInfoA (KERNEL32.@)
695 int WINAPI
SetCalendarInfoA(LCID Locale
, CALID Calendar
, CALTYPE CalType
, LPCSTR lpCalData
)
697 FIXME("(%08lx,%08lx,%08lx,%s): stub\n",
698 Locale
, Calendar
, CalType
, debugstr_a(lpCalData
));
702 /*********************************************************************
703 * SetCalendarInfoW (KERNEL32.@)
705 * See SetCalendarInfoA.
707 int WINAPI
SetCalendarInfoW(LCID Locale
, CALID Calendar
, CALTYPE CalType
, LPCWSTR lpCalData
)
709 FIXME("(%08lx,%08lx,%08lx,%s): stub\n",
710 Locale
, Calendar
, CalType
, debugstr_w(lpCalData
));
714 /*********************************************************************
715 * LocalFileTimeToFileTime (KERNEL32.@)
717 BOOL WINAPI
LocalFileTimeToFileTime( const FILETIME
*localft
, LPFILETIME utcft
)
720 LARGE_INTEGER local
, utc
;
722 local
.s
.LowPart
= localft
->dwLowDateTime
;
723 local
.s
.HighPart
= localft
->dwHighDateTime
;
724 if (!(status
= RtlLocalTimeToSystemTime( &local
, &utc
)))
726 utcft
->dwLowDateTime
= utc
.s
.LowPart
;
727 utcft
->dwHighDateTime
= utc
.s
.HighPart
;
729 else SetLastError( RtlNtStatusToDosError(status
) );
734 /*********************************************************************
735 * FileTimeToLocalFileTime (KERNEL32.@)
737 BOOL WINAPI
FileTimeToLocalFileTime( const FILETIME
*utcft
, LPFILETIME localft
)
740 LARGE_INTEGER local
, utc
;
742 utc
.s
.LowPart
= utcft
->dwLowDateTime
;
743 utc
.s
.HighPart
= utcft
->dwHighDateTime
;
744 if (!(status
= RtlSystemTimeToLocalTime( &utc
, &local
)))
746 localft
->dwLowDateTime
= local
.s
.LowPart
;
747 localft
->dwHighDateTime
= local
.s
.HighPart
;
749 else SetLastError( RtlNtStatusToDosError(status
) );
754 /*********************************************************************
755 * FileTimeToSystemTime (KERNEL32.@)
757 BOOL WINAPI
FileTimeToSystemTime( const FILETIME
*ft
, LPSYSTEMTIME syst
)
762 t
.s
.LowPart
= ft
->dwLowDateTime
;
763 t
.s
.HighPart
= ft
->dwHighDateTime
;
764 RtlTimeToTimeFields(&t
, &tf
);
766 syst
->wYear
= tf
.Year
;
767 syst
->wMonth
= tf
.Month
;
769 syst
->wHour
= tf
.Hour
;
770 syst
->wMinute
= tf
.Minute
;
771 syst
->wSecond
= tf
.Second
;
772 syst
->wMilliseconds
= tf
.Milliseconds
;
773 syst
->wDayOfWeek
= tf
.Weekday
;
777 /*********************************************************************
778 * SystemTimeToFileTime (KERNEL32.@)
780 BOOL WINAPI
SystemTimeToFileTime( const SYSTEMTIME
*syst
, LPFILETIME ft
)
785 tf
.Year
= syst
->wYear
;
786 tf
.Month
= syst
->wMonth
;
788 tf
.Hour
= syst
->wHour
;
789 tf
.Minute
= syst
->wMinute
;
790 tf
.Second
= syst
->wSecond
;
791 tf
.Milliseconds
= syst
->wMilliseconds
;
793 RtlTimeFieldsToTime(&tf
, &t
);
794 ft
->dwLowDateTime
= t
.s
.LowPart
;
795 ft
->dwHighDateTime
= t
.s
.HighPart
;
799 /*********************************************************************
800 * CompareFileTime (KERNEL32.@)
802 * Compare two FILETIME's to each other.
806 * y [I] time to compare to x
809 * -1, 0, or 1 indicating that x is less than, equal to, or greater
810 * than y respectively.
812 INT WINAPI
CompareFileTime( const FILETIME
*x
, const FILETIME
*y
)
814 if (!x
|| !y
) return -1;
816 if (x
->dwHighDateTime
> y
->dwHighDateTime
)
818 if (x
->dwHighDateTime
< y
->dwHighDateTime
)
820 if (x
->dwLowDateTime
> y
->dwLowDateTime
)
822 if (x
->dwLowDateTime
< y
->dwLowDateTime
)
827 /*********************************************************************
828 * GetLocalTime (KERNEL32.@)
830 * Get the current local time.
835 VOID WINAPI
GetLocalTime(LPSYSTEMTIME systime
) /* [O] Destination for current time */
838 LARGE_INTEGER ft
, ft2
;
840 NtQuerySystemTime(&ft
);
841 RtlSystemTimeToLocalTime(&ft
, &ft2
);
842 lft
.dwLowDateTime
= ft2
.s
.LowPart
;
843 lft
.dwHighDateTime
= ft2
.s
.HighPart
;
844 FileTimeToSystemTime(&lft
, systime
);
847 /*********************************************************************
848 * GetSystemTime (KERNEL32.@)
850 * Get the current system time.
855 VOID WINAPI
GetSystemTime(LPSYSTEMTIME systime
) /* [O] Destination for current time */
860 NtQuerySystemTime(&t
);
861 ft
.dwLowDateTime
= t
.s
.LowPart
;
862 ft
.dwHighDateTime
= t
.s
.HighPart
;
863 FileTimeToSystemTime(&ft
, systime
);