Commit 3f01f2bd authored by Wouter van der Beek's avatar Wouter van der Beek Committed by Kishen Maloor

port/windows: Update clock to return time in UTC

Change-Id: I6a354a54a4dcbfcd0f19b17bccecd429aeaa3c34
Signed-off-by: Kishen Maloor's avatarKishen Maloor <kishen.maloor@intel.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/29408
parent 82df6abf
...@@ -20,24 +20,32 @@ ...@@ -20,24 +20,32 @@
#define WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN
#include <windows.h> #include <windows.h>
static LARGE_INTEGER frequency = { 0 };
void void
oc_clock_init(void) oc_clock_init(void)
{ {
QueryPerformanceFrequency(&frequency);
} }
oc_clock_time_t oc_clock_time_t
oc_clock_time(void) oc_clock_time(void)
{ {
LARGE_INTEGER count = { 0 }; oc_clock_time_t time = 0;
if (frequency.QuadPart && QueryPerformanceCounter(&count)) {
oc_clock_time_t t = // This magic number is the number of 100 nanosecond intervals since January
1000 * count.QuadPart / frequency.QuadPart; // milliseconds // 1, 1601 (UTC)
return t; // until 00:00:00 January 1, 1970
} static const uint64_t EPOCH = ((uint64_t)116444736000000000ULL);
// fall back if no QueryPerformanceCounter available
return GetTickCount64(); SYSTEMTIME system_time;
FILETIME file_time;
GetSystemTime(&system_time);
SystemTimeToFileTime(&system_time, &file_time);
time = ((uint64_t)file_time.dwLowDateTime);
time += ((uint64_t)file_time.dwHighDateTime) << 32;
time = (oc_clock_time_t)((time - EPOCH) / 10000L);
return time;
} }
unsigned long unsigned long
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment