AuroraRuntime/Source/Time/Time.hpp
2021-06-27 22:25:29 +01:00

36 lines
916 B
C++

/***
Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: Time.hpp
Date: 2021-6-17
Author: Reece
***/
#pragma once
namespace Aurora::Time
{
#if defined(AURORA_PLATFORM_WIN32)
static inline AuSInt ConvertTimestamp(const FILETIME &ft)
{
ULARGE_INTEGER ull;
ull.LowPart = ft.dwLowDateTime;
ull.HighPart = ft.dwHighDateTime;
return ull.QuadPart / 10000ULL - 12'643'550'100'000ULL;
}
#elif defined(AURORA_PLATFORM_LINUX) || defined(AURORA_PLATFORM_ANDROID) || defined(AURORA_HAS_PTHREADS)
static inline AuUInt32 ConvertUnixTimespecToMs(const struct timespec &spec)
{
return ConvertUnixToAuroraMS(spec.tv_sec * 1000ULL + spec.tv_nsec / 1000000ULL);
}
static void ms2ts(struct timespec *ts, unsigned long ms)
{
ts->tv_sec = ms / 1000;
ts->tv_nsec = (ms % 1000) * 1000000;
}
#endif
}