Skip to content

Commit 02fd12c

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 bbd61a2 commit 02fd12c

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,12 +108,13 @@ _dispatch_get_nanoseconds(void)
108108
return _dispatch_timespec_to_nano(ts);
109109
#elif defined(_WIN32)
110110
// FILETIME is 100-nanosecond intervals since January 1, 1601 (UTC).
111+
static const uint64_t kNTToUNIXBiasAdjustment = 11644473600 * NSEC_PER_SEC;
111112
FILETIME ft;
112113
ULARGE_INTEGER li;
113114
GetSystemTimeAsFileTime(&ft);
114115
li.LowPart = ft.dwLowDateTime;
115116
li.HighPart = ft.dwHighDateTime;
116-
return li.QuadPart * 100ull;
117+
return li.QuadPart * 100ull + kNTToUNIXBiasAdjustment;
117118
#else
118119
struct timeval tv;
119120
dispatch_assert_zero(gettimeofday(&tv, NULL));

0 commit comments

Comments
 (0)