Replace empty window rect checks by a new X11DRV_is_window_rect_mapped
[wine/multimedia.git] / dlls / kernel / time.c
blob44170ba5284faecf71328a550b917b074755ce8e
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 <stdarg.h>
28 #include <stdlib.h>
29 #include <time.h>
30 #ifdef HAVE_SYS_TIME_H
31 # include <sys/time.h>
32 #endif
33 #ifdef HAVE_SYS_TIMES_H
34 # include <sys/times.h>
35 #endif
37 #define NONAMELESSUNION
38 #define NONAMELESSSTRUCT
39 #include "windef.h"
40 #include "winbase.h"
41 #include "winreg.h"
42 #include "ntstatus.h"
43 #include "winternl.h"
44 #include "winerror.h"
45 #include "winnls.h"
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
57 /***********************************************************************
58 * SetLocalTime (KERNEL32.@)
60 * Set the local time using current time zone and daylight
61 * savings settings.
63 * RETURNS
64 * Success: TRUE. The time was set
65 * Failure: FALSE, if the time was invalid or caller does not have
66 * permission to change the time.
68 BOOL WINAPI SetLocalTime(
69 const SYSTEMTIME *systime) /* [in] The desired local time. */
71 FILETIME ft;
72 LARGE_INTEGER st, st2;
73 NTSTATUS status;
75 SystemTimeToFileTime( systime, &ft );
76 st.u.LowPart = ft.dwLowDateTime;
77 st.u.HighPart = ft.dwHighDateTime;
78 RtlLocalTimeToSystemTime( &st, &st2 );
80 if ((status = NtSetSystemTime(&st2, NULL)))
81 SetLastError( RtlNtStatusToDosError(status) );
82 return !status;
86 /***********************************************************************
87 * GetSystemTimeAdjustment (KERNEL32.@)
89 * Get the period between clock interrupts and the amount the clock
90 * is adjusted each interrupt so as to keep it in sync with an external source.
92 * RETURNS
93 * TRUE.
95 * BUGS
96 * Only the special case of disabled time adjustments is supported.
98 BOOL WINAPI GetSystemTimeAdjustment(
99 PDWORD lpTimeAdjustment, /* [out] The clock adjustment per interupt in 100's of nanoseconds. */
100 PDWORD lpTimeIncrement, /* [out] The time between clock interupts in 100's of nanoseconds. */
101 PBOOL lpTimeAdjustmentDisabled) /* [out] The clock synchonisation has been disabled. */
103 *lpTimeAdjustment = 0;
104 *lpTimeIncrement = 0;
105 *lpTimeAdjustmentDisabled = TRUE;
106 return TRUE;
110 /***********************************************************************
111 * SetSystemTime (KERNEL32.@)
113 * Set the system time in utc.
115 * RETURNS
116 * Success: TRUE. The time was set
117 * Failure: FALSE, if the time was invalid or caller does not have
118 * permission to change the time.
120 BOOL WINAPI SetSystemTime(
121 const SYSTEMTIME *systime) /* [in] The desired system time. */
123 FILETIME ft;
124 LARGE_INTEGER t;
125 NTSTATUS status;
127 SystemTimeToFileTime( systime, &ft );
128 t.u.LowPart = ft.dwLowDateTime;
129 t.u.HighPart = ft.dwHighDateTime;
130 if ((status = NtSetSystemTime(&t, NULL)))
131 SetLastError( RtlNtStatusToDosError(status) );
132 return !status;
135 /***********************************************************************
136 * SetSystemTimeAdjustment (KERNEL32.@)
138 * Enables or disables the timing adjustments to the system's clock.
140 * RETURNS
141 * Success: TRUE.
142 * Failure: FALSE.
144 BOOL WINAPI SetSystemTimeAdjustment(
145 DWORD dwTimeAdjustment,
146 BOOL bTimeAdjustmentDisabled)
148 /* Fake function for now... */
149 FIXME("(%08lx,%d): stub !\n", dwTimeAdjustment, bTimeAdjustmentDisabled);
150 return TRUE;
154 /***********************************************************************
155 * GetTimeZoneInformation (KERNEL32.@)
157 * Get information about the current local time zone.
159 * RETURNS
160 * Success: TIME_ZONE_ID_STANDARD. tzinfo contains the time zone info.
161 * Failure: TIME_ZONE_ID_INVALID.
162 * FIXME: return TIME_ZONE_ID_DAYLIGHT when daylight saving is on.
164 DWORD WINAPI GetTimeZoneInformation(
165 LPTIME_ZONE_INFORMATION tzinfo) /* [out] Destination for time zone information */
167 NTSTATUS status;
168 if ((status = RtlQueryTimeZoneInformation(tzinfo)))
169 SetLastError( RtlNtStatusToDosError(status) );
170 return TIME_ZONE_ID_STANDARD;
174 /***********************************************************************
175 * SetTimeZoneInformation (KERNEL32.@)
177 * Change the settings of the current local time zone.
179 * RETURNS
180 * Success: TRUE. The time zone was updated with the settings from tzinfo
181 * Failure: FALSE.
183 BOOL WINAPI SetTimeZoneInformation(
184 const LPTIME_ZONE_INFORMATION tzinfo) /* [in] The new time zone. */
186 NTSTATUS status;
187 if ((status = RtlSetTimeZoneInformation(tzinfo)))
188 SetLastError( RtlNtStatusToDosError(status) );
189 return !status;
193 /***********************************************************************
194 * _DayLightCompareDate
196 * Compares two dates without looking at the year
198 * RETURNS
200 * -1 if date < compareDate
201 * 0 if date == compareDate
202 * 1 if date > compareDate
203 * -2 if an error occures
206 static int _DayLightCompareDate(
207 const LPSYSTEMTIME date, /* [in] The date to compare. */
208 const LPSYSTEMTIME compareDate) /* [in] The daylight saving begin or end date */
210 int limit_day;
212 if (compareDate->wYear != 0)
214 if (date->wMonth < compareDate->wMonth)
215 return -1; /* We are in a year before the date limit. */
217 if (date->wMonth > compareDate->wMonth)
218 return 1; /* We are in a year after the date limit. */
221 if (date->wMonth < compareDate->wMonth)
222 return -1; /* We are in a month before the date limit. */
224 if (date->wMonth > compareDate->wMonth)
225 return 1; /* We are in a month after the date limit. */
227 if (compareDate->wDayOfWeek <= 6)
229 SYSTEMTIME tmp;
230 FILETIME tmp_ft;
232 /* compareDate->wDay is interpreted as number of the week in the month. */
233 /* 5 means: the last week in the month */
234 int weekofmonth = compareDate->wDay;
236 /* calculate day of week for the first day in the month */
237 memcpy(&tmp, date, sizeof(SYSTEMTIME));
238 tmp.wDay = 1;
239 tmp.wDayOfWeek = -1;
241 if (weekofmonth == 5)
243 /* Go to the beginning of the next month. */
244 if (++tmp.wMonth > 12)
246 tmp.wMonth = 1;
247 ++tmp.wYear;
251 if (!SystemTimeToFileTime(&tmp, &tmp_ft))
252 return -2;
254 if (weekofmonth == 5)
256 LONGLONG t, one_day;
258 t = tmp_ft.dwHighDateTime;
259 t <<= 32;
260 t += (UINT)tmp_ft.dwLowDateTime;
262 /* subtract one day */
263 one_day = 24*60*60;
264 one_day *= 10000000;
265 t -= one_day;
267 tmp_ft.dwLowDateTime = (UINT)t;
268 tmp_ft.dwHighDateTime = (UINT)(t >> 32);
271 if (!FileTimeToSystemTime(&tmp_ft, &tmp))
272 return -2;
274 if (weekofmonth == 5)
276 /* calculate the last matching day of the week in this month */
277 int dif = tmp.wDayOfWeek - compareDate->wDayOfWeek;
278 if (dif < 0)
279 dif += 7;
281 limit_day = tmp.wDay - dif;
283 else
285 /* calculate the matching day of the week in the given week */
286 int dif = compareDate->wDayOfWeek - tmp.wDayOfWeek;
287 if (dif < 0)
288 dif += 7;
290 limit_day = tmp.wDay + 7*(weekofmonth-1) + dif;
293 else
295 limit_day = compareDate->wDay;
298 if (date->wDay < limit_day)
299 return -1;
301 if (date->wDay > limit_day)
302 return 1;
304 return 0; /* date is equal to the date limit. */
308 /***********************************************************************
309 * _GetTimezoneBias
311 * Calculates the local time bias for a given time zone
313 * RETURNS
315 * Returns TRUE when the time zone bias was calculated.
318 static BOOL _GetTimezoneBias(
319 const LPTIME_ZONE_INFORMATION lpTimeZoneInformation, /* [in] The time zone data. */
320 LPSYSTEMTIME lpSystemTime, /* [in] The system time. */
321 LONG* pBias) /* [out] The calulated bias in minutes */
323 int ret;
324 BOOL beforeStandardDate, afterDaylightDate;
325 BOOL daylightsaving = FALSE;
326 LONG bias = lpTimeZoneInformation->Bias;
328 if (lpTimeZoneInformation->DaylightDate.wMonth != 0)
330 if (lpTimeZoneInformation->StandardDate.wMonth == 0 ||
331 lpTimeZoneInformation->StandardDate.wDay<1 ||
332 lpTimeZoneInformation->StandardDate.wDay>5 ||
333 lpTimeZoneInformation->DaylightDate.wDay<1 ||
334 lpTimeZoneInformation->DaylightDate.wDay>5)
336 SetLastError(ERROR_INVALID_PARAMETER);
337 return FALSE;
340 /* check for daylight saving */
341 ret = _DayLightCompareDate(lpSystemTime, &lpTimeZoneInformation->StandardDate);
342 if (ret == -2)
343 return FALSE;
345 beforeStandardDate = ret < 0;
347 ret = _DayLightCompareDate(lpSystemTime, &lpTimeZoneInformation->DaylightDate);
348 if (ret == -2)
349 return FALSE;
351 afterDaylightDate = ret >= 0;
353 if (beforeStandardDate && afterDaylightDate)
354 daylightsaving = TRUE;
357 if (daylightsaving)
358 bias += lpTimeZoneInformation->DaylightBias;
359 else if (lpTimeZoneInformation->StandardDate.wMonth != 0)
360 bias += lpTimeZoneInformation->StandardBias;
362 *pBias = bias;
364 return TRUE;
368 /***********************************************************************
369 * SystemTimeToTzSpecificLocalTime (KERNEL32.@)
371 * Convert a utc system time to a local time in a given time zone.
373 * RETURNS
374 * Success: TRUE. lpLocalTime contains the converted time
375 * Failure: FALSE.
378 BOOL WINAPI SystemTimeToTzSpecificLocalTime(
379 LPTIME_ZONE_INFORMATION lpTimeZoneInformation, /* [in] The desired time zone. */
380 LPSYSTEMTIME lpUniversalTime, /* [in] The utc time to base local time on. */
381 LPSYSTEMTIME lpLocalTime) /* [out] The local time in the time zone. */
383 FILETIME ft;
384 LONG lBias;
385 LONGLONG t, bias;
386 TIME_ZONE_INFORMATION tzinfo;
388 if (lpTimeZoneInformation != NULL)
390 memcpy(&tzinfo, lpTimeZoneInformation, sizeof(TIME_ZONE_INFORMATION));
392 else
394 if (GetTimeZoneInformation(&tzinfo) == TIME_ZONE_ID_INVALID)
395 return FALSE;
398 if (!SystemTimeToFileTime(lpUniversalTime, &ft))
399 return FALSE;
401 t = ft.dwHighDateTime;
402 t <<= 32;
403 t += (UINT)ft.dwLowDateTime;
405 if (!_GetTimezoneBias(&tzinfo, lpUniversalTime, &lBias))
406 return FALSE;
408 bias = (LONGLONG)lBias * 600000000; /* 60 seconds per minute, 100000 [100-nanoseconds-ticks] per second */
409 t -= bias;
411 ft.dwLowDateTime = (UINT)t;
412 ft.dwHighDateTime = (UINT)(t >> 32);
414 return FileTimeToSystemTime(&ft, lpLocalTime);
418 /***********************************************************************
419 * TzSpecificLocalTimeToSystemTime (KERNEL32.@)
421 * Converts a local time to a time in utc.
423 * RETURNS
424 * Success: TRUE. lpUniversalTime contains the converted time
425 * Failure: FALSE.
427 BOOL WINAPI TzSpecificLocalTimeToSystemTime(
428 LPTIME_ZONE_INFORMATION lpTimeZoneInformation, /* [in] The desired time zone. */
429 LPSYSTEMTIME lpLocalTime, /* [in] The local time. */
430 LPSYSTEMTIME lpUniversalTime) /* [out] The calculated utc time. */
432 FILETIME ft;
433 LONG lBias;
434 LONGLONG t, bias;
435 TIME_ZONE_INFORMATION tzinfo;
437 if (lpTimeZoneInformation != NULL)
439 memcpy(&tzinfo, lpTimeZoneInformation, sizeof(TIME_ZONE_INFORMATION));
441 else
443 if (GetTimeZoneInformation(&tzinfo) == TIME_ZONE_ID_INVALID)
444 return FALSE;
447 if (!SystemTimeToFileTime(lpLocalTime, &ft))
448 return FALSE;
450 t = ft.dwHighDateTime;
451 t <<= 32;
452 t += (UINT)ft.dwLowDateTime;
454 if (!_GetTimezoneBias(&tzinfo, lpLocalTime, &lBias))
455 return FALSE;
457 bias = (LONGLONG)lBias * 600000000; /* 60 seconds per minute, 100000 [100-nanoseconds-ticks] per second */
458 t += bias;
460 ft.dwLowDateTime = (UINT)t;
461 ft.dwHighDateTime = (UINT)(t >> 32);
463 return FileTimeToSystemTime(&ft, lpUniversalTime);
467 /***********************************************************************
468 * GetSystemTimeAsFileTime (KERNEL32.@)
470 * Get the current time in utc format.
472 * RETURNS
473 * Nothing.
475 VOID WINAPI GetSystemTimeAsFileTime(
476 LPFILETIME time) /* [out] Destination for the current utc time */
478 LARGE_INTEGER t;
479 NtQuerySystemTime( &t );
480 time->dwLowDateTime = t.u.LowPart;
481 time->dwHighDateTime = t.u.HighPart;
485 /*********************************************************************
486 * TIME_ClockTimeToFileTime (olorin@fandra.org, 20-Sep-1998)
488 * Used by GetProcessTimes to convert clock_t into FILETIME.
490 * Differences to UnixTimeToFileTime:
491 * 1) Divided by CLK_TCK
492 * 2) Time is relative. There is no 'starting date', so there is
493 * no need for offset correction, like in UnixTimeToFileTime
495 static void TIME_ClockTimeToFileTime(clock_t unix_time, LPFILETIME filetime)
497 ULONGLONG secs = RtlEnlargedUnsignedMultiply( unix_time, 10000000 );
498 secs = RtlExtendedLargeIntegerDivide( secs, CLK_TCK, NULL );
499 filetime->dwLowDateTime = (DWORD)secs;
500 filetime->dwHighDateTime = (DWORD)(secs >> 32);
503 /*********************************************************************
504 * GetProcessTimes (KERNEL32.@)
506 * Get the user and kernel execution times of a process,
507 * along with the creation and exit times if known.
509 * RETURNS
510 * TRUE.
512 * NOTES
513 * olorin@fandra.org:
514 * Would be nice to subtract the cpu time used by Wine at startup.
515 * Also, there is a need to separate times used by different applications.
517 * BUGS
518 * lpCreationTime and lpExitTime are not initialised in the Wine implementation.
520 BOOL WINAPI GetProcessTimes(
521 HANDLE hprocess, /* [in] The process to be queried (obtained from PROCESS_QUERY_INFORMATION). */
522 LPFILETIME lpCreationTime, /* [out] The creation time of the process. */
523 LPFILETIME lpExitTime, /* [out] The exit time of the process if exited. */
524 LPFILETIME lpKernelTime, /* [out] The time spent in kernal routines in 100's of nanoseconds. */
525 LPFILETIME lpUserTime) /* [out] The time spent in user routines in 100's of nanoseconds. */
527 struct tms tms;
529 times(&tms);
530 TIME_ClockTimeToFileTime(tms.tms_utime,lpUserTime);
531 TIME_ClockTimeToFileTime(tms.tms_stime,lpKernelTime);
532 return TRUE;
535 /*********************************************************************
536 * GetCalendarInfoA (KERNEL32.@)
539 int WINAPI GetCalendarInfoA(LCID lcid, CALID Calendar, CALTYPE CalType,
540 LPSTR lpCalData, int cchData, LPDWORD lpValue)
542 int ret;
543 LPWSTR lpCalDataW = NULL;
545 FIXME("(%08lx,%08lx,%08lx,%p,%d,%p): quarter-stub\n",
546 lcid, Calendar, CalType, lpCalData, cchData, lpValue);
548 lcid = ConvertDefaultLocale(lcid);
550 if (NLS_IsUnicodeOnlyLcid(lcid))
552 SetLastError(ERROR_INVALID_PARAMETER);
553 return 0;
556 if (cchData &&
557 !(lpCalDataW = HeapAlloc(GetProcessHeap(), 0, cchData*sizeof(WCHAR))))
558 return 0;
560 ret = GetCalendarInfoW(lcid, Calendar, CalType, lpCalDataW, cchData, lpValue);
561 if(ret && lpCalDataW && lpCalData)
562 WideCharToMultiByte(CP_ACP, 0, lpCalDataW, cchData, lpCalData, cchData, NULL, NULL);
563 if(lpCalDataW)
564 HeapFree(GetProcessHeap(), 0, lpCalDataW);
566 return ret;
569 /*********************************************************************
570 * GetCalendarInfoW (KERNEL32.@)
572 * See GetCalendarInfoA.
574 int WINAPI GetCalendarInfoW(LCID Locale, CALID Calendar, CALTYPE CalType,
575 LPWSTR lpCalData, int cchData, LPDWORD lpValue)
577 FIXME("(%08lx,%08lx,%08lx,%p,%d,%p): quarter-stub\n",
578 Locale, Calendar, CalType, lpCalData, cchData, lpValue);
580 if (CalType & CAL_NOUSEROVERRIDE)
581 FIXME("flag CAL_NOUSEROVERRIDE used, not fully implemented\n");
582 if (CalType & CAL_USE_CP_ACP)
583 FIXME("flag CAL_USE_CP_ACP used, not fully implemented\n");
585 if (CalType & CAL_RETURN_NUMBER) {
586 if (lpCalData != NULL)
587 WARN("lpCalData not NULL (%p) when it should!\n", lpCalData);
588 if (cchData != 0)
589 WARN("cchData not 0 (%d) when it should!\n", cchData);
590 } else {
591 if (lpValue != NULL)
592 WARN("lpValue not NULL (%p) when it should!\n", lpValue);
595 /* FIXME: No verification is made yet wrt Locale
596 * for the CALTYPES not requiring GetLocaleInfoA */
597 switch (CalType & ~(CAL_NOUSEROVERRIDE|CAL_RETURN_NUMBER|CAL_USE_CP_ACP)) {
598 case CAL_ICALINTVALUE:
599 FIXME("Unimplemented caltype %ld\n", CalType & 0xffff);
600 return E_FAIL;
601 case CAL_SCALNAME:
602 FIXME("Unimplemented caltype %ld\n", CalType & 0xffff);
603 return E_FAIL;
604 case CAL_IYEAROFFSETRANGE:
605 FIXME("Unimplemented caltype %ld\n", CalType & 0xffff);
606 return E_FAIL;
607 case CAL_SERASTRING:
608 FIXME("Unimplemented caltype %ld\n", CalType & 0xffff);
609 return E_FAIL;
610 case CAL_SSHORTDATE:
611 return GetLocaleInfoW(Locale, LOCALE_SSHORTDATE, lpCalData, cchData);
612 case CAL_SLONGDATE:
613 return GetLocaleInfoW(Locale, LOCALE_SLONGDATE, lpCalData, cchData);
614 case CAL_SDAYNAME1:
615 return GetLocaleInfoW(Locale, LOCALE_SDAYNAME1, lpCalData, cchData);
616 case CAL_SDAYNAME2:
617 return GetLocaleInfoW(Locale, LOCALE_SDAYNAME2, lpCalData, cchData);
618 case CAL_SDAYNAME3:
619 return GetLocaleInfoW(Locale, LOCALE_SDAYNAME3, lpCalData, cchData);
620 case CAL_SDAYNAME4:
621 return GetLocaleInfoW(Locale, LOCALE_SDAYNAME4, lpCalData, cchData);
622 case CAL_SDAYNAME5:
623 return GetLocaleInfoW(Locale, LOCALE_SDAYNAME5, lpCalData, cchData);
624 case CAL_SDAYNAME6:
625 return GetLocaleInfoW(Locale, LOCALE_SDAYNAME6, lpCalData, cchData);
626 case CAL_SDAYNAME7:
627 return GetLocaleInfoW(Locale, LOCALE_SDAYNAME7, lpCalData, cchData);
628 case CAL_SABBREVDAYNAME1:
629 return GetLocaleInfoW(Locale, LOCALE_SABBREVDAYNAME1, lpCalData, cchData);
630 case CAL_SABBREVDAYNAME2:
631 return GetLocaleInfoW(Locale, LOCALE_SABBREVDAYNAME2, lpCalData, cchData);
632 case CAL_SABBREVDAYNAME3:
633 return GetLocaleInfoW(Locale, LOCALE_SABBREVDAYNAME3, lpCalData, cchData);
634 case CAL_SABBREVDAYNAME4:
635 return GetLocaleInfoW(Locale, LOCALE_SABBREVDAYNAME4, lpCalData, cchData);
636 case CAL_SABBREVDAYNAME5:
637 return GetLocaleInfoW(Locale, LOCALE_SABBREVDAYNAME5, lpCalData, cchData);
638 case CAL_SABBREVDAYNAME6:
639 return GetLocaleInfoW(Locale, LOCALE_SABBREVDAYNAME6, lpCalData, cchData);
640 case CAL_SABBREVDAYNAME7:
641 return GetLocaleInfoW(Locale, LOCALE_SABBREVDAYNAME7, lpCalData, cchData);
642 case CAL_SMONTHNAME1:
643 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME1, lpCalData, cchData);
644 case CAL_SMONTHNAME2:
645 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME2, lpCalData, cchData);
646 case CAL_SMONTHNAME3:
647 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME3, lpCalData, cchData);
648 case CAL_SMONTHNAME4:
649 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME4, lpCalData, cchData);
650 case CAL_SMONTHNAME5:
651 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME5, lpCalData, cchData);
652 case CAL_SMONTHNAME6:
653 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME6, lpCalData, cchData);
654 case CAL_SMONTHNAME7:
655 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME7, lpCalData, cchData);
656 case CAL_SMONTHNAME8:
657 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME8, lpCalData, cchData);
658 case CAL_SMONTHNAME9:
659 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME9, lpCalData, cchData);
660 case CAL_SMONTHNAME10:
661 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME10, lpCalData, cchData);
662 case CAL_SMONTHNAME11:
663 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME11, lpCalData, cchData);
664 case CAL_SMONTHNAME12:
665 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME12, lpCalData, cchData);
666 case CAL_SMONTHNAME13:
667 return GetLocaleInfoW(Locale, LOCALE_SMONTHNAME13, lpCalData, cchData);
668 case CAL_SABBREVMONTHNAME1:
669 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME1, lpCalData, cchData);
670 case CAL_SABBREVMONTHNAME2:
671 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME2, lpCalData, cchData);
672 case CAL_SABBREVMONTHNAME3:
673 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME3, lpCalData, cchData);
674 case CAL_SABBREVMONTHNAME4:
675 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME4, lpCalData, cchData);
676 case CAL_SABBREVMONTHNAME5:
677 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME5, lpCalData, cchData);
678 case CAL_SABBREVMONTHNAME6:
679 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME6, lpCalData, cchData);
680 case CAL_SABBREVMONTHNAME7:
681 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME7, lpCalData, cchData);
682 case CAL_SABBREVMONTHNAME8:
683 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME8, lpCalData, cchData);
684 case CAL_SABBREVMONTHNAME9:
685 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME9, lpCalData, cchData);
686 case CAL_SABBREVMONTHNAME10:
687 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME10, lpCalData, cchData);
688 case CAL_SABBREVMONTHNAME11:
689 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME11, lpCalData, cchData);
690 case CAL_SABBREVMONTHNAME12:
691 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME12, lpCalData, cchData);
692 case CAL_SABBREVMONTHNAME13:
693 return GetLocaleInfoW(Locale, LOCALE_SABBREVMONTHNAME13, lpCalData, cchData);
694 case CAL_SYEARMONTH:
695 return GetLocaleInfoW(Locale, LOCALE_SYEARMONTH, lpCalData, cchData);
696 case CAL_ITWODIGITYEARMAX:
697 if (lpValue) *lpValue = CALINFO_MAX_YEAR;
698 break;
699 default: MESSAGE("Unknown caltype %ld\n",CalType & 0xffff);
700 return E_FAIL;
702 return 0;
705 /*********************************************************************
706 * SetCalendarInfoA (KERNEL32.@)
709 int WINAPI SetCalendarInfoA(LCID Locale, CALID Calendar, CALTYPE CalType, LPCSTR lpCalData)
711 FIXME("(%08lx,%08lx,%08lx,%s): stub\n",
712 Locale, Calendar, CalType, debugstr_a(lpCalData));
713 return 0;
716 /*********************************************************************
717 * SetCalendarInfoW (KERNEL32.@)
719 * See SetCalendarInfoA.
721 int WINAPI SetCalendarInfoW(LCID Locale, CALID Calendar, CALTYPE CalType, LPCWSTR lpCalData)
723 FIXME("(%08lx,%08lx,%08lx,%s): stub\n",
724 Locale, Calendar, CalType, debugstr_w(lpCalData));
725 return 0;
728 /*********************************************************************
729 * LocalFileTimeToFileTime (KERNEL32.@)
731 BOOL WINAPI LocalFileTimeToFileTime( const FILETIME *localft, LPFILETIME utcft )
733 NTSTATUS status;
734 LARGE_INTEGER local, utc;
736 local.u.LowPart = localft->dwLowDateTime;
737 local.u.HighPart = localft->dwHighDateTime;
738 if (!(status = RtlLocalTimeToSystemTime( &local, &utc )))
740 utcft->dwLowDateTime = utc.u.LowPart;
741 utcft->dwHighDateTime = utc.u.HighPart;
743 else SetLastError( RtlNtStatusToDosError(status) );
745 return !status;
748 /*********************************************************************
749 * FileTimeToLocalFileTime (KERNEL32.@)
751 BOOL WINAPI FileTimeToLocalFileTime( const FILETIME *utcft, LPFILETIME localft )
753 NTSTATUS status;
754 LARGE_INTEGER local, utc;
756 utc.u.LowPart = utcft->dwLowDateTime;
757 utc.u.HighPart = utcft->dwHighDateTime;
758 if (!(status = RtlSystemTimeToLocalTime( &utc, &local )))
760 localft->dwLowDateTime = local.u.LowPart;
761 localft->dwHighDateTime = local.u.HighPart;
763 else SetLastError( RtlNtStatusToDosError(status) );
765 return !status;
768 /*********************************************************************
769 * FileTimeToSystemTime (KERNEL32.@)
771 BOOL WINAPI FileTimeToSystemTime( const FILETIME *ft, LPSYSTEMTIME syst )
773 TIME_FIELDS tf;
774 LARGE_INTEGER t;
776 t.u.LowPart = ft->dwLowDateTime;
777 t.u.HighPart = ft->dwHighDateTime;
778 RtlTimeToTimeFields(&t, &tf);
780 syst->wYear = tf.Year;
781 syst->wMonth = tf.Month;
782 syst->wDay = tf.Day;
783 syst->wHour = tf.Hour;
784 syst->wMinute = tf.Minute;
785 syst->wSecond = tf.Second;
786 syst->wMilliseconds = tf.Milliseconds;
787 syst->wDayOfWeek = tf.Weekday;
788 return TRUE;
791 /*********************************************************************
792 * SystemTimeToFileTime (KERNEL32.@)
794 BOOL WINAPI SystemTimeToFileTime( const SYSTEMTIME *syst, LPFILETIME ft )
796 TIME_FIELDS tf;
797 LARGE_INTEGER t;
799 tf.Year = syst->wYear;
800 tf.Month = syst->wMonth;
801 tf.Day = syst->wDay;
802 tf.Hour = syst->wHour;
803 tf.Minute = syst->wMinute;
804 tf.Second = syst->wSecond;
805 tf.Milliseconds = syst->wMilliseconds;
807 RtlTimeFieldsToTime(&tf, &t);
808 ft->dwLowDateTime = t.u.LowPart;
809 ft->dwHighDateTime = t.u.HighPart;
810 return TRUE;
813 /*********************************************************************
814 * CompareFileTime (KERNEL32.@)
816 * Compare two FILETIME's to each other.
818 * PARAMS
819 * x [I] First time
820 * y [I] time to compare to x
822 * RETURNS
823 * -1, 0, or 1 indicating that x is less than, equal to, or greater
824 * than y respectively.
826 INT WINAPI CompareFileTime( const FILETIME *x, const FILETIME *y )
828 if (!x || !y) return -1;
830 if (x->dwHighDateTime > y->dwHighDateTime)
831 return 1;
832 if (x->dwHighDateTime < y->dwHighDateTime)
833 return -1;
834 if (x->dwLowDateTime > y->dwLowDateTime)
835 return 1;
836 if (x->dwLowDateTime < y->dwLowDateTime)
837 return -1;
838 return 0;
841 /*********************************************************************
842 * GetLocalTime (KERNEL32.@)
844 * Get the current local time.
846 * RETURNS
847 * Nothing.
849 VOID WINAPI GetLocalTime(LPSYSTEMTIME systime) /* [O] Destination for current time */
851 FILETIME lft;
852 LARGE_INTEGER ft, ft2;
854 NtQuerySystemTime(&ft);
855 RtlSystemTimeToLocalTime(&ft, &ft2);
856 lft.dwLowDateTime = ft2.u.LowPart;
857 lft.dwHighDateTime = ft2.u.HighPart;
858 FileTimeToSystemTime(&lft, systime);
861 /*********************************************************************
862 * GetSystemTime (KERNEL32.@)
864 * Get the current system time.
866 * RETURNS
867 * Nothing.
869 VOID WINAPI GetSystemTime(LPSYSTEMTIME systime) /* [O] Destination for current time */
871 FILETIME ft;
872 LARGE_INTEGER t;
874 NtQuerySystemTime(&t);
875 ft.dwLowDateTime = t.u.LowPart;
876 ft.dwHighDateTime = t.u.HighPart;
877 FileTimeToSystemTime(&ft, systime);
880 /*********************************************************************
881 * GetDaylightFlag (KERNEL32.@)
883 * returns TRUE if daylight saving time is in operation
885 * Note: this function is called from the Win98's control applet
886 * timedate.cpl
888 BOOL WINAPI GetDaylightFlag(void)
890 time_t t = time(NULL);
891 struct tm *ptm = localtime( &t);
892 return ptm->tm_isdst > 0;