6 #ifndef BITCOIN_UTIL_TIME_H
7 #define BITCOIN_UTIL_TIME_H
13 using namespace std::chrono_literals;
16 struct NodeClock :
public std::chrono::system_clock {
44 template <typename Dur1, typename Dur2>
47 return std::chrono::duration_cast<Dur1>(d).count();
49 template <
typename Duration,
typename Timepo
int>
52 return Ticks<Duration>(
t.time_since_epoch());
54 constexpr int64_t
count_seconds(std::chrono::seconds t) {
return t.count(); }
58 using HoursDouble = std::chrono::duration<double, std::chrono::hours::period>;
59 using SecondsDouble = std::chrono::duration<double, std::chrono::seconds::period>;
81 void SetMockTime(std::chrono::seconds mock_time_in);
93 return std::chrono::time_point_cast<typename T::duration>(T::clock::now());
99 return Now<std::chrono::time_point<NodeClock, T>>().time_since_epoch();
#define T(expected, seed, data)
Mockable clock in the context of tests, otherwise the system clock.
std::chrono::time_point< NodeClock > time_point
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::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.
bool ChronoSanityCheck()
Sanity check epoch match normal Unix epoch.
std::string FormatISO8601DateTime(int64_t nTime)
ISO 8601 formatting is preferred.
std::chrono::time_point< std::chrono::steady_clock, std::chrono::milliseconds > SteadyMilliseconds