-
Notifications
You must be signed in to change notification settings - Fork 29
/
clock.c
48 lines (43 loc) · 1.29 KB
/
clock.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/* This file is part of MCF Gthread.
* Copyright (C) 2022-2024 LH_Mouse. All wrongs reserved.
*
* MCF Gthread is free software. Licensing information is included in
* LICENSE.TXT as a whole. The GCC Runtime Library Exception applies
* to this file. */
#define _POSIX_C_SOURCE 200809
#include "../mcfgthread/clock.h"
#include <assert.h>
#include <stdio.h>
#include <time.h>
#include <windows.h>
int
main(void)
{
#if defined _WIN32
_tzset();
#else
tzset();
#endif
SYSTEMTIME st;
GetLocalTime(&st);
struct tm tm;
tm.tm_year = st.wYear - 1900;
tm.tm_mon = st.wMonth - 1;
tm.tm_mday = st.wDay;
tm.tm_hour = st.wHour;
tm.tm_min = st.wMinute;
tm.tm_sec = st.wSecond;
tm.tm_isdst = -1;
long long vcrt_now = mktime(&tm) * 1000LL + st.wMilliseconds;
fprintf(stderr, "vcrt_now = %lld\n", vcrt_now);
long long ms_now = _MCF_utc_now();
long long ms_delta = ms_now - vcrt_now;
fprintf(stderr, "_MCF_utc_now() = %lld (delta %+lld)\n", ms_now, ms_delta);
assert(ms_delta >= -100);
assert(ms_delta <= +100);
double hi_now = _MCF_hires_utc_now();
double hi_delta = hi_now - (double) vcrt_now;
fprintf(stderr, "_MCF_hires_utc_now() = %.0f (delta %+.3f)\n", hi_now, hi_delta);
assert(hi_delta >= -100);
assert(hi_delta <= +100);
}