Release 990815.
[wine/multimedia.git] / win32 / time.c
blobcbb5a8ea5ada3bace50065a01a28ecc00267537a
1 /*
2 * Win32 kernel functions
4 * Copyright 1995 Martin von Loewis and Cameron Heide
5 */
7 #include <string.h>
8 #include <time.h>
9 #include <sys/time.h>
10 #include <unistd.h>
11 #include "file.h"
12 #include "winerror.h"
13 #include "debugtools.h"
15 DEFAULT_DEBUG_CHANNEL(win32)
17 /***********************************************************************
18 * GetLocalTime (KERNEL32.228)
20 VOID WINAPI GetLocalTime(LPSYSTEMTIME systime)
22 time_t local_time;
23 struct tm *local_tm;
24 struct timeval tv;
26 gettimeofday(&tv, NULL);
27 local_time = tv.tv_sec;
28 local_tm = localtime(&local_time);
30 systime->wYear = local_tm->tm_year + 1900;
31 systime->wMonth = local_tm->tm_mon + 1;
32 systime->wDayOfWeek = local_tm->tm_wday;
33 systime->wDay = local_tm->tm_mday;
34 systime->wHour = local_tm->tm_hour;
35 systime->wMinute = local_tm->tm_min;
36 systime->wSecond = local_tm->tm_sec;
37 systime->wMilliseconds = (tv.tv_usec / 1000) % 1000;
41 /***********************************************************************
42 * SetLocalTime (KERNEL32.655)
44 * FIXME: correct ? Is the timezone param of settimeofday() needed ?
45 * I don't have any docu about SetLocal/SystemTime(), argl...
47 BOOL WINAPI SetLocalTime(const SYSTEMTIME *systime)
49 struct timeval tv;
50 struct tm t;
51 time_t sec;
53 /* get the number of seconds */
54 t.tm_sec = systime->wSecond;
55 t.tm_min = systime->wMinute;
56 t.tm_hour = systime->wHour;
57 t.tm_mday = systime->wDay;
58 t.tm_mon = systime->wMonth;
59 t.tm_year = systime->wYear;
60 sec = mktime (&t);
62 /* set the new time */
63 tv.tv_sec = sec;
64 tv.tv_usec = systime->wMilliseconds * 1000;
65 return !settimeofday(&tv, NULL);
69 /***********************************************************************
70 * GetSystemTime (KERNEL32.285)
72 VOID WINAPI GetSystemTime(LPSYSTEMTIME systime)
74 time_t local_time;
75 struct tm *local_tm;
76 struct timeval tv;
78 gettimeofday(&tv, NULL);
79 local_time = tv.tv_sec;
80 local_tm = gmtime(&local_time);
82 systime->wYear = local_tm->tm_year + 1900;
83 systime->wMonth = local_tm->tm_mon + 1;
84 systime->wDayOfWeek = local_tm->tm_wday;
85 systime->wDay = local_tm->tm_mday;
86 systime->wHour = local_tm->tm_hour;
87 systime->wMinute = local_tm->tm_min;
88 systime->wSecond = local_tm->tm_sec;
89 systime->wMilliseconds = (tv.tv_usec / 1000) % 1000;
93 /***********************************************************************
94 * SetSystemTime (KERNEL32.507)
96 BOOL WINAPI SetSystemTime(const SYSTEMTIME *systime)
98 struct timeval tv;
99 struct timezone tz;
100 struct tm t;
101 time_t sec;
103 /* call gettimeofday to get the current timezone */
104 gettimeofday(&tv, &tz);
106 /* get the number of seconds */
107 t.tm_sec = systime->wSecond;
108 t.tm_min = systime->wMinute;
109 t.tm_hour = systime->wHour;
110 t.tm_mday = systime->wDay;
111 t.tm_mon = systime->wMonth;
112 t.tm_year = systime->wYear;
113 sec = mktime (&t);
115 /* set the new time */
116 tv.tv_sec = sec;
117 tv.tv_usec = systime->wMilliseconds * 1000;
118 return !settimeofday(&tv, &tz);
122 /***********************************************************************
123 * GetTimeZoneInformation (KERNEL32.302)
125 DWORD WINAPI GetTimeZoneInformation(LPTIME_ZONE_INFORMATION tzinfo)
127 time_t gmt, lt;
128 struct tm *ptm;
129 int daylight;
131 memset(tzinfo, 0, sizeof(TIME_ZONE_INFORMATION));
133 gmt = time(NULL);
134 ptm=localtime(&gmt);
135 daylight=ptm->tm_isdst;
137 ptm = gmtime(&gmt);
138 ptm->tm_isdst=daylight;
139 lt = mktime(ptm);
141 tzinfo->Bias = (lt - gmt) / 60;
142 tzinfo->StandardBias = 0;
143 tzinfo->DaylightBias = -60;
145 return TIME_ZONE_ID_UNKNOWN;
149 /***********************************************************************
150 * SetTimeZoneInformation (KERNEL32.515)
152 BOOL WINAPI SetTimeZoneInformation(const LPTIME_ZONE_INFORMATION tzinfo)
154 struct timezone tz;
156 tz.tz_minuteswest = tzinfo->Bias;
157 #ifdef DST_NONE
158 tz.tz_dsttime = DST_NONE;
159 #else
160 tz.tz_dsttime = 0;
161 #endif
162 return !settimeofday(NULL, &tz);
166 /***********************************************************************
167 * GetSystemTimeAsFileTime (KERNEL32)
169 VOID WINAPI GetSystemTimeAsFileTime(LPFILETIME systemtimeAsfiletime) {
170 DOSFS_UnixTimeToFileTime(time(NULL),systemtimeAsfiletime,0);
173 /***********************************************************************
174 * SystemTimeToTzSpecificLocalTime32 (KERNEL32.683)
176 BOOL WINAPI SystemTimeToTzSpecificLocalTime(
177 LPTIME_ZONE_INFORMATION lpTimeZoneInformation,
178 LPSYSTEMTIME lpUniversalTime,
179 LPSYSTEMTIME lpLocalTime) {
181 FIXME(":stub\n");
182 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
183 return FALSE;