diff options
author | MarcoFalke <falke.marco@gmail.com> | 2022-04-09 14:41:09 +0200 |
---|---|---|
committer | MarcoFalke <falke.marco@gmail.com> | 2022-04-16 13:15:14 +0200 |
commit | 0000a63689036dc4368d04c0648a55fdf507932f (patch) | |
tree | 278d32311e51b6488b8816b7e3765341b613a7bd /src/util/time.cpp | |
parent | 6be319beb8d6281cd82be8132dc4b765978122ba (diff) | |
download | bitcoin-0000a63689036dc4368d04c0648a55fdf507932f.tar.xz |
Simplify GetTime
Diffstat (limited to 'src/util/time.cpp')
-rw-r--r-- | src/util/time.cpp | 19 |
1 files changed, 6 insertions, 13 deletions
diff --git a/src/util/time.cpp b/src/util/time.cpp index f7712f0dc8..e428430bac 100644 --- a/src/util/time.cpp +++ b/src/util/time.cpp @@ -23,16 +23,6 @@ void UninterruptibleSleep(const std::chrono::microseconds& n) { std::this_thread static std::atomic<int64_t> nMockTime(0); //!< For testing -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 @@ -80,11 +70,12 @@ template <typename T> T GetTime() { const std::chrono::seconds mocktime{nMockTime.load(std::memory_order_relaxed)}; - - return std::chrono::duration_cast<T>( + const auto ret{ mocktime.count() ? mocktime : - std::chrono::microseconds{GetTimeMicros()}); + std::chrono::duration_cast<T>(std::chrono::system_clock::now().time_since_epoch())}; + assert(ret > 0s); + return ret; } template std::chrono::seconds GetTime(); template std::chrono::milliseconds GetTime(); @@ -129,6 +120,8 @@ int64_t GetTimeSeconds() return int64_t{GetSystemTime<std::chrono::seconds>().count()}; } +int64_t GetTime() { return GetTime<std::chrono::seconds>().count(); } + std::string FormatISO8601DateTime(int64_t nTime) { struct tm ts; time_t time_val = nTime; |