diff --git a/src/util/time.cpp b/src/util/time.cpp --- a/src/util/time.cpp +++ b/src/util/time.cpp @@ -25,17 +25,6 @@ //! For unit testing static std::atomic nMockTime(0); -int64_t GetTime() { - int64_t mocktime = nMockTime.load(std::memory_order_relaxed); - if (mocktime) { - return mocktime; - } - - time_t now = time(nullptr); - assert(now > 0); - return now; -} - bool ChronoSanityCheck() { // std::chrono::system_clock.time_since_epoch and time_t(0) are not // guaranteed to use the Unix epoch timestamp, prior to C++20, but in @@ -81,9 +70,13 @@ const std::chrono::seconds mocktime{ nMockTime.load(std::memory_order_relaxed)}; - return std::chrono::duration_cast( - mocktime.count() ? mocktime - : std::chrono::microseconds{GetTimeMicros()}); + const auto ret{ + mocktime.count() + ? mocktime + : std::chrono::duration_cast( + std::chrono::system_clock::now().time_since_epoch())}; + assert(ret > 0s); + return ret; } template std::chrono::seconds GetTime(); template std::chrono::milliseconds GetTime(); @@ -117,6 +110,10 @@ return int64_t{GetSystemTime().count()}; } +int64_t GetTime() { + return GetTime().count(); +} + std::string FormatISO8601DateTime(int64_t nTime) { struct tm ts; time_t time_val = nTime;