mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-05-11 14:32:58 +02:00
util: Add NodeClock::epoch alias
A default constructed time_point is the epoch, by definition. Existing code uses a default constructed (or explicitly constructed with a zero duration) chrono type to mean epoch. New code can now use NodeClock::epoch as an alias.
This commit is contained in:
@@ -27,6 +27,8 @@ static std::atomic<std::chrono::seconds> g_mock_time{}; //!< For testing
|
||||
std::atomic<bool> g_used_system_time{false};
|
||||
static std::atomic<MockableSteadyClock::mock_time_point::duration> g_mock_steady_time{}; //!< For testing
|
||||
|
||||
static_assert(NodeClock::epoch.time_since_epoch().count() == 0);
|
||||
|
||||
NodeClock::time_point NodeClock::now() noexcept
|
||||
{
|
||||
const auto mocktime{g_mock_time.load(std::memory_order_relaxed)};
|
||||
|
||||
@@ -23,6 +23,7 @@ struct NodeClock : public std::chrono::system_clock {
|
||||
static time_point now() noexcept;
|
||||
static std::time_t to_time_t(const time_point&) = delete; // unused
|
||||
static time_point from_time_t(std::time_t) = delete; // unused
|
||||
static constexpr time_point epoch{};
|
||||
};
|
||||
using NodeSeconds = std::chrono::time_point<NodeClock, std::chrono::seconds>;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user