CX Framework
Cross-platform C utility framework
Loading...
Searching...
No Matches
win_time.h
1#pragma once
2
3#include <cx/cx.h>
4#include <cx/platform/win.h>
5
6_meta_inline int64 timeFromFileTime(FILETIME *ft)
7{
8 int64 ret = ((int64)ft->dwHighDateTime << 32) | ft->dwLowDateTime;
9 ret /= 10; // convert from 100-ns intervals to microseconds
10
11 // FILETIME epoch is midnight on Jan 1, 1601
12 // Which is a julian date of 2305813.50000
13 // That's 199222286400 in seconds, or in microseconds...
14
15 ret += 199222286400000000LL; // adjust epoch
16 // This still leaves over 280,000 years before overflow
17
18 return ret;
19}
20
21_meta_inline bool timeToFileTime(int64 time, FILETIME *ft)
22{
23 time -= 199222286400000000LL; // adjust epoch
24 if (time < 0)
25 return false;
26
27 time *= 10; // convert to 100-ns intervals
28 ft->dwHighDateTime = (DWORD)(time >> 32);
29 ft->dwLowDateTime = (DWORD)(time & 0xffffffff);
30 return true;
31}