2001-01-10 23:59:25 +00:00
|
|
|
/*
|
|
|
|
* msvcrt.dll date/time functions
|
|
|
|
*
|
|
|
|
* Copyright 1996,1998 Marcus Meissner
|
|
|
|
* Copyright 1996 Jukka Iivonen
|
|
|
|
* Copyright 1997,2000 Uwe Bonnes
|
|
|
|
* Copyright 2000 Jon Griffiths
|
2002-03-09 23:29:33 +00:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
2001-01-10 23:59:25 +00:00
|
|
|
*/
|
2001-04-23 18:22:33 +00:00
|
|
|
|
2002-08-26 21:53:24 +00:00
|
|
|
#include "config.h"
|
|
|
|
|
2001-01-10 23:59:25 +00:00
|
|
|
#include <time.h>
|
2002-08-26 21:53:24 +00:00
|
|
|
#ifdef HAVE_SYS_TIMES_H
|
|
|
|
# include <sys/times.h>
|
|
|
|
#endif
|
2001-01-10 23:59:25 +00:00
|
|
|
|
2001-04-23 18:22:33 +00:00
|
|
|
#include "msvcrt.h"
|
2001-04-10 23:25:25 +00:00
|
|
|
#include "msvcrt/sys/timeb.h"
|
|
|
|
#include "msvcrt/time.h"
|
2001-01-10 23:59:25 +00:00
|
|
|
|
2004-03-11 00:43:47 +00:00
|
|
|
#include "winbase.h"
|
2001-04-10 23:25:25 +00:00
|
|
|
|
2002-01-22 00:57:16 +00:00
|
|
|
#include "wine/debug.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(msvcrt);
|
2001-01-10 23:59:25 +00:00
|
|
|
|
|
|
|
/* INTERNAL: Return formatted current time/date */
|
2001-04-10 21:16:07 +00:00
|
|
|
char* msvcrt_get_current_time(char* out, const char* format)
|
2001-01-10 23:59:25 +00:00
|
|
|
{
|
2001-04-10 23:25:25 +00:00
|
|
|
static const MSVCRT_time_t bad_time = (MSVCRT_time_t)-1;
|
2001-01-10 23:59:25 +00:00
|
|
|
time_t t;
|
|
|
|
struct tm *_tm = NULL;
|
|
|
|
char *retval = NULL;
|
|
|
|
|
|
|
|
if (time(&t) != bad_time && (_tm = localtime(&t)) &&
|
|
|
|
strftime(out,9,format,_tm) == 8)
|
|
|
|
retval = out;
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2001-11-12 15:47:26 +00:00
|
|
|
/**********************************************************************
|
|
|
|
* mktime (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
MSVCRT_time_t MSVCRT_mktime(struct MSVCRT_tm *t)
|
|
|
|
{
|
2001-12-05 22:08:46 +00:00
|
|
|
MSVCRT_time_t res;
|
|
|
|
struct tm tm;
|
2001-11-12 15:47:26 +00:00
|
|
|
|
2001-12-05 22:08:46 +00:00
|
|
|
tm.tm_sec = t->tm_sec;
|
|
|
|
tm.tm_min = t->tm_min;
|
|
|
|
tm.tm_hour = t->tm_hour;
|
|
|
|
tm.tm_mday = t->tm_mday;
|
|
|
|
tm.tm_mon = t->tm_mon;
|
|
|
|
tm.tm_year = t->tm_year;
|
|
|
|
tm.tm_isdst = t->tm_isdst;
|
|
|
|
res = mktime(&tm);
|
|
|
|
if (res != -1)
|
|
|
|
{
|
|
|
|
t->tm_sec = tm.tm_sec;
|
|
|
|
t->tm_min = tm.tm_min;
|
|
|
|
t->tm_hour = tm.tm_hour;
|
|
|
|
t->tm_mday = tm.tm_mday;
|
|
|
|
t->tm_mon = tm.tm_mon;
|
|
|
|
t->tm_year = tm.tm_year;
|
|
|
|
t->tm_isdst = tm.tm_isdst;
|
|
|
|
}
|
|
|
|
return res;
|
2001-11-12 15:47:26 +00:00
|
|
|
}
|
|
|
|
|
2001-01-10 23:59:25 +00:00
|
|
|
/**********************************************************************
|
|
|
|
* _strdate (MSVCRT.@)
|
|
|
|
*/
|
2001-04-10 21:16:07 +00:00
|
|
|
char* _strdate(char* date)
|
2001-01-10 23:59:25 +00:00
|
|
|
{
|
2001-04-10 21:16:07 +00:00
|
|
|
return msvcrt_get_current_time(date,"%m/%d/%y");
|
2001-01-10 23:59:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _strtime (MSVCRT.@)
|
|
|
|
*/
|
2001-04-10 21:16:07 +00:00
|
|
|
char* _strtime(char* date)
|
2001-01-10 23:59:25 +00:00
|
|
|
{
|
2001-04-10 21:16:07 +00:00
|
|
|
return msvcrt_get_current_time(date,"%H:%M:%S");
|
2001-01-10 23:59:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* clock (MSVCRT.@)
|
|
|
|
*/
|
2001-04-16 18:54:31 +00:00
|
|
|
MSVCRT_clock_t MSVCRT_clock(void)
|
2001-01-10 23:59:25 +00:00
|
|
|
{
|
|
|
|
struct tms alltimes;
|
|
|
|
clock_t res;
|
|
|
|
|
|
|
|
times(&alltimes);
|
|
|
|
res = alltimes.tms_utime + alltimes.tms_stime +
|
|
|
|
alltimes.tms_cutime + alltimes.tms_cstime;
|
|
|
|
/* FIXME: We need some symbolic representation for CLOCKS_PER_SEC,
|
|
|
|
* 10 holds only for Windows/Linux_i86)
|
|
|
|
*/
|
|
|
|
return 10*res;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* difftime (MSVCRT.@)
|
|
|
|
*/
|
2001-04-10 23:25:25 +00:00
|
|
|
double MSVCRT_difftime(MSVCRT_time_t time1, MSVCRT_time_t time2)
|
2001-01-10 23:59:25 +00:00
|
|
|
{
|
|
|
|
return (double)(time1 - time2);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* time (MSVCRT.@)
|
|
|
|
*/
|
2001-04-10 23:25:25 +00:00
|
|
|
MSVCRT_time_t MSVCRT_time(MSVCRT_time_t* buf)
|
2001-01-10 23:59:25 +00:00
|
|
|
{
|
2001-04-10 23:25:25 +00:00
|
|
|
MSVCRT_time_t curtime = time(NULL);
|
2001-01-10 23:59:25 +00:00
|
|
|
return buf ? *buf = curtime : curtime;
|
|
|
|
}
|
|
|
|
|
2004-03-11 00:43:47 +00:00
|
|
|
#define SECSPERDAY 86400
|
|
|
|
/* 1601 to 1970 is 369 years plus 89 leap days */
|
|
|
|
#define SECS_1601_TO_1970 ((369 * 365 + 89) * (ULONGLONG)SECSPERDAY)
|
|
|
|
#define TICKSPERSEC 10000000
|
|
|
|
#define TICKSPERMSEC 10000
|
|
|
|
|
2001-01-10 23:59:25 +00:00
|
|
|
/*********************************************************************
|
|
|
|
* _ftime (MSVCRT.@)
|
|
|
|
*/
|
2001-04-10 23:25:25 +00:00
|
|
|
void _ftime(struct _timeb *buf)
|
2001-01-10 23:59:25 +00:00
|
|
|
{
|
2004-03-11 00:43:47 +00:00
|
|
|
TIME_ZONE_INFORMATION tzinfo;
|
|
|
|
FILETIME ft;
|
|
|
|
ULONGLONG time;
|
|
|
|
|
|
|
|
DWORD tzid = GetTimeZoneInformation(&tzinfo);
|
|
|
|
GetSystemTimeAsFileTime(&ft);
|
|
|
|
|
|
|
|
time = ((ULONGLONG)ft.dwHighDateTime << 32) | ft.dwLowDateTime;
|
|
|
|
|
|
|
|
buf->time = time / TICKSPERSEC - SECS_1601_TO_1970;
|
|
|
|
buf->millitm = (time % TICKSPERSEC) / TICKSPERMSEC;
|
|
|
|
buf->timezone = tzinfo.Bias;
|
|
|
|
buf->dstflag = (tzid == TIME_ZONE_ID_DAYLIGHT?1:0);
|
2001-01-10 23:59:25 +00:00
|
|
|
}
|
2003-03-04 02:19:15 +00:00
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _daylight (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
int MSVCRT___daylight = 1; /* FIXME: assume daylight */
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* __p_daylight (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
void *MSVCRT___p__daylight(void)
|
|
|
|
{
|
|
|
|
return &MSVCRT___daylight;
|
|
|
|
}
|