31 #include "precompiled.h"
42 static const long _1e3 = 1000;
43 static const long _1e6 = 1000000;
44 static const long _1e7 = 10000000;
60 return u64_from_u32(ft->dwHighDateTime, ft->dwLowDateTime);
75 return (time_t)(s & 0xFFFFFFFF);
89 GetSystemTimeAsFileTime(&ft);
105 ts.
tv_sec = (time_t)((ns /
_1e9) & 0xFFFFFFFF);
136 const i64 ns =
i64(resolution * 1e9);
155 ENSURE(sec < std::numeric_limits<size_t>::max()/1000);
157 const DWORD ms = sec * 1000;
168 const DWORD ms = us/1000;
280 for (i = 0; strs[i] != NULL; ++i) {
281 size_t len = strlen (strs[i]);
283 if (strncasecmp (*buf, strs[i], len) == 0) {
303 return (year % 4) == 0 && ((year % 100) != 0 || (year % 400) == 0);
315 for (; year > 1970; --year)
329 timeptr->tm_yday = wnum * 7 + timeptr->tm_wday - fday;
330 if (timeptr->tm_yday < 0) {
331 timeptr->tm_wday = fday;
332 timeptr->tm_yday = 0;
345 timeptr->tm_yday = wnum * 7 + (timeptr->tm_wday + 6) % 7 - fday;
346 if (timeptr->tm_yday < 0) {
347 timeptr->tm_wday = (fday + 1) % 7;
348 timeptr->tm_yday = 0;
365 timeptr->tm_yday = offset + (wnum - 1) * 7 + timeptr->tm_wday - fday;
366 if (timeptr->tm_yday < 0) {
367 timeptr->tm_wday = fday;
368 timeptr->tm_yday = 0;
377 strptime (
const char *buf,
const char *format,
struct tm *timeptr)
381 for (; (c = *format) !=
'\0'; ++format) {
386 while (isspace (*buf))
388 }
else if (c ==
'%' && format[1] !=
'\0') {
390 if (c ==
'E' || c ==
'O')
397 timeptr->tm_wday = ret;
403 timeptr->tm_wday = ret;
409 timeptr->tm_mon = ret;
416 timeptr->tm_mon = ret;
419 ret = strtol (buf, &s, 10);
428 s =
strptime (buf,
"%m/%d/%y", timeptr);
435 ret = strtol (buf, &s, 10);
438 timeptr->tm_mday = ret;
443 ret = strtol (buf, &s, 10);
446 timeptr->tm_hour = ret;
451 ret = strtol (buf, &s, 10);
455 timeptr->tm_hour = 0;
457 timeptr->tm_hour = ret;
461 ret = strtol (buf, &s, 10);
464 timeptr->tm_yday = ret - 1;
468 ret = strtol (buf, &s, 10);
471 timeptr->tm_mon = ret - 1;
475 ret = strtol (buf, &s, 10);
478 timeptr->tm_min = ret;
491 if (timeptr->tm_hour == 0) {
493 timeptr->tm_hour = 12;
495 timeptr->tm_hour += 12;
498 s =
strptime (buf,
"%I:%M:%S %p", timeptr);
504 s =
strptime (buf,
"%H:%M", timeptr);
510 ret = strtol (buf, &s, 10);
513 timeptr->tm_sec = ret;
524 s =
strptime (buf,
"%H:%M:%S", timeptr);
530 ret = strtol (buf, &s, 10);
533 timeptr->tm_wday = ret - 1;
537 ret = strtol (buf, &s, 10);
540 timeptr->tm_wday = ret;
544 ret = strtol (buf, &s, 10);
551 ret = strtol (buf, &s, 10);
558 ret = strtol (buf, &s, 10);
565 s =
strptime (buf,
"%Y:%m:%d", timeptr);
571 ret = strtol (buf, &s, 10);
575 timeptr->tm_year = 100 + ret;
577 timeptr->tm_year = ret;
581 ret = strtol (buf, &s, 10);
599 if (*buf ==
'%' || *++buf == c)
static void set_week_number_mon4(struct tm *timeptr, int wnum)
unsigned sleep(unsigned sec)
static void LatchInitialSystemTime()
static size_t MsFromTimespec(const timespec &ts)
static int match_string(const char **buf, const char **strs)
int clock_gettime(clockid_t clock, struct timespec *ts)
static const char * abb_month[]
static const u64 posix_epoch_hns
static i64 CurrentSystemTime_ns()
static void set_week_number_sun(struct tm *timeptr, int wnum)
char * strptime(const char *buf, const char *format, struct tm *timeptr)
int usleep(useconds_t us)
#define ENSURE(expr)
ensure the expression <expr> evaluates to non-zero.
static int first_day(int year)
static timespec TimespecFromNs(i64 ns)
static const char * abb_weekdays[]
static const char * full_weekdays[]
i64 Status
Error handling system.
static void set_week_number_mon(struct tm *timeptr, int wnum)
static const char * ampm[]
#define WINIT_REGISTER_MAIN_INIT(func)
static int is_leap_year(int year)
static Status wtime_Init()
int clock_getres(clockid_t clock, struct timespec *ts)
u64 u64_from_u32(u32 hi, u32 lo)
return lower 16-bits
time_t wtime_utc_filetime_to_time_t(FILETIME *ft)
static const char * full_month[]
int nanosleep(const struct timespec *rqtp, struct timespec *)
static volatile TimerState *volatile ts
static u64 u64_from_FILETIME(const FILETIME *ft)