Skip to content

Commit a3b66d7

Browse files
committed
shims: correct _dispatch_get_nanoseconds on Windows
The NT time representation uses 1/1/1601 as epoch as opposed to Unix which uses 1/1/1970. Account for the offset in the calculation. This corrects the calculation of now.
1 parent 9b49bf6 commit a3b66d7

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/shims/time.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,13 +108,14 @@ _dispatch_get_nanoseconds(void)
108108
dispatch_assume_zero(clock_gettime(CLOCK_REALTIME, &ts));
109109
return _dispatch_timespec_to_nano(ts);
110110
#elif defined(_WIN32)
111+
static const uint64_t kNTToUNIXBiasAdjustment = 11644473600 * NSEC_PER_SEC;
111112
// FILETIME is 100-nanosecond intervals since January 1, 1601 (UTC).
112113
FILETIME ft;
113114
ULARGE_INTEGER li;
114115
GetSystemTimeAsFileTime(&ft);
115116
li.LowPart = ft.dwLowDateTime;
116117
li.HighPart = ft.dwHighDateTime;
117-
return li.QuadPart * 100ull;
118+
return li.QuadPart * 100ull - kNTToUNIXBiasAdjustment;
118119
#else
119120
struct timeval tv;
120121
dispatch_assert_zero(gettimeofday(&tv, NULL));

0 commit comments

Comments
 (0)