From 42bb617841294c8ea2e338258ca9d5d824c82f7e Mon Sep 17 00:00:00 2001 From: Michael Zillgith Date: Tue, 23 Feb 2021 17:14:46 +0100 Subject: [PATCH] - HAL: implemented Hal_setTimeInNs for windows --- hal/inc/hal_time.h | 8 ++++++++ hal/time/win32/time.c | 18 ++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/hal/inc/hal_time.h b/hal/inc/hal_time.h index 52782959..7d5a942c 100644 --- a/hal/inc/hal_time.h +++ b/hal/inc/hal_time.h @@ -71,6 +71,14 @@ Hal_getTimeInMs(void); PAL_API nsSinceEpoch Hal_getTimeInNs(void); +/** +* Set the system time from ns time +* +* The time value returned as 64-bit unsigned integer should represent the nanoseconds +* since the UNIX epoch (1970/01/01 00:00 UTC). +* +* \return true on success, otherwise false +*/ PAL_API bool Hal_setTimeInNs(nsSinceEpoch nsTime); diff --git a/hal/time/win32/time.c b/hal/time/win32/time.c index 17eaf65d..1e7adfe3 100644 --- a/hal/time/win32/time.c +++ b/hal/time/win32/time.c @@ -57,3 +57,21 @@ Hal_getTimeInNs() return nsTime; } + +bool +Hal_setTimeInNs(nsSinceEpoch nsTime) +{ + uint64_t t = (nsTime / 100ULL) + 116444736000000000ULL; + + FILETIME ft; + + ft.dwLowDateTime = (uint32_t)(t & 0xffffffff); + ft.dwHighDateTime = (uint32_t)(t >> 32); + + SYSTEMTIME st; + + FileTimeToSystemTime(&ft, &st); + + return SetSystemTime(&st); +} +