Documentation updates.
[wine/hacks.git] / dlls / kernel / time.c
blobcaa10c2eeb673c2c785fbbc14c42cb2c34025a42
1 /*
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
21 #include "config.h"
23 #include <string.h>
24 #ifdef HAVE_UNISTD_H
25 # include <unistd.h>
26 #endif
27 #include <stdlib.h>
28 #ifdef HAVE_SYS_TIME_H
29 # include <sys/time.h>
30 #endif
31 #ifdef HAVE_SYS_TIMES_H
32 # include <sys/times.h>
33 #endif
35 #define NONAMELESSUNION
36 #define NONAMELESSSTRUCT
37 #include "file.h"
38 #include "winternl.h"
39 #include "winerror.h"
40 #include "winnls.h"
41 #include "wine/unicode.h"
42 #include "wine/debug.h"
44 WINE_DEFAULT_DEBUG_CHANNEL(win32);
46 /* maximum time adjustment in seconds for SetLocalTime and SetSystemTime */
47 #define SETTIME_MAX_ADJUST 120
48 #define CALINFO_MAX_YEAR 2029
51 /***********************************************************************
52 * SetLocalTime (KERNEL32.@)
54 * Set the local time using current time zone and daylight
55 * savings settings.
57 * RETURNS
58 * Success: TRUE. The time was set
59 * Failure: FALSE, if the time was invalid or caller does not have
60 * permission to change the time.
62 BOOL WINAPI SetLocalTime(
63 const SYSTEMTIME *systime) /* [in] The desired local time. */
65 FILETIME ft;
66 LARGE_INTEGER st, st2;
67 NTSTATUS status;
69 SystemTimeToFileTime( systime, &ft );
70 st.s.LowPart = ft.dwLowDateTime;
71 st.s.HighPart = ft.dwHighDateTime;
72 RtlLocalTimeToSystemTime( &st, &st2 );
74 if ((status = NtSetSystemTime(&st2, NULL)))
75 SetLastError( RtlNtStatusToDosError(status) );
76 return !status;
80 /***********************************************************************
81 * GetSystemTimeAdjustment (KERNEL32.@)
83 * Get the period between clock interrupts and the amount the clock
84 * is adjusted each interrupt so as to keep it in sync with an external source.
86 * RETURNS
87 * TRUE.
89 * BUGS
90 * Only the special case of disabled time adjustments is supported.
92 BOOL WINAPI GetSystemTimeAdjustment(
93 PDWORD lpTimeAdjustment, /* [out] The clock adjustment per interupt in 100's of nanoseconds. */
94 PDWORD lpTimeIncrement, /* [out] The time between clock interupts in 100's of nanoseconds. */
95 PBOOL lpTimeAdjustmentDisabled) /* [out] The clock synchonisation has been disabled. */
97 *lpTimeAdjustment = 0;
98 *lpTimeIncrement = 0;
99 *lpTimeAdjustmentDisabled = TRUE;
100 return TRUE;
104 /***********************************************************************
105 * SetSystemTime (KERNEL32.@)
107 * Set the system time in utc.
109 * RETURNS
110 * Success: TRUE. The time was set
111 * Failure: FALSE, if the time was invalid or caller does not have
112 * permission to change the time.
114 BOOL WINAPI SetSystemTime(
115 const SYSTEMTIME *systime) /* [in] The desired system time. */
117 FILETIME ft;
118 LARGE_INTEGER t;
119 NTSTATUS status;
121 SystemTimeToFileTime( systime, &ft );
122 t.s.LowPart = ft.dwLowDateTime;
123 t.s.HighPart = ft.dwHighDateTime;
124 if ((status = NtSetSystemTime(&t, NULL)))
125 SetLastError( RtlNtStatusToDosError(status) );
126 return !status;
130 /***********************************************************************
131 * GetTimeZoneInformation (KERNEL32.@)
133 * Get information about the current local time zone.
135 * RETURNS
136 * Success: TIME_ZONE_ID_STANDARD. tzinfo contains the time zone info.
137 * Failure: TIME_ZONE_ID_INVALID.
139 DWORD WINAPI GetTimeZoneInformation(
140 LPTIME_ZONE_INFORMATION tzinfo) /* [out] Destination for time zone information */
142 NTSTATUS status;
143 if ((status = RtlQueryTimeZoneInformation(tzinfo)))
144 SetLastError( RtlNtStatusToDosError(status) );
145 return TIME_ZONE_ID_STANDARD;
149 /***********************************************************************
150 * SetTimeZoneInformation (KERNEL32.@)
152 * Change the settings of the current local time zone.
154 * RETURNS
155 * Success: TRUE. The time zone was updated with the settings from tzinfo
156 * Failure: FALSE.
158 BOOL WINAPI SetTimeZoneInformation(
159 const LPTIME_ZONE_INFORMATION tzinfo) /* [in] The new time zone. */
161 NTSTATUS status;
162 if ((status = RtlSetTimeZoneInformation(tzinfo)))
163 SetLastError( RtlNtStatusToDosError(status) );
164 return !status;
168 /***********************************************************************
169 * _DayLightCompareDate
171 * Compares two dates without looking at the year
173 * RETURNS
175 * -1 if date < compareDate
176 * 0 if date == compareDate
177 * 1 if date > compareDate
178 * -2 if an error occures
181 static int _DayLightCompareDate(
182 const LPSYSTEMTIME date, /* [in] The date to compare. */
183 const LPSYSTEMTIME compareDate) /* [in] The daylight saving begin or end date */
185 int limit_day;
187 if (compareDate->wYear != 0)
189 if (date->wMonth < compareDate->wMonth)
190 return -1; /* We are in a year before the date limit. */
192 if (date->wMonth > compareDate->wMonth)
193 return 1; /* We are in a year after the date limit. */
196 if (date->wMonth < compareDate->wMonth)
197 return -1; /* We are in a month before the date limit. */
199 if (date->wMonth > compareDate->wMonth)
200 return 1; /* We are in a month after the date limit. */
202 if (compareDate->wDayOfWeek <= 6)
204 SYSTEMTIME tmp;
205 FILETIME tmp_ft;
207 /* compareDate->wDay is interpreted as number of the week in the month. */
208 /* 5 means: the last week in the month */
209 int weekofmonth = compareDate->wDay;
211 /* calculate day of week for the first day in the month */
212 memcpy(&tmp, date, sizeof(SYSTEMTIME));
213 tmp.wDay = 1;
214 tmp.wDayOfWeek = -1;
216 if (weekofmonth == 5)
218 /* Go to the beginning of the next month. */
219 if (++tmp.wMonth > 12)
221 tmp.wMonth = 1;
222 ++tmp.wYear;
226 if (!SystemTimeToFileTime(&tmp, &tmp_ft))
227 return -2;
229 if (weekofmonth == 5)
231 LONGLONG t, one_day;
233 t = tmp_ft.dwHighDateTime;
234 t <<= 32;
235 t += (UINT)tmp_ft.dwLowDateTime;
237 /* substract one day */
238 one_day = 24*60*60;
239 one_day *= 10000000;
240 t -= one_day;
242 tmp_ft.dwLowDateTime = (UINT)t;
243 tmp_ft.dwHighDateTime = (UINT)(t >> 32);
246 if (!FileTimeToSystemTime(&tmp_ft, &tmp))
247 return -2;
249 if (weekofmonth == 5)
251 /* calculate the last matching day of the week in this month */
252 int dif = tmp.wDayOfWeek - compareDate->wDayOfWeek;
253 if (dif < 0)
254 dif += 7;
256 limit_day = tmp.wDay - dif;
258 else
260 /* calulcate the matching day of the week in the given week */
261 int dif = compareDate->wDayOfWeek - tmp.wDayOfWeek;
262 if (dif < 0)
263 dif += 7;
265 limit_day = tmp.wDay + 7*(weekofmonth-1) + dif;
268 else
270 limit_day = compareDate->wDay;
273 if (date->wDay < limit_day)
274 return -1;
276 if (date->wDay > limit_day)
277 return 1;
279 return 0; /* date is equal to the date limit. */
283 /***********************************************************************
284 * _GetTimezoneBias
286 * Calculates the local time bias for a given time zone
288 * RETURNS
290 * Returns TRUE when the time zone bias was calculated.
293 static BOOL _GetTimezoneBias(
294 const LPTIME_ZONE_INFORMATION lpTimeZoneInformation, /* [in] The time zone data. */
295 LPSYSTEMTIME lpSystemTime, /* [in] The system time. */
296 LONG* pBias) /* [out] The calulated bias in minutes */
298 int ret;
299 BOOL beforedaylightsaving, afterdaylightsaving;
300 BOOL daylightsaving = FALSE;
301 LONG bias = lpTimeZoneInformation->Bias;
303 if (lpTimeZoneInformation->DaylightDate.wMonth != 0)
305 if (lpTimeZoneInformation->StandardDate.wMonth == 0 ||
306 lpTimeZoneInformation->StandardDate.wDay<1 ||
307 lpTimeZoneInformation->StandardDate.wDay>5 ||
308 lpTimeZoneInformation->DaylightDate.wDay<1 ||
309 lpTimeZoneInformation->DaylightDate.wDay>5)
311 SetLastError(ERROR_INVALID_PARAMETER);
312 return FALSE;
315 /* check for daylight saving */
316 ret = _DayLightCompareDate(lpSystemTime, &lpTimeZoneInformation->StandardDate);
317 if (ret == -2)
318 return FALSE;
320 beforedaylightsaving = ret < 0;
322 _DayLightCompareDate(lpSystemTime, &lpTimeZoneInformation->DaylightDate);
323 if (ret == -2)
324 return FALSE;
326 afterdaylightsaving = ret >= 0;
328 if (!beforedaylightsaving && !afterdaylightsaving)
329 daylightsaving = TRUE;
332 if (daylightsaving)
333 bias += lpTimeZoneInformation->DaylightBias;
334 else if (lpTimeZoneInformation->StandardDate.wMonth != 0)
335 bias += lpTimeZoneInformation->StandardBias;
337 *pBias = bias;
339 return TRUE;
343 /***********************************************************************
344 * SystemTimeToTzSpecificLocalTime (KERNEL32.@)
346 * Convert a utc system time to a local time in a given time zone.
348 * RETURNS
349 * Success: TRUE. lpLocalTime contains the converted time
350 * Failure: FALSE.
353 BOOL WINAPI SystemTimeToTzSpecificLocalTime(
354 LPTIME_ZONE_INFORMATION lpTimeZoneInformation, /* [in] The desired time zone. */
355 LPSYSTEMTIME lpUniversalTime, /* [in] The utc time to base local time on. */
356 LPSYSTEMTIME lpLocalTime) /* [out] The local time in the time zone. */
358 FILETIME ft;
359 LONG lBias;
360 LONGLONG t, bias;
361 TIME_ZONE_INFORMATION tzinfo;
363 if (lpTimeZoneInformation != NULL)
365 memcpy(&tzinfo, lpTimeZoneInformation, sizeof(TIME_ZONE_INFORMATION));
367 else
369 if (GetTimeZoneInformation(&tzinfo) == TIME_ZONE_ID_INVALID)
370 return FALSE;
373 if (!SystemTimeToFileTime(lpUniversalTime, &ft))
374 return FALSE;
376 t = ft.dwHighDateTime;
377 t <<= 32;
378 t += (UINT)ft.dwLowDateTime;
380 if (!_GetTimezoneBias(&tzinfo, lpUniversalTime, &lBias))
381 return FALSE;
383 bias = (LONGLONG)lBias * 600000000; /* 60 seconds per minute, 100000 [100-nanoseconds-ticks] per second */
384 t -= bias;
386 ft.dwLowDateTime = (UINT)t;
387 ft.dwHighDateTime = (UINT)(t >> 32);
389 return FileTimeToSystemTime(&ft, lpLocalTime);
393 /***********************************************************************
394 * TzSpecificLocalTimeToSystemTime (KERNEL32.@)
396 * Converts a local time to a time in utc.
398 * RETURNS
399 * Success: TRUE. lpUniversalTime contains the converted time
400 * Failure: FALSE.
402 BOOL WINAPI TzSpecificLocalTimeToSystemTime(
403 LPTIME_ZONE_INFORMATION lpTimeZoneInformation, /* [in] The desired time zone. */
404 LPSYSTEMTIME lpLocalTime, /* [in] The local time. */
405 LPSYSTEMTIME lpUniversalTime) /* [out] The calculated utc time. */
407 FILETIME ft;
408 LONG lBias;
409 LONGLONG t, bias;
410 TIME_ZONE_INFORMATION tzinfo;
412 if (lpTimeZoneInformation != NULL)
414 memcpy(&tzinfo, lpTimeZoneInformation, sizeof(TIME_ZONE_INFORMATION));
416 else
418 if (GetTimeZoneInformation(&tzinfo) == TIME_ZONE_ID_INVALID)
419 return FALSE;
422 if (!SystemTimeToFileTime(lpLocalTime, &ft))
423 return FALSE;
425 t = ft.dwHighDateTime;
426 t <<= 32;
427 t += (UINT)ft.dwLowDateTime;
429 if (!_GetTimezoneBias(&tzinfo, lpUniversalTime, &lBias))
430 return FALSE;
432 bias = (LONGLONG)lBias * 600000000; /* 60 seconds per minute, 100000 [100-nanoseconds-ticks] per second */
433 t += bias;
435 ft.dwLowDateTime = (UINT)t;
436 ft.dwHighDateTime = (UINT)(t >> 32);
438 return FileTimeToSystemTime(&ft, lpUniversalTime);
442 /***********************************************************************
443 * GetSystemTimeAsFileTime (KERNEL32.@)
445 * Get the current time in utc format.
447 * RETURNS
448 * Nothing.
450 VOID WINAPI GetSystemTimeAsFileTime(
451 LPFILETIME time) /* [out] Destination for the current utc time */
453 LARGE_INTEGER t;
454 NtQuerySystemTime( &t );
455 time->dwLowDateTime = t.s.LowPart;
456 time->dwHighDateTime = t.s.HighPart;
460 /*********************************************************************
461 * TIME_ClockTimeToFileTime (olorin@fandra.org, 20-Sep-1998)
463 * Used by GetProcessTimes to convert clock_t into FILETIME.
465 * Differences to UnixTimeToFileTime:
466 * 1) Divided by CLK_TCK
467 * 2) Time is relative. There is no 'starting date', so there is
468 * no need in offset correction, like in UnixTimeToFileTime
470 static void TIME_ClockTimeToFileTime(clock_t unix_time, LPFILETIME filetime)
472 ULONGLONG secs = RtlEnlargedUnsignedMultiply( unix_time, 10000000 );
473 secs = RtlExtendedLargeIntegerDivide( secs, CLK_TCK, NULL );
474 filetime->dwLowDateTime = (DWORD)secs;
475 filetime->dwHighDateTime = (DWORD)(secs >> 32);
478 /*********************************************************************
479 * GetProcessTimes (KERNEL32.@)
481 * Get the user and kernel execution times of a process,
482 * along with the creation and exit times if known.
484 * RETURNS
485 * TRUE.
487 * NOTES
488 * olorin@fandra.org:
489 * Would be nice to subtract the cpu time used by Wine at startup.
490 * Also, there is a need to separate times used by different applications.
492 * BUGS
493 * lpCreationTime and lpExitTime are not initialised in the Wine implementation.
495 BOOL WINAPI GetProcessTimes(
496 HANDLE hprocess, /* [in] The process to be queried (obtained from PROCESS_QUERY_INFORMATION). */
497 LPFILETIME lpCreationTime, /* [out] The creation time of the process. */
498 LPFILETIME lpExitTime, /* [out] The exit time of the process if exited. */
499 LPFILETIME lpKernelTime, /* [out] The time spent in kernal routines in 100's of nanoseconds. */
500 LPFILETIME lpUserTime) /* [out] The time spent in user routines in 100's of nanoseconds. */
502 struct tms tms;
504 times(&tms);
505 TIME_ClockTimeToFileTime(tms.tms_utime,lpUserTime);
506 TIME_ClockTimeToFileTime(tms.tms_stime,lpKernelTime);
507 return TRUE;
510 /*********************************************************************
511 * GetCalendarInfoA (KERNEL32.@)
514 int WINAPI GetCalendarInfoA(LCID Locale, CALID Calendar, CALTYPE CalType,
515 LPSTR lpCalData, int cchData, LPDWORD lpValue)
517 int ret;
518 LPWSTR lpCalDataW = NULL;
520 FIXME("(%08lx,%08lx,%08lx,%p,%d,%p): quarter-stub\n",
521 Locale, Calendar, CalType, lpCalData, cchData, lpValue);
522 /* FIXME: Should verify if Locale is allowable in ANSI, as per MSDN */
524 if(cchData)
525 if(!(lpCalDataW = HeapAlloc(GetProcessHeap(), 0, cchData*sizeof(WCHAR)))) return 0;
527 ret = GetCalendarInfoW(Locale, Calendar, CalType, lpCalDataW, cchData, lpValue);
528 if(ret && lpCalDataW && lpCalData)
529 WideCharToMultiByte(CP_ACP, 0, lpCalDataW, cchData, lpCalData, cchData, NULL, NULL);
530 if(lpCalDataW)
531 HeapFree(GetProcessHeap(), 0, lpCalDataW);
533 return ret;
536 /*********************************************************************
537 * GetCalendarInfoW (KERNEL32.@)
539 * See GetCalendarInfoA.
541 int WINAPI GetCalendarInfoW(LCID Locale, CALID Calendar, CALTYPE CalType,
542 LPWSTR lpCalData, int cchData, LPDWORD lpValue)
544 FIXME("(%08lx,%08lx,%08lx,%p,%d,%p): quarter-stub\n",
545 Locale, Calendar, CalType, lpCalData, cchData, lpValue);
547 if (CalType & CAL_NOUSEROVERRIDE)
548 FIXME("flag CAL_NOUSEROVERRIDE used, not fully implemented\n");
549 if (CalType & CAL_USE_CP_ACP)
550 FIXME("flag CAL_USE_CP_ACP used, not fully implemented\n");
552 if (CalType & CAL_RETURN_NUMBER) {
553 if (lpCalData != NULL)
554 WARN("lpCalData not NULL (%p) when it should!\n", lpCalData);
555 if (cchData != 0)
556 WARN("cchData not 0 (%d) when it should!\n", cchData);
557 } else {
558 if (lpValue != NULL)
559 WARN("lpValue not NULL (%p) when it should!\n", lpValue);
562 /* FIXME: No verification is made yet wrt Locale
563 * for the CALTYPES not requiring GetLocaleInfoA */
564 switch (CalType & ~(CAL_NOUSEROVERRIDE|CAL_RETURN_NUMBER|CAL_USE_CP_ACP)) {
565 case CAL_ICALINTVALUE:
566 FIXME("Unimplemented caltype %ld\n", CalType & 0xffff);
567 return E_FAIL;
568 case CAL_SCALNAME:
569 FIXME("Unimplemented caltype %ld\n", CalType & 0xffff);
570 return E_FAIL;
571 case CAL_IYEAROFFSETRANGE:
572 FIXME("Unimplemented caltype %ld\n", CalType & 0xffff);
573 return E_FAIL;
574 case CAL_SERASTRING:
575 FIXME("Unimplemented caltype %ld\n", CalType & 0xffff);
576 return E_FAIL;
577 case CAL_SSHORTDATE:
578 return GetLocaleInfoW(Locale, LOCALE_SSHORTDATE, lpCalData, cchData);
579 case CAL_SLONGDATE:
580 return GetLocaleInfoW(Locale, LOCALE_SLONGDATE, lpCalData, cchData);
581 case CAL_SDAYNAME1:
582 return GetLocaleInfoW(Locale, LOCALE_SDAYNAME1, lpCalData, cchData);
583 case CAL_SDAYNAME2:
584 return GetLocaleInfoW(Locale, LOCALE_SDAYNAME2, lpCalData, cchData);
585 case CAL_SDAYNAME3:
586 return GetLocaleInfoW(Locale, LOCALE_SDAYNAME3, lpCalData, cchData);
587 case CAL_SDAYNAME4:
588 return GetLocaleInfoW(Locale, LOCALE_SDAYNAME4, lpCalData, cchData);
589 case CAL_SDAYNAME5:
590 return GetLocaleInfoW(Locale, LOCALE_SDAYNAME5, lpCalData, cchData);
591 case CAL_SDAYNAME6:
592 return GetLocaleInfoW(Locale, LOCALE_SDAYNAME6, lpCalData, cchData);
593 case CAL_SDAYNAME7:
594 return GetLocaleInfoW(Locale, LOCALE_SDAYNAME7, lpCalData, cchData);
595 case CAL_SABBREVDAYNAME1:
596 return GetLocaleInfoW(Locale, LOCALE_SABBREVDAYNAME1, lpCalData, cchData);
597 case CAL_SABBREVDAYNAME2:
598 return GetLocaleInfoW(Locale, LOCALE_SABBREVDAYNAME2, lpCalData, cchData);
599 case CAL_SABBREVDAYNAME3:
600 return GetLocaleInfoW(Locale, LOCALE_SABBREVDAYNAME3, lpCalData, cchData);
601 case CAL_SABBREVDAYNAME4:
602 return GetLocaleInfoW(Locale, LOCALE_SABBREVDAYNAME4, lpCalData, cchData);
603 case CAL_SABBREVDAYNAME5:
604 return GetLocaleInfoW(Locale, LOCALE_SABBREVDAYNAME5, lpCalData, cchData);
605 case CAL_SABBREVDAYNAME6:
606 return GetLocaleInfoW(Locale, LOCALE_SABBREVDAYNAME6, lpCalData, cchData);
607 case CAL_SABBREVDAYNAME7:
608 return GetLocaleInfoW(Locale, LOCALE_SABBREVDAYNAME7, lpCalData, cchData);
609 case CAL_SMONTHNAME1:
610 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME1, lpCalData, cchData);
611 case CAL_SMONTHNAME2:
612 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME2, lpCalData, cchData);
613 case CAL_SMONTHNAME3:
614 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME3, lpCalData, cchData);
615 case CAL_SMONTHNAME4:
616 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME4, lpCalData, cchData);
617 case CAL_SMONTHNAME5:
618 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME5, lpCalData, cchData);
619 case CAL_SMONTHNAME6:
620 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME6, lpCalData, cchData);
621 case CAL_SMONTHNAME7:
622 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME7, lpCalData, cchData);
623 case CAL_SMONTHNAME8:
624 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME8, lpCalData, cchData);
625 case CAL_SMONTHNAME9:
626 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME9, lpCalData, cchData);
627 case CAL_SMONTHNAME10:
628 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME10, lpCalData, cchData);
629 case CAL_SMONTHNAME11:
630 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME11, lpCalData, cchData);
631 case CAL_SMONTHNAME12:
632 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME12, lpCalData, cchData);
633 case CAL_SMONTHNAME13:
634 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME13, lpCalData, cchData);
635 case CAL_SABBREVMONTHNAME1:
636 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME1, lpCalData, cchData);
637 case CAL_SABBREVMONTHNAME2:
638 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME2, lpCalData, cchData);
639 case CAL_SABBREVMONTHNAME3:
640 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME3, lpCalData, cchData);
641 case CAL_SABBREVMONTHNAME4:
642 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME4, lpCalData, cchData);
643 case CAL_SABBREVMONTHNAME5:
644 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME5, lpCalData, cchData);
645 case CAL_SABBREVMONTHNAME6:
646 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME6, lpCalData, cchData);
647 case CAL_SABBREVMONTHNAME7:
648 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME7, lpCalData, cchData);
649 case CAL_SABBREVMONTHNAME8:
650 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME8, lpCalData, cchData);
651 case CAL_SABBREVMONTHNAME9:
652 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME9, lpCalData, cchData);
653 case CAL_SABBREVMONTHNAME10:
654 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME10, lpCalData, cchData);
655 case CAL_SABBREVMONTHNAME11:
656 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME11, lpCalData, cchData);
657 case CAL_SABBREVMONTHNAME12:
658 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME12, lpCalData, cchData);
659 case CAL_SABBREVMONTHNAME13:
660 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME13, lpCalData, cchData);
661 case CAL_SYEARMONTH:
662 return GetLocaleInfoW(Locale, LOCALE_SYEARMONTH, lpCalData, cchData);
663 case CAL_ITWODIGITYEARMAX:
664 if (lpValue) *lpValue = CALINFO_MAX_YEAR;
665 break;
666 default: MESSAGE("Unknown caltype %ld\n",CalType & 0xffff);
667 return E_FAIL;
669 return 0;
672 /*********************************************************************
673 * SetCalendarInfoA (KERNEL32.@)
676 int WINAPI SetCalendarInfoA(LCID Locale, CALID Calendar, CALTYPE CalType, LPCSTR lpCalData)
678 FIXME("(%08lx,%08lx,%08lx,%s): stub\n",
679 Locale, Calendar, CalType, debugstr_a(lpCalData));
680 return 0;
683 /*********************************************************************
684 * SetCalendarInfoW (KERNEL32.@)
686 * See SetCalendarInfoA.
688 int WINAPI SetCalendarInfoW(LCID Locale, CALID Calendar, CALTYPE CalType, LPCWSTR lpCalData)
690 FIXME("(%08lx,%08lx,%08lx,%s): stub\n",
691 Locale, Calendar, CalType, debugstr_w(lpCalData));
692 return 0;
695 /*********************************************************************
696 * LocalFileTimeToFileTime (KERNEL32.@)
698 BOOL WINAPI LocalFileTimeToFileTime( const FILETIME *localft, LPFILETIME utcft )
700 NTSTATUS status;
701 LARGE_INTEGER local, utc;
703 local.s.LowPart = localft->dwLowDateTime;
704 local.s.HighPart = localft->dwHighDateTime;
705 if (!(status = RtlLocalTimeToSystemTime( &local, &utc )))
707 utcft->dwLowDateTime = utc.s.LowPart;
708 utcft->dwHighDateTime = utc.s.HighPart;
710 else SetLastError( RtlNtStatusToDosError(status) );
712 return !status;
715 /*********************************************************************
716 * FileTimeToLocalFileTime (KERNEL32.@)
718 BOOL WINAPI FileTimeToLocalFileTime( const FILETIME *utcft, LPFILETIME localft )
720 NTSTATUS status;
721 LARGE_INTEGER local, utc;
723 utc.s.LowPart = utcft->dwLowDateTime;
724 utc.s.HighPart = utcft->dwHighDateTime;
725 if (!(status = RtlSystemTimeToLocalTime( &utc, &local )))
727 localft->dwLowDateTime = local.s.LowPart;
728 localft->dwHighDateTime = local.s.HighPart;
730 else SetLastError( RtlNtStatusToDosError(status) );
732 return !status;
735 /*********************************************************************
736 * FileTimeToSystemTime (KERNEL32.@)
738 BOOL WINAPI FileTimeToSystemTime( const FILETIME *ft, LPSYSTEMTIME syst )
740 TIME_FIELDS tf;
741 LARGE_INTEGER t;
743 t.s.LowPart = ft->dwLowDateTime;
744 t.s.HighPart = ft->dwHighDateTime;
745 RtlTimeToTimeFields(&t, &tf);
747 syst->wYear = tf.Year;
748 syst->wMonth = tf.Month;
749 syst->wDay = tf.Day;
750 syst->wHour = tf.Hour;
751 syst->wMinute = tf.Minute;
752 syst->wSecond = tf.Second;
753 syst->wMilliseconds = tf.Milliseconds;
754 syst->wDayOfWeek = tf.Weekday;
755 return TRUE;
758 /*********************************************************************
759 * SystemTimeToFileTime (KERNEL32.@)
761 BOOL WINAPI SystemTimeToFileTime( const SYSTEMTIME *syst, LPFILETIME ft )
763 TIME_FIELDS tf;
764 LARGE_INTEGER t;
766 tf.Year = syst->wYear;
767 tf.Month = syst->wMonth;
768 tf.Day = syst->wDay;
769 tf.Hour = syst->wHour;
770 tf.Minute = syst->wMinute;
771 tf.Second = syst->wSecond;
772 tf.Milliseconds = syst->wMilliseconds;
774 RtlTimeFieldsToTime(&tf, &t);
775 ft->dwLowDateTime = t.s.LowPart;
776 ft->dwHighDateTime = t.s.HighPart;
777 return TRUE;
780 /*********************************************************************
781 * CompareFileTime (KERNEL32.@)
783 * Compare two FILETIME's to each other.
785 * PARAMS
786 * x [I] First time
787 * y [I] time to compare to x
789 * RETURNS
790 * -1, 0, or 1 indicating that x is less than, equal to, or greater
791 * than y respectively.
793 INT WINAPI CompareFileTime( const FILETIME *x, const FILETIME *y )
795 if (!x || !y) return -1;
797 if (x->dwHighDateTime > y->dwHighDateTime)
798 return 1;
799 if (x->dwHighDateTime < y->dwHighDateTime)
800 return -1;
801 if (x->dwLowDateTime > y->dwLowDateTime)
802 return 1;
803 if (x->dwLowDateTime < y->dwLowDateTime)
804 return -1;
805 return 0;
808 /*********************************************************************
809 * GetLocalTime (KERNEL32.@)
811 * Get the current local time.
813 * RETURNS
814 * Nothing.
816 VOID WINAPI GetLocalTime(LPSYSTEMTIME systime) /* [O] Destination for current time */
818 FILETIME lft;
819 LARGE_INTEGER ft, ft2;
821 NtQuerySystemTime(&ft);
822 RtlSystemTimeToLocalTime(&ft, &ft2);
823 lft.dwLowDateTime = ft2.s.LowPart;
824 lft.dwHighDateTime = ft2.s.HighPart;
825 FileTimeToSystemTime(&lft, systime);
828 /*********************************************************************
829 * GetSystemTime (KERNEL32.@)
831 * Get the current system time.
833 * RETURNS
834 * Nothing.
836 VOID WINAPI GetSystemTime(LPSYSTEMTIME systime) /* [O] Destination for current time */
838 FILETIME ft;
839 LARGE_INTEGER t;
841 NtQuerySystemTime(&t);
842 ft.dwLowDateTime = t.s.LowPart;
843 ft.dwHighDateTime = t.s.HighPart;
844 FileTimeToSystemTime(&ft, systime);