6#ifndef BITCOIN_UTIL_TIME_H
7#define BITCOIN_UTIL_TIME_H
15using namespace std::chrono_literals;
18struct NodeClock :
public std::chrono::system_clock {
46template <typename Dur1, typename Dur2>
49 return std::chrono::duration_cast<Dur1>(d).count();
51template <
typename Duration,
typename Timepo
int>
54 return Ticks<Duration>(
t.time_since_epoch());
60using HoursDouble = std::chrono::duration<double, std::chrono::hours::period>;
61using SecondsDouble = std::chrono::duration<double, std::chrono::seconds::period>;
95 return std::chrono::time_point_cast<typename T::duration>(T::clock::now());
101 return Now<std::chrono::time_point<NodeClock, T>>().time_since_epoch();
Mockable clock in the context of tests, otherwise the system clock.
static time_point now() noexcept
Return current system time or mocked time, if set.
std::chrono::time_point< NodeClock > time_point
static std::time_t to_time_t(const time_point &)=delete
static time_point from_time_t(std::time_t)=delete
constexpr int64_t count_milliseconds(std::chrono::milliseconds t)
struct timeval MillisToTimeval(int64_t nTimeout)
Convert milliseconds to a struct timeval for e.g.
std::chrono::duration< double, std::chrono::seconds::period > SecondsDouble
std::chrono::duration< double, std::chrono::hours::period > HoursDouble
std::chrono::steady_clock SteadyClock
std::chrono::duration< double, std::chrono::milliseconds::period > MillisecondsDouble
void UninterruptibleSleep(const std::chrono::microseconds &n)
std::chrono::seconds GetMockTime()
For testing.
int64_t GetTime()
DEPRECATED Use either ClockType::now() or Now<TimePointType>() if a cast is needed.
constexpr auto TicksSinceEpoch(Timepoint t)
std::string FormatISO8601Date(int64_t nTime)
void SetMockTime(int64_t nMockTimeIn)
DEPRECATED Use SetMockTime with chrono type.
T Now()
Return the current time point cast to the given precision.
std::chrono::system_clock SystemClock
constexpr int64_t count_microseconds(std::chrono::microseconds t)
constexpr int64_t count_seconds(std::chrono::seconds t)
std::chrono::time_point< std::chrono::steady_clock, std::chrono::microseconds > SteadyMicroseconds
std::chrono::time_point< NodeClock, std::chrono::seconds > NodeSeconds
std::optional< int64_t > ParseISO8601DateTime(std::string_view str)
std::chrono::time_point< std::chrono::steady_clock, std::chrono::seconds > SteadySeconds
constexpr auto Ticks(Dur2 d)
Helper to count the seconds of a duration/time_point.
std::string FormatISO8601DateTime(int64_t nTime)
ISO 8601 formatting is preferred.
std::chrono::time_point< std::chrono::steady_clock, std::chrono::milliseconds > SteadyMilliseconds