#pragma once
#include <cstdint>
#include <chrono>
#if defined(_WIN32)
#include <Windows.h>
#elif defined(__unix__)
#include <time.h>
#else
#error dasdasd
#endif
struct win_time
{
using rep = int64_t;
using period = std::ratio<1, 10000000>;
using duration = std::chrono::duration<rep, period>;
using time_point = std::chrono::time_point<win_time, duration>;
static time_point now() noexcept;
static constexpr bool is_steady = true;
private:
static constexpr int64_t UNIX_START = 116444736000000000;
};
inline win_time::time_point win_time::now() noexcept
{
#if defined(_WIN32)
FILETIME ft;
GetSystemTimePreciseAsFileTime( &ft );
return time_point( duration( (uint64_t)ft.dwHighDateTime << 32 | ft.dwLowDateTime ) );
#elif defined(__unix__)
timespec ts;
clock_gettime( CLOCK_REALTIME, &ts );
return time_point( duration( UNIX_START + (uint64_t)ts.tv_sec * 10'000'000u + ((uint64_t)ts.tv_nsec + 50u) / 100u ) );
#endif
}
What does this do ?
Sysop: | Tetrazocine |
---|---|
Location: | Melbourne, VIC, Australia |
Users: | 14 |
Nodes: | 8 (0 / 8) |
Uptime: | 207:40:25 |
Calls: | 178 |
Files: | 21,502 |
Messages: | 80,307 |