@ -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);
@ -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);