Added support for implementing VxDs as separate dlls and loading them
[wine.git] / dlls / kernel / time.c
blob341f52c5f3e63eb5d33e1c812676c622dc17a866
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 "ntstatus.h"
38 #include "file.h"
39 #include "winternl.h"
40 #include "winerror.h"
41 #include "winnls.h"
42 #include "kernel_private.h"
43 #include "wine/unicode.h"
44 #include "wine/debug.h"
46 WINE_DEFAULT_DEBUG_CHANNEL(win32);
48 /* maximum time adjustment in seconds for SetLocalTime and SetSystemTime */
49 #define SETTIME_MAX_ADJUST 120
50 #define CALINFO_MAX_YEAR 2029
53 /***********************************************************************
54 * SetLocalTime (KERNEL32.@)
56 * Set the local time using current time zone and daylight
57 * savings settings.
59 * RETURNS
60 * Success: TRUE. The time was set
61 * Failure: FALSE, if the time was invalid or caller does not have
62 * permission to change the time.
64 BOOL WINAPI SetLocalTime(
65 const SYSTEMTIME *systime) /* [in] The desired local time. */
67 FILETIME ft;
68 LARGE_INTEGER st, st2;
69 NTSTATUS status;
71 SystemTimeToFileTime( systime, &ft );
72 st.u.LowPart = ft.dwLowDateTime;
73 st.u.HighPart = ft.dwHighDateTime;
74 RtlLocalTimeToSystemTime( &st, &st2 );
76 if ((status = NtSetSystemTime(&st2, NULL)))
77 SetLastError( RtlNtStatusToDosError(status) );
78 return !status;
82 /***********************************************************************
83 * GetSystemTimeAdjustment (KERNEL32.@)
85 * Get the period between clock interrupts and the amount the clock
86 * is adjusted each interrupt so as to keep it in sync with an external source.
88 * RETURNS
89 * TRUE.
91 * BUGS
92 * Only the special case of disabled time adjustments is supported.
94 BOOL WINAPI GetSystemTimeAdjustment(
95 PDWORD lpTimeAdjustment, /* [out] The clock adjustment per interupt in 100's of nanoseconds. */
96 PDWORD lpTimeIncrement, /* [out] The time between clock interupts in 100's of nanoseconds. */
97 PBOOL lpTimeAdjustmentDisabled) /* [out] The clock synchonisation has been disabled. */
99 *lpTimeAdjustment = 0;
100 *lpTimeIncrement = 0;
101 *lpTimeAdjustmentDisabled = TRUE;
102 return TRUE;
106 /***********************************************************************
107 * SetSystemTime (KERNEL32.@)
109 * Set the system time in utc.
111 * RETURNS
112 * Success: TRUE. The time was set
113 * Failure: FALSE, if the time was invalid or caller does not have
114 * permission to change the time.
116 BOOL WINAPI SetSystemTime(
117 const SYSTEMTIME *systime) /* [in] The desired system time. */
119 FILETIME ft;
120 LARGE_INTEGER t;
121 NTSTATUS status;
123 SystemTimeToFileTime( systime, &ft );
124 t.u.LowPart = ft.dwLowDateTime;
125 t.u.HighPart = ft.dwHighDateTime;
126 if ((status = NtSetSystemTime(&t, NULL)))
127 SetLastError( RtlNtStatusToDosError(status) );
128 return !status;
131 /***********************************************************************
132 * SetSystemTimeAdjustment (KERNEL32.@)
134 * Enables or disables the timing adjustments to the system's clock.
136 * RETURNS
137 * Success: TRUE.
138 * Failure: FALSE.
140 BOOL WINAPI SetSystemTimeAdjustment(
141 DWORD dwTimeAdjustment,
142 BOOL bTimeAdjustmentDisabled)
144 /* Fake function for now... */
145 FIXME("(%08lx,%d): stub !\n", dwTimeAdjustment, bTimeAdjustmentDisabled);
146 return TRUE;
150 /***********************************************************************
151 * GetTimeZoneInformation (KERNEL32.@)
153 * Get information about the current local time zone.
155 * RETURNS
156 * Success: TIME_ZONE_ID_STANDARD. tzinfo contains the time zone info.
157 * Failure: TIME_ZONE_ID_INVALID.
159 DWORD WINAPI GetTimeZoneInformation(
160 LPTIME_ZONE_INFORMATION tzinfo) /* [out] Destination for time zone information */
162 NTSTATUS status;
163 if ((status = RtlQueryTimeZoneInformation(tzinfo)))
164 SetLastError( RtlNtStatusToDosError(status) );
165 return TIME_ZONE_ID_STANDARD;
169 /***********************************************************************
170 * SetTimeZoneInformation (KERNEL32.@)
172 * Change the settings of the current local time zone.
174 * RETURNS
175 * Success: TRUE. The time zone was updated with the settings from tzinfo
176 * Failure: FALSE.
178 BOOL WINAPI SetTimeZoneInformation(
179 const LPTIME_ZONE_INFORMATION tzinfo) /* [in] The new time zone. */
181 NTSTATUS status;
182 if ((status = RtlSetTimeZoneInformation(tzinfo)))
183 SetLastError( RtlNtStatusToDosError(status) );
184 return !status;
188 /***********************************************************************
189 * _DayLightCompareDate
191 * Compares two dates without looking at the year
193 * RETURNS
195 * -1 if date < compareDate
196 * 0 if date == compareDate
197 * 1 if date > compareDate
198 * -2 if an error occures
201 static int _DayLightCompareDate(
202 const LPSYSTEMTIME date, /* [in] The date to compare. */
203 const LPSYSTEMTIME compareDate) /* [in] The daylight saving begin or end date */
205 int limit_day;
207 if (compareDate->wYear != 0)
209 if (date->wMonth < compareDate->wMonth)
210 return -1; /* We are in a year before the date limit. */
212 if (date->wMonth > compareDate->wMonth)
213 return 1; /* We are in a year after the date limit. */
216 if (date->wMonth < compareDate->wMonth)
217 return -1; /* We are in a month before the date limit. */
219 if (date->wMonth > compareDate->wMonth)
220 return 1; /* We are in a month after the date limit. */
222 if (compareDate->wDayOfWeek <= 6)
224 SYSTEMTIME tmp;
225 FILETIME tmp_ft;
227 /* compareDate->wDay is interpreted as number of the week in the month. */
228 /* 5 means: the last week in the month */
229 int weekofmonth = compareDate->wDay;
231 /* calculate day of week for the first day in the month */
232 memcpy(&tmp, date, sizeof(SYSTEMTIME));
233 tmp.wDay = 1;
234 tmp.wDayOfWeek = -1;
236 if (weekofmonth == 5)
238 /* Go to the beginning of the next month. */
239 if (++tmp.wMonth > 12)
241 tmp.wMonth = 1;
242 ++tmp.wYear;
246 if (!SystemTimeToFileTime(&tmp, &tmp_ft))
247 return -2;
249 if (weekofmonth == 5)
251 LONGLONG t, one_day;
253 t = tmp_ft.dwHighDateTime;
254 t <<= 32;
255 t += (UINT)tmp_ft.dwLowDateTime;
257 /* subtract one day */
258 one_day = 24*60*60;
259 one_day *= 10000000;
260 t -= one_day;
262 tmp_ft.dwLowDateTime = (UINT)t;
263 tmp_ft.dwHighDateTime = (UINT)(t >> 32);
266 if (!FileTimeToSystemTime(&tmp_ft, &tmp))
267 return -2;
269 if (weekofmonth == 5)
271 /* calculate the last matching day of the week in this month */
272 int dif = tmp.wDayOfWeek - compareDate->wDayOfWeek;
273 if (dif < 0)
274 dif += 7;
276 limit_day = tmp.wDay - dif;
278 else
280 /* calculate the matching day of the week in the given week */
281 int dif = compareDate->wDayOfWeek - tmp.wDayOfWeek;
282 if (dif < 0)
283 dif += 7;
285 limit_day = tmp.wDay + 7*(weekofmonth-1) + dif;
288 else
290 limit_day = compareDate->wDay;
293 if (date->wDay < limit_day)
294 return -1;
296 if (date->wDay > limit_day)
297 return 1;
299 return 0; /* date is equal to the date limit. */
303 /***********************************************************************
304 * _GetTimezoneBias
306 * Calculates the local time bias for a given time zone
308 * RETURNS
310 * Returns TRUE when the time zone bias was calculated.
313 static BOOL _GetTimezoneBias(
314 const LPTIME_ZONE_INFORMATION lpTimeZoneInformation, /* [in] The time zone data. */
315 LPSYSTEMTIME lpSystemTime, /* [in] The system time. */
316 LONG* pBias) /* [out] The calulated bias in minutes */
318 int ret;
319 BOOL beforeStandardDate, afterDaylightDate;
320 BOOL daylightsaving = FALSE;
321 LONG bias = lpTimeZoneInformation->Bias;
323 if (lpTimeZoneInformation->DaylightDate.wMonth != 0)
325 if (lpTimeZoneInformation->StandardDate.wMonth == 0 ||
326 lpTimeZoneInformation->StandardDate.wDay<1 ||
327 lpTimeZoneInformation->StandardDate.wDay>5 ||
328 lpTimeZoneInformation->DaylightDate.wDay<1 ||
329 lpTimeZoneInformation->DaylightDate.wDay>5)
331 SetLastError(ERROR_INVALID_PARAMETER);
332 return FALSE;
335 /* check for daylight saving */
336 ret = _DayLightCompareDate(lpSystemTime, &lpTimeZoneInformation->StandardDate);
337 if (ret == -2)
338 return FALSE;
340 beforeStandardDate = ret < 0;
342 ret = _DayLightCompareDate(lpSystemTime, &lpTimeZoneInformation->DaylightDate);
343 if (ret == -2)
344 return FALSE;
346 afterDaylightDate = ret >= 0;
348 if (beforeStandardDate && afterDaylightDate)
349 daylightsaving = TRUE;
352 if (daylightsaving)
353 bias += lpTimeZoneInformation->DaylightBias;
354 else if (lpTimeZoneInformation->StandardDate.wMonth != 0)
355 bias += lpTimeZoneInformation->StandardBias;
357 *pBias = bias;
359 return TRUE;
363 /***********************************************************************
364 * SystemTimeToTzSpecificLocalTime (KERNEL32.@)
366 * Convert a utc system time to a local time in a given time zone.
368 * RETURNS
369 * Success: TRUE. lpLocalTime contains the converted time
370 * Failure: FALSE.
373 BOOL WINAPI SystemTimeToTzSpecificLocalTime(
374 LPTIME_ZONE_INFORMATION lpTimeZoneInformation, /* [in] The desired time zone. */
375 LPSYSTEMTIME lpUniversalTime, /* [in] The utc time to base local time on. */
376 LPSYSTEMTIME lpLocalTime) /* [out] The local time in the time zone. */
378 FILETIME ft;
379 LONG lBias;
380 LONGLONG t, bias;
381 TIME_ZONE_INFORMATION tzinfo;
383 if (lpTimeZoneInformation != NULL)
385 memcpy(&tzinfo, lpTimeZoneInformation, sizeof(TIME_ZONE_INFORMATION));
387 else
389 if (GetTimeZoneInformation(&tzinfo) == TIME_ZONE_ID_INVALID)
390 return FALSE;
393 if (!SystemTimeToFileTime(lpUniversalTime, &ft))
394 return FALSE;
396 t = ft.dwHighDateTime;
397 t <<= 32;
398 t += (UINT)ft.dwLowDateTime;
400 if (!_GetTimezoneBias(&tzinfo, lpUniversalTime, &lBias))
401 return FALSE;
403 bias = (LONGLONG)lBias * 600000000; /* 60 seconds per minute, 100000 [100-nanoseconds-ticks] per second */
404 t -= bias;
406 ft.dwLowDateTime = (UINT)t;
407 ft.dwHighDateTime = (UINT)(t >> 32);
409 return FileTimeToSystemTime(&ft, lpLocalTime);
413 /***********************************************************************
414 * TzSpecificLocalTimeToSystemTime (KERNEL32.@)
416 * Converts a local time to a time in utc.
418 * RETURNS
419 * Success: TRUE. lpUniversalTime contains the converted time
420 * Failure: FALSE.
422 BOOL WINAPI TzSpecificLocalTimeToSystemTime(
423 LPTIME_ZONE_INFORMATION lpTimeZoneInformation, /* [in] The desired time zone. */
424 LPSYSTEMTIME lpLocalTime, /* [in] The local time. */
425 LPSYSTEMTIME lpUniversalTime) /* [out] The calculated utc time. */
427 FILETIME ft;
428 LONG lBias;
429 LONGLONG t, bias;
430 TIME_ZONE_INFORMATION tzinfo;
432 if (lpTimeZoneInformation != NULL)
434 memcpy(&tzinfo, lpTimeZoneInformation, sizeof(TIME_ZONE_INFORMATION));
436 else
438 if (GetTimeZoneInformation(&tzinfo) == TIME_ZONE_ID_INVALID)
439 return FALSE;
442 if (!SystemTimeToFileTime(lpLocalTime, &ft))
443 return FALSE;
445 t = ft.dwHighDateTime;
446 t <<= 32;
447 t += (UINT)ft.dwLowDateTime;
449 if (!_GetTimezoneBias(&tzinfo, lpLocalTime, &lBias))
450 return FALSE;
452 bias = (LONGLONG)lBias * 600000000; /* 60 seconds per minute, 100000 [100-nanoseconds-ticks] per second */
453 t += bias;
455 ft.dwLowDateTime = (UINT)t;
456 ft.dwHighDateTime = (UINT)(t >> 32);
458 return FileTimeToSystemTime(&ft, lpUniversalTime);
462 /***********************************************************************
463 * GetSystemTimeAsFileTime (KERNEL32.@)
465 * Get the current time in utc format.
467 * RETURNS
468 * Nothing.
470 VOID WINAPI GetSystemTimeAsFileTime(
471 LPFILETIME time) /* [out] Destination for the current utc time */
473 LARGE_INTEGER t;
474 NtQuerySystemTime( &t );
475 time->dwLowDateTime = t.u.LowPart;
476 time->dwHighDateTime = t.u.HighPart;
480 /*********************************************************************
481 * TIME_ClockTimeToFileTime (olorin@fandra.org, 20-Sep-1998)
483 * Used by GetProcessTimes to convert clock_t into FILETIME.
485 * Differences to UnixTimeToFileTime:
486 * 1) Divided by CLK_TCK
487 * 2) Time is relative. There is no 'starting date', so there is
488 * no need for offset correction, like in UnixTimeToFileTime
490 static void TIME_ClockTimeToFileTime(clock_t unix_time, LPFILETIME filetime)
492 ULONGLONG secs = RtlEnlargedUnsignedMultiply( unix_time, 10000000 );
493 secs = RtlExtendedLargeIntegerDivide( secs, CLK_TCK, NULL );
494 filetime->dwLowDateTime = (DWORD)secs;
495 filetime->dwHighDateTime = (DWORD)(secs >> 32);
498 /*********************************************************************
499 * GetProcessTimes (KERNEL32.@)
501 * Get the user and kernel execution times of a process,
502 * along with the creation and exit times if known.
504 * RETURNS
505 * TRUE.
507 * NOTES
508 * olorin@fandra.org:
509 * Would be nice to subtract the cpu time used by Wine at startup.
510 * Also, there is a need to separate times used by different applications.
512 * BUGS
513 * lpCreationTime and lpExitTime are not initialised in the Wine implementation.
515 BOOL WINAPI GetProcessTimes(
516 HANDLE hprocess, /* [in] The process to be queried (obtained from PROCESS_QUERY_INFORMATION). */
517 LPFILETIME lpCreationTime, /* [out] The creation time of the process. */
518 LPFILETIME lpExitTime, /* [out] The exit time of the process if exited. */
519 LPFILETIME lpKernelTime, /* [out] The time spent in kernal routines in 100's of nanoseconds. */
520 LPFILETIME lpUserTime) /* [out] The time spent in user routines in 100's of nanoseconds. */
522 struct tms tms;
524 times(&tms);
525 TIME_ClockTimeToFileTime(tms.tms_utime,lpUserTime);
526 TIME_ClockTimeToFileTime(tms.tms_stime,lpKernelTime);
527 return TRUE;
530 /*********************************************************************
531 * GetCalendarInfoA (KERNEL32.@)
534 int WINAPI GetCalendarInfoA(LCID lcid, CALID Calendar, CALTYPE CalType,
535 LPSTR lpCalData, int cchData, LPDWORD lpValue)
537 int ret;
538 LPWSTR lpCalDataW = NULL;
540 FIXME("(%08lx,%08lx,%08lx,%p,%d,%p): quarter-stub\n",
541 lcid, Calendar, CalType, lpCalData, cchData, lpValue);
543 lcid = ConvertDefaultLocale(lcid);
545 if (NLS_IsUnicodeOnlyLcid(lcid))
547 SetLastError(ERROR_INVALID_PARAMETER);
548 return 0;
551 if (cchData &&
552 !(lpCalDataW = HeapAlloc(GetProcessHeap(), 0, cchData*sizeof(WCHAR))))
553 return 0;
555 ret = GetCalendarInfoW(lcid, Calendar, CalType, lpCalDataW, cchData, lpValue);
556 if(ret && lpCalDataW && lpCalData)
557 WideCharToMultiByte(CP_ACP, 0, lpCalDataW, cchData, lpCalData, cchData, NULL, NULL);
558 if(lpCalDataW)
559 HeapFree(GetProcessHeap(), 0, lpCalDataW);
561 return ret;
564 /*********************************************************************
565 * GetCalendarInfoW (KERNEL32.@)
567 * See GetCalendarInfoA.
569 int WINAPI GetCalendarInfoW(LCID Locale, CALID Calendar, CALTYPE CalType,
570 LPWSTR lpCalData, int cchData, LPDWORD lpValue)
572 FIXME("(%08lx,%08lx,%08lx,%p,%d,%p): quarter-stub\n",
573 Locale, Calendar, CalType, lpCalData, cchData, lpValue);
575 if (CalType & CAL_NOUSEROVERRIDE)
576 FIXME("flag CAL_NOUSEROVERRIDE used, not fully implemented\n");
577 if (CalType & CAL_USE_CP_ACP)
578 FIXME("flag CAL_USE_CP_ACP used, not fully implemented\n");
580 if (CalType & CAL_RETURN_NUMBER) {
581 if (lpCalData != NULL)
582 WARN("lpCalData not NULL (%p) when it should!\n", lpCalData);
583 if (cchData != 0)
584 WARN("cchData not 0 (%d) when it should!\n", cchData);
585 } else {
586 if (lpValue != NULL)
587 WARN("lpValue not NULL (%p) when it should!\n", lpValue);
590 /* FIXME: No verification is made yet wrt Locale
591 * for the CALTYPES not requiring GetLocaleInfoA */
592 switch (CalType & ~(CAL_NOUSEROVERRIDE|CAL_RETURN_NUMBER|CAL_USE_CP_ACP)) {
593 case CAL_ICALINTVALUE:
594 FIXME("Unimplemented caltype %ld\n", CalType & 0xffff);
595 return E_FAIL;
596 case CAL_SCALNAME:
597 FIXME("Unimplemented caltype %ld\n", CalType & 0xffff);
598 return E_FAIL;
599 case CAL_IYEAROFFSETRANGE:
600 FIXME("Unimplemented caltype %ld\n", CalType & 0xffff);
601 return E_FAIL;
602 case CAL_SERASTRING:
603 FIXME("Unimplemented caltype %ld\n", CalType & 0xffff);
604 return E_FAIL;
605 case CAL_SSHORTDATE:
606 return GetLocaleInfoW(Locale, LOCALE_SSHORTDATE, lpCalData, cchData);
607 case CAL_SLONGDATE:
608 return GetLocaleInfoW(Locale, LOCALE_SLONGDATE, lpCalData, cchData);
609 case CAL_SDAYNAME1:
610 return GetLocaleInfoW(Locale, LOCALE_SDAYNAME1, lpCalData, cchData);
611 case CAL_SDAYNAME2:
612 return GetLocaleInfoW(Locale, LOCALE_SDAYNAME2, lpCalData, cchData);
613 case CAL_SDAYNAME3:
614 return GetLocaleInfoW(Locale, LOCALE_SDAYNAME3, lpCalData, cchData);
615 case CAL_SDAYNAME4:
616 return GetLocaleInfoW(Locale, LOCALE_SDAYNAME4, lpCalData, cchData);
617 case CAL_SDAYNAME5:
618 return GetLocaleInfoW(Locale, LOCALE_SDAYNAME5, lpCalData, cchData);
619 case CAL_SDAYNAME6:
620 return GetLocaleInfoW(Locale, LOCALE_SDAYNAME6, lpCalData, cchData);
621 case CAL_SDAYNAME7:
622 return GetLocaleInfoW(Locale, LOCALE_SDAYNAME7, lpCalData, cchData);
623 case CAL_SABBREVDAYNAME1:
624 return GetLocaleInfoW(Locale, LOCALE_SABBREVDAYNAME1, lpCalData, cchData);
625 case CAL_SABBREVDAYNAME2:
626 return GetLocaleInfoW(Locale, LOCALE_SABBREVDAYNAME2, lpCalData, cchData);
627 case CAL_SABBREVDAYNAME3:
628 return GetLocaleInfoW(Locale, LOCALE_SABBREVDAYNAME3, lpCalData, cchData);
629 case CAL_SABBREVDAYNAME4:
630 return GetLocaleInfoW(Locale, LOCALE_SABBREVDAYNAME4, lpCalData, cchData);
631 case CAL_SABBREVDAYNAME5:
632 return GetLocaleInfoW(Locale, LOCALE_SABBREVDAYNAME5, lpCalData, cchData);
633 case CAL_SABBREVDAYNAME6:
634 return GetLocaleInfoW(Locale, LOCALE_SABBREVDAYNAME6, lpCalData, cchData);
635 case CAL_SABBREVDAYNAME7:
636 return GetLocaleInfoW(Locale, LOCALE_SABBREVDAYNAME7, lpCalData, cchData);
637 case CAL_SMONTHNAME1:
638 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME1, lpCalData, cchData);
639 case CAL_SMONTHNAME2:
640 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME2, lpCalData, cchData);
641 case CAL_SMONTHNAME3:
642 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME3, lpCalData, cchData);
643 case CAL_SMONTHNAME4:
644 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME4, lpCalData, cchData);
645 case CAL_SMONTHNAME5:
646 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME5, lpCalData, cchData);
647 case CAL_SMONTHNAME6:
648 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME6, lpCalData, cchData);
649 case CAL_SMONTHNAME7:
650 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME7, lpCalData, cchData);
651 case CAL_SMONTHNAME8:
652 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME8, lpCalData, cchData);
653 case CAL_SMONTHNAME9:
654 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME9, lpCalData, cchData);
655 case CAL_SMONTHNAME10:
656 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME10, lpCalData, cchData);
657 case CAL_SMONTHNAME11:
658 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME11, lpCalData, cchData);
659 case CAL_SMONTHNAME12:
660 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME12, lpCalData, cchData);
661 case CAL_SMONTHNAME13:
662 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME13, lpCalData, cchData);
663 case CAL_SABBREVMONTHNAME1:
664 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME1, lpCalData, cchData);
665 case CAL_SABBREVMONTHNAME2:
666 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME2, lpCalData, cchData);
667 case CAL_SABBREVMONTHNAME3:
668 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME3, lpCalData, cchData);
669 case CAL_SABBREVMONTHNAME4:
670 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME4, lpCalData, cchData);
671 case CAL_SABBREVMONTHNAME5:
672 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME5, lpCalData, cchData);
673 case CAL_SABBREVMONTHNAME6:
674 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME6, lpCalData, cchData);
675 case CAL_SABBREVMONTHNAME7:
676 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME7, lpCalData, cchData);
677 case CAL_SABBREVMONTHNAME8:
678 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME8, lpCalData, cchData);
679 case CAL_SABBREVMONTHNAME9:
680 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME9, lpCalData, cchData);
681 case CAL_SABBREVMONTHNAME10:
682 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME10, lpCalData, cchData);
683 case CAL_SABBREVMONTHNAME11:
684 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME11, lpCalData, cchData);
685 case CAL_SABBREVMONTHNAME12:
686 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME12, lpCalData, cchData);
687 case CAL_SABBREVMONTHNAME13:
688 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME13, lpCalData, cchData);
689 case CAL_SYEARMONTH:
690 return GetLocaleInfoW(Locale, LOCALE_SYEARMONTH, lpCalData, cchData);
691 case CAL_ITWODIGITYEARMAX:
692 if (lpValue) *lpValue = CALINFO_MAX_YEAR;
693 break;
694 default: MESSAGE("Unknown caltype %ld\n",CalType & 0xffff);
695 return E_FAIL;
697 return 0;
700 /*********************************************************************
701 * SetCalendarInfoA (KERNEL32.@)
704 int WINAPI SetCalendarInfoA(LCID Locale, CALID Calendar, CALTYPE CalType, LPCSTR lpCalData)
706 FIXME("(%08lx,%08lx,%08lx,%s): stub\n",
707 Locale, Calendar, CalType, debugstr_a(lpCalData));
708 return 0;
711 /*********************************************************************
712 * SetCalendarInfoW (KERNEL32.@)
714 * See SetCalendarInfoA.
716 int WINAPI SetCalendarInfoW(LCID Locale, CALID Calendar, CALTYPE CalType, LPCWSTR lpCalData)
718 FIXME("(%08lx,%08lx,%08lx,%s): stub\n",
719 Locale, Calendar, CalType, debugstr_w(lpCalData));
720 return 0;
723 /*********************************************************************
724 * LocalFileTimeToFileTime (KERNEL32.@)
726 BOOL WINAPI LocalFileTimeToFileTime( const FILETIME *localft, LPFILETIME utcft )
728 NTSTATUS status;
729 LARGE_INTEGER local, utc;
731 local.u.LowPart = localft->dwLowDateTime;
732 local.u.HighPart = localft->dwHighDateTime;
733 if (!(status = RtlLocalTimeToSystemTime( &local, &utc )))
735 utcft->dwLowDateTime = utc.u.LowPart;
736 utcft->dwHighDateTime = utc.u.HighPart;
738 else SetLastError( RtlNtStatusToDosError(status) );
740 return !status;
743 /*********************************************************************
744 * FileTimeToLocalFileTime (KERNEL32.@)
746 BOOL WINAPI FileTimeToLocalFileTime( const FILETIME *utcft, LPFILETIME localft )
748 NTSTATUS status;
749 LARGE_INTEGER local, utc;
751 utc.u.LowPart = utcft->dwLowDateTime;
752 utc.u.HighPart = utcft->dwHighDateTime;
753 if (!(status = RtlSystemTimeToLocalTime( &utc, &local )))
755 localft->dwLowDateTime = local.u.LowPart;
756 localft->dwHighDateTime = local.u.HighPart;
758 else SetLastError( RtlNtStatusToDosError(status) );
760 return !status;
763 /*********************************************************************
764 * FileTimeToSystemTime (KERNEL32.@)
766 BOOL WINAPI FileTimeToSystemTime( const FILETIME *ft, LPSYSTEMTIME syst )
768 TIME_FIELDS tf;
769 LARGE_INTEGER t;
771 t.u.LowPart = ft->dwLowDateTime;
772 t.u.HighPart = ft->dwHighDateTime;
773 RtlTimeToTimeFields(&t, &tf);
775 syst->wYear = tf.Year;
776 syst->wMonth = tf.Month;
777 syst->wDay = tf.Day;
778 syst->wHour = tf.Hour;
779 syst->wMinute = tf.Minute;
780 syst->wSecond = tf.Second;
781 syst->wMilliseconds = tf.Milliseconds;
782 syst->wDayOfWeek = tf.Weekday;
783 return TRUE;
786 /*********************************************************************
787 * SystemTimeToFileTime (KERNEL32.@)
789 BOOL WINAPI SystemTimeToFileTime( const SYSTEMTIME *syst, LPFILETIME ft )
791 TIME_FIELDS tf;
792 LARGE_INTEGER t;
794 tf.Year = syst->wYear;
795 tf.Month = syst->wMonth;
796 tf.Day = syst->wDay;
797 tf.Hour = syst->wHour;
798 tf.Minute = syst->wMinute;
799 tf.Second = syst->wSecond;
800 tf.Milliseconds = syst->wMilliseconds;
802 RtlTimeFieldsToTime(&tf, &t);
803 ft->dwLowDateTime = t.u.LowPart;
804 ft->dwHighDateTime = t.u.HighPart;
805 return TRUE;
808 /*********************************************************************
809 * CompareFileTime (KERNEL32.@)
811 * Compare two FILETIME's to each other.
813 * PARAMS
814 * x [I] First time
815 * y [I] time to compare to x
817 * RETURNS
818 * -1, 0, or 1 indicating that x is less than, equal to, or greater
819 * than y respectively.
821 INT WINAPI CompareFileTime( const FILETIME *x, const FILETIME *y )
823 if (!x || !y) return -1;
825 if (x->dwHighDateTime > y->dwHighDateTime)
826 return 1;
827 if (x->dwHighDateTime < y->dwHighDateTime)
828 return -1;
829 if (x->dwLowDateTime > y->dwLowDateTime)
830 return 1;
831 if (x->dwLowDateTime < y->dwLowDateTime)
832 return -1;
833 return 0;
836 /*********************************************************************
837 * GetLocalTime (KERNEL32.@)
839 * Get the current local time.
841 * RETURNS
842 * Nothing.
844 VOID WINAPI GetLocalTime(LPSYSTEMTIME systime) /* [O] Destination for current time */
846 FILETIME lft;
847 LARGE_INTEGER ft, ft2;
849 NtQuerySystemTime(&ft);
850 RtlSystemTimeToLocalTime(&ft, &ft2);
851 lft.dwLowDateTime = ft2.u.LowPart;
852 lft.dwHighDateTime = ft2.u.HighPart;
853 FileTimeToSystemTime(&lft, systime);
856 /*********************************************************************
857 * GetSystemTime (KERNEL32.@)
859 * Get the current system time.
861 * RETURNS
862 * Nothing.
864 VOID WINAPI GetSystemTime(LPSYSTEMTIME systime) /* [O] Destination for current time */
866 FILETIME ft;
867 LARGE_INTEGER t;
869 NtQuerySystemTime(&t);
870 ft.dwLowDateTime = t.u.LowPart;
871 ft.dwHighDateTime = t.u.HighPart;
872 FileTimeToSystemTime(&ft, systime);