#include "time.hpp" #include #include namespace llarp { namespace { using Clock_t = std::chrono::system_clock; template static Duration_t time_since_epoch(std::chrono::time_point point) { return std::chrono::duration_cast(point.time_since_epoch()); } const static auto started_at_system = Clock_t::now(); const static auto started_at_steady = std::chrono::steady_clock::now(); } // namespace uint64_t ToMS(Duration_t ms) { return ms.count(); } /// get our uptime in ms Duration_t uptime() { return std::chrono::duration_cast( std::chrono::steady_clock::now() - started_at_steady); } Duration_t time_now_ms() { auto t = uptime(); #ifdef TESTNET_SPEED t /= uint64_t{TESTNET_SPEED}; #endif return t + time_since_epoch(started_at_system); } nlohmann::json to_json(const Duration_t& t) { return ToMS(t); } } // namespace llarp