8#if defined(HAVE_CONFIG_H)
9#include <config/bitcoin-config.h>
15#include <boost/date_time/posix_time/posix_time.hpp>
24 std::this_thread::sleep_for(n);
42 if (std::chrono::duration_cast<std::chrono::seconds>(
43 clock.time_since_epoch())
64 if ((
epoch.tm_sec != 0) || (
epoch.tm_min != 0) || (
epoch.tm_hour != 0) ||
73 nMockTime.load(std::memory_order_relaxed)};
77 : std::chrono::system_clock::now().time_since_epoch()};
83 const auto now = std::chrono::duration_cast<T>(
98 return std::chrono::seconds(
nMockTime.load(std::memory_order_relaxed));
123 return strprintf(
"%04i-%02i-%02iT%02i:%02i:%02iZ",
ts.tm_year + 1900,
124 ts.tm_mon + 1,
ts.tm_mday,
ts.tm_hour,
ts.tm_min,
138 return strprintf(
"%04i-%02i-%02i",
ts.tm_year + 1900,
ts.tm_mon + 1,
143 static const boost::posix_time::ptime
epoch =
144 boost::posix_time::from_time_t(0);
145 static const std::locale
loc(
146 std::locale::classic(),
147 new boost::posix_time::time_input_facet(
"%Y-%m-%dT%H:%M:%SZ"));
148 std::istringstream
iss(str);
150 boost::posix_time::ptime
ptime(boost::date_time::not_a_date_time);
161 timeout.tv_usec = (
nTimeout % 1000) * 1000;
#define Assert(val)
Identity function.
Implement std::hash so RCUPtr can be used as a key for maps or sets.
T GetRand(T nMax=std::numeric_limits< T >::max()) noexcept
Generate a uniform random integer of type T in the range [0..nMax) nMax defaults to std::numeric_limi...
static time_point now() noexcept
Return current system time or mocked time, if set.
std::chrono::time_point< NodeClock > time_point
struct timeval MillisToTimeval(int64_t nTimeout)
Convert milliseconds to a struct timeval for e.g.
int64_t GetTimeMicros()
Returns the system time (not mockable)
int64_t GetTimeMillis()
Returns the system time (not mockable)
void UninterruptibleSleep(const std::chrono::microseconds &n)
static std::atomic< int64_t > nMockTime(0)
For testing.
std::chrono::seconds GetMockTime()
For testing.
int64_t GetTime()
DEPRECATED Use either ClockType::now() or Now<TimePointType>() if a cast is needed.
std::string FormatISO8601Date(int64_t nTime)
void SetMockTime(int64_t nMockTimeIn)
DEPRECATED Use SetMockTime with chrono type.
int64_t ParseISO8601DateTime(const std::string &str)
bool ChronoSanityCheck()
Sanity check epoch match normal Unix epoch.
std::string FormatISO8601DateTime(int64_t nTime)
ISO 8601 formatting is preferred.
constexpr int64_t count_milliseconds(std::chrono::milliseconds t)