2 * msvcrt.dll date/time functions
4 * Copyright 1996,1998 Marcus Meissner
5 * Copyright 1996 Jukka Iivonen
6 * Copyright 1997,2000 Uwe Bonnes
7 * Copyright 2000 Jon Griffiths
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 #ifdef HAVE_SYS_TIMES_H
28 # include <sys/times.h>
32 #include "msvcrt/sys/timeb.h"
33 #include "msvcrt/time.h"
37 #include "wine/debug.h"
39 WINE_DEFAULT_DEBUG_CHANNEL(msvcrt);
41 /* INTERNAL: Return formatted current time/date */
42 char* msvcrt_get_current_time(char* out, const char* format)
44 static const MSVCRT_time_t bad_time = (MSVCRT_time_t)-1;
46 struct tm *_tm = NULL;
49 if (time(&t) != bad_time && (_tm = localtime(&t)) &&
50 strftime(out,9,format,_tm) == 8)
55 /**********************************************************************
58 MSVCRT_time_t MSVCRT_mktime(struct MSVCRT_tm *t)
63 tm.tm_sec = t->tm_sec;
64 tm.tm_min = t->tm_min;
65 tm.tm_hour = t->tm_hour;
66 tm.tm_mday = t->tm_mday;
67 tm.tm_mon = t->tm_mon;
68 tm.tm_year = t->tm_year;
69 tm.tm_isdst = t->tm_isdst;
73 t->tm_sec = tm.tm_sec;
74 t->tm_min = tm.tm_min;
75 t->tm_hour = tm.tm_hour;
76 t->tm_mday = tm.tm_mday;
77 t->tm_mon = tm.tm_mon;
78 t->tm_year = tm.tm_year;
79 t->tm_isdst = tm.tm_isdst;
84 /**********************************************************************
87 char* _strdate(char* date)
89 return msvcrt_get_current_time(date,"%m/%d/%y");
92 /*********************************************************************
95 char* _strtime(char* date)
97 return msvcrt_get_current_time(date,"%H:%M:%S");
100 /*********************************************************************
103 MSVCRT_clock_t MSVCRT_clock(void)
109 res = alltimes.tms_utime + alltimes.tms_stime +
110 alltimes.tms_cutime + alltimes.tms_cstime;
111 /* FIXME: We need some symbolic representation for CLOCKS_PER_SEC,
112 * 10 holds only for Windows/Linux_i86)
117 /*********************************************************************
118 * difftime (MSVCRT.@)
120 double MSVCRT_difftime(MSVCRT_time_t time1, MSVCRT_time_t time2)
122 return (double)(time1 - time2);
125 /*********************************************************************
128 MSVCRT_time_t MSVCRT_time(MSVCRT_time_t* buf)
130 MSVCRT_time_t curtime = time(NULL);
131 return buf ? *buf = curtime : curtime;
134 #define SECSPERDAY 86400
135 /* 1601 to 1970 is 369 years plus 89 leap days */
136 #define SECS_1601_TO_1970 ((369 * 365 + 89) * (ULONGLONG)SECSPERDAY)
137 #define TICKSPERSEC 10000000
138 #define TICKSPERMSEC 10000
140 /*********************************************************************
143 void _ftime(struct _timeb *buf)
145 TIME_ZONE_INFORMATION tzinfo;
149 DWORD tzid = GetTimeZoneInformation(&tzinfo);
150 GetSystemTimeAsFileTime(&ft);
152 time = ((ULONGLONG)ft.dwHighDateTime << 32) | ft.dwLowDateTime;
154 buf->time = time / TICKSPERSEC - SECS_1601_TO_1970;
155 buf->millitm = (time % TICKSPERSEC) / TICKSPERMSEC;
156 buf->timezone = tzinfo.Bias;
157 buf->dstflag = (tzid == TIME_ZONE_ID_DAYLIGHT?1:0);
160 /*********************************************************************
161 * _daylight (MSVCRT.@)
163 int MSVCRT___daylight = 1; /* FIXME: assume daylight */
165 /*********************************************************************
166 * __p_daylight (MSVCRT.@)
168 void *MSVCRT___p__daylight(void)
170 return &MSVCRT___daylight;