RTEXP time_t time( time_t *timer ) { SYSTEMTIME systime; GetSystemTime( &systime ); if(timer != NULL){ *timer = mktime( tm_struct_from_systime( &systime )); } return mktime( tm_struct_from_systime( &systime )); }
struct tm *localtime( const time_t *timer ) /* same, but local */ { SYSTEMTIME systime; GetLocalTime( &systime ); return tm_struct_from_systime( &systime ); }
struct tm *gmtime( const time_t *timer ) /* returns a pointer to a structure of type tm. The fields of the returned structure hold the evaluated value of the timer argument in UTC rather than in local time. Each of the structure fields is of type int, as follows: */ { SYSTEMTIME systime; GetSystemTime( &systime ); return tm_struct_from_systime( &systime ); }
/* ** Convert a time_t (UTC) to a tm structure in UTC time. ** Lua only calls this once (from os_date). */ RTEXP struct tm *gmtime( const time_t *timer ) { static struct tm stm; SYSTEMTIME syst; int secs; int tdays; secs = *timer; /* Calculate day of week. 1970-01-01 was a Thursday. (day 4 in SYSTEMTIME format)*/ tdays = secs / SECONDS_IN_DAY; syst.wDayOfWeek = 4 + (tdays % 7); if(syst.wDayOfWeek > 6) syst.wDayOfWeek -= 7; syst.wYear = 1970; while(secs >= SECONDS_IN_YEAR) { if(IsLeap(syst.wYear) && secs >= SECONDS_IN_LEAP_YEAR) { secs -= SECONDS_IN_LEAP_YEAR; syst.wYear++; } else { secs -= SECONDS_IN_YEAR; syst.wYear++; } } syst.wMonth = 1; while(secs) { if(secs >= DaysInMonth(syst.wMonth, syst.wYear) * SECONDS_IN_DAY) secs -= (DaysInMonth(syst.wMonth++, syst.wYear) * SECONDS_IN_DAY); else break; } syst.wDay = 1; while(secs) { if(secs >= SECONDS_IN_DAY) { secs -= SECONDS_IN_DAY; syst.wDay++; } else break; } syst.wHour = 0; while(secs) { if(secs >= 3600) { secs -= 3600; syst.wHour++; } else break; } syst.wMinute = 0; while(secs) { if(secs >= 60) { secs -= 60; syst.wMinute++; } else break; } syst.wSecond = secs; syst.wMilliseconds = 0; return tm_struct_from_systime( &syst ); }
time_t time( time_t *timer ) { SYSTEMTIME systime; GetSystemTime( &systime ); return mktime( tm_struct_from_systime( &systime )); }