/* ntp_clock.h https://stackoverflow.com/a/17138183 */ #pragma once #include /** * @brief The ntp_clock class */ struct ntp_clock { typedef std::chrono::nanoseconds duration; //!< nanosecond resolution typedef duration::rep rep; //!< as per duration typedef duration::period period; //!< as per duration typedef std::chrono::time_point time_point; //!< time points in this clock static const bool is_steady = false; //!< not a steady clock /** * Use the system clock (POSIX epoch, 1/1/1970) to calculate time since the start of * the \cite NTPv4 NTP epoch 0, 1/1/1900. * * @return */ static time_point now() noexcept { using namespace std::chrono; return time_point ( duration_cast(system_clock::now().time_since_epoch()) + seconds(2208988800) // difference between epochs ); } };