initial import
This commit is contained in:
@ -2,7 +2,7 @@
|
||||
* $Id$
|
||||
*/
|
||||
|
||||
#include <ase/cmn/time.h>
|
||||
#include <qse/cmn/time.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
@ -11,28 +11,28 @@
|
||||
#include <time.h>
|
||||
#endif
|
||||
|
||||
#if defined(ASE_USE_SYSCALL) && defined(HAVE_SYS_SYSCALL_H)
|
||||
#if defined(QSE_USE_SYSCALL) && defined(HAVE_SYS_SYSCALL_H)
|
||||
#include <sys/syscall.h>
|
||||
#endif
|
||||
|
||||
#ifdef _WIN32
|
||||
#define WIN_EPOCH_YEAR ((ase_ntime_t)1601)
|
||||
#define WIN_EPOCH_MON ((ase_ntime_t)1)
|
||||
#define WIN_EPOCH_DAY ((ase_ntime_t)1)
|
||||
#define WIN_EPOCH_YEAR ((qse_ntime_t)1601)
|
||||
#define WIN_EPOCH_MON ((qse_ntime_t)1)
|
||||
#define WIN_EPOCH_DAY ((qse_ntime_t)1)
|
||||
|
||||
#define EPOCH_DIFF_YEARS (ASE_EPOCH_YEAR-WIN_EPOCH_YEAR)
|
||||
#define EPOCH_DIFF_YEARS (QSE_EPOCH_YEAR-WIN_EPOCH_YEAR)
|
||||
#define EPOCH_DIFF_DAYS (EPOCH_DIFF_YEARS*365+EPOCH_DIFF_YEARS/4-3)
|
||||
#define EPOCH_DIFF_SECS (EPOCH_DIFF_DAYS*24*60*60)
|
||||
#define EPOCH_DIFF_MSECS (EPOCH_DIFF_SECS*ASE_MSEC_IN_SEC)
|
||||
#define EPOCH_DIFF_MSECS (EPOCH_DIFF_SECS*QSE_MSEC_IN_SEC)
|
||||
#endif
|
||||
|
||||
static int mdays[2][ASE_MON_IN_YEAR] =
|
||||
static int mdays[2][QSE_MON_IN_YEAR] =
|
||||
{
|
||||
{ 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 },
|
||||
{ 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }
|
||||
};
|
||||
|
||||
int ase_gettime (ase_ntime_t* t)
|
||||
int qse_gettime (qse_ntime_t* t)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
SYSTEMTIME st;
|
||||
@ -45,7 +45,7 @@ int ase_gettime (ase_ntime_t* t)
|
||||
|
||||
GetSystemTime (&st);
|
||||
if (SystemTimeToFileTime (&st, &ft) == FALSE) return -1;
|
||||
*t = ((ase_ntime_t)(*((ase_int64_t*)&ft)) / (10 * 1000));
|
||||
*t = ((qse_ntime_t)(*((qse_int64_t*)&ft)) / (10 * 1000));
|
||||
*t -= EPOCH_DIFF_MSECS;
|
||||
return 0;
|
||||
#else
|
||||
@ -53,24 +53,24 @@ int ase_gettime (ase_ntime_t* t)
|
||||
int n;
|
||||
|
||||
#ifdef SYS_gettimeofday
|
||||
n = syscall (SYS_gettimeofday, &tv, ASE_NULL);
|
||||
n = syscall (SYS_gettimeofday, &tv, QSE_NULL);
|
||||
#else
|
||||
n = gettimeofday (&tv, ASE_NULL);
|
||||
n = gettimeofday (&tv, QSE_NULL);
|
||||
#endif
|
||||
if (n == -1) return -1;
|
||||
|
||||
*t = tv.tv_sec * ASE_MSEC_IN_SEC + tv.tv_usec / ASE_USEC_IN_MSEC;
|
||||
*t = tv.tv_sec * QSE_MSEC_IN_SEC + tv.tv_usec / QSE_USEC_IN_MSEC;
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
int ase_settime (ase_ntime_t t)
|
||||
int qse_settime (qse_ntime_t t)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
FILETIME ft;
|
||||
SYSTEMTIME st;
|
||||
|
||||
*((ase_int64_t*)&ft) = ((t + EPOCH_DIFF_MSECS) * (10 * 1000));
|
||||
*((qse_int64_t*)&ft) = ((t + EPOCH_DIFF_MSECS) * (10 * 1000));
|
||||
if (FileTimeToSystemTime (&ft, &st) == FALSE) return -1;
|
||||
if (SetSystemTime(&st) == FALSE) return -1;
|
||||
return 0;
|
||||
@ -78,8 +78,8 @@ int ase_settime (ase_ntime_t t)
|
||||
struct timeval tv;
|
||||
int n;
|
||||
|
||||
tv.tv_sec = t / ASE_MSEC_IN_SEC;
|
||||
tv.tv_usec = (t % ASE_MSEC_IN_SEC) * ASE_USEC_IN_MSEC;
|
||||
tv.tv_sec = t / QSE_MSEC_IN_SEC;
|
||||
tv.tv_usec = (t % QSE_MSEC_IN_SEC) * QSE_USEC_IN_MSEC;
|
||||
|
||||
/*
|
||||
#if defined CLOCK_REALTIME && HAVE_CLOCK_SETTIME
|
||||
@ -97,38 +97,38 @@ int ase_settime (ase_ntime_t t)
|
||||
*/
|
||||
|
||||
#ifdef SYS_settimeofday
|
||||
n = syscall (SYS_settimeofday, &tv, ASE_NULL);
|
||||
n = syscall (SYS_settimeofday, &tv, QSE_NULL);
|
||||
#else
|
||||
n = settimeofday (&tv, ASE_NULL);
|
||||
n = settimeofday (&tv, QSE_NULL);
|
||||
#endif
|
||||
if (n == -1) return -1;
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
void ase_gmtime (ase_ntime_t nt, ase_btime_t* bt)
|
||||
void qse_gmtime (qse_ntime_t nt, qse_btime_t* bt)
|
||||
{
|
||||
/* code based on minix 2.0 src/lib/ansi/gmtime.c */
|
||||
|
||||
ase_ntime_t days; /* total days */
|
||||
ase_ntime_t secs; /* number of seconds in the fractional days */
|
||||
ase_ntime_t time; /* total seconds */
|
||||
qse_ntime_t days; /* total days */
|
||||
qse_ntime_t secs; /* number of seconds in the fractional days */
|
||||
qse_ntime_t time; /* total seconds */
|
||||
|
||||
int year = ASE_EPOCH_YEAR;
|
||||
int year = QSE_EPOCH_YEAR;
|
||||
|
||||
time = nt / ASE_MSEC_IN_SEC;
|
||||
days = (unsigned long)time / ASE_SEC_IN_DAY;
|
||||
secs = (unsigned long)time % ASE_SEC_IN_DAY;
|
||||
time = nt / QSE_MSEC_IN_SEC;
|
||||
days = (unsigned long)time / QSE_SEC_IN_DAY;
|
||||
secs = (unsigned long)time % QSE_SEC_IN_DAY;
|
||||
|
||||
bt->sec = secs % ASE_SEC_IN_MIN;
|
||||
bt->min = (secs % ASE_SEC_IN_HOUR) / ASE_SEC_IN_MIN;
|
||||
bt->hour = secs / ASE_SEC_IN_HOUR;
|
||||
bt->sec = secs % QSE_SEC_IN_MIN;
|
||||
bt->min = (secs % QSE_SEC_IN_HOUR) / QSE_SEC_IN_MIN;
|
||||
bt->hour = secs / QSE_SEC_IN_HOUR;
|
||||
|
||||
bt->wday = (days + 4) % ASE_DAY_IN_WEEK;
|
||||
bt->wday = (days + 4) % QSE_DAY_IN_WEEK;
|
||||
|
||||
while (days >= ASE_DAY_IN_YEAR(year))
|
||||
while (days >= QSE_DAY_IN_YEAR(year))
|
||||
{
|
||||
days -= ASE_DAY_IN_YEAR(year);
|
||||
days -= QSE_DAY_IN_YEAR(year);
|
||||
year++;
|
||||
}
|
||||
|
||||
@ -136,9 +136,9 @@ void ase_gmtime (ase_ntime_t nt, ase_btime_t* bt)
|
||||
bt->yday = days;
|
||||
bt->mon = 0;
|
||||
|
||||
while (days >= mdays[ASE_IS_LEAPYEAR(year)][bt->mon])
|
||||
while (days >= mdays[QSE_IS_LEAPYEAR(year)][bt->mon])
|
||||
{
|
||||
days -= mdays[ASE_IS_LEAPYEAR(year)][bt->mon];
|
||||
days -= mdays[QSE_IS_LEAPYEAR(year)][bt->mon];
|
||||
bt->mon++;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user