23 const std::chrono::seconds mocktime{
nMockTime.load(std::memory_order_relaxed)};
27 std::chrono::system_clock::now().time_since_epoch()};
35 nMockTime.store(nMockTimeIn, std::memory_order_relaxed);
40 nMockTime.store(mock_time_in.count(), std::memory_order_relaxed);
45 return std::chrono::seconds(
nMockTime.load(std::memory_order_relaxed));
48 int64_t
GetTime() {
return GetTime<std::chrono::seconds>().count(); }
52 const std::chrono::sys_seconds secs{std::chrono::seconds{nTime}};
53 const auto days{std::chrono::floor<std::chrono::days>(secs)};
54 const std::chrono::year_month_day ymd{days};
55 const std::chrono::hh_mm_ss hms{secs - days};
56 return strprintf(
"%04i-%02u-%02uT%02i:%02i:%02iZ",
signed{ymd.year()},
unsigned{ymd.month()},
unsigned{ymd.day()}, hms.hours().
count(), hms.minutes().count(), hms.seconds().count());
61 const std::chrono::sys_seconds secs{std::chrono::seconds{nTime}};
62 const auto days{std::chrono::floor<std::chrono::days>(secs)};
63 const std::chrono::year_month_day ymd{days};
64 return strprintf(
"%04i-%02u-%02u",
signed{ymd.year()},
unsigned{ymd.month()},
unsigned{ymd.day()});
69 struct timeval timeout;
70 timeout.tv_sec = nTimeout / 1000;
71 timeout.tv_usec = (nTimeout % 1000) * 1000;
#define Assert(val)
Identity function.
static time_point now() noexcept
Return current system time or mocked time, if set.
std::chrono::time_point< NodeClock > time_point
static std::atomic< int64_t > nMockTime(0)
For testing.
struct timeval MillisToTimeval(int64_t nTimeout)
Convert milliseconds to a struct timeval for e.g.
void UninterruptibleSleep(const std::chrono::microseconds &n)
std::chrono::seconds GetMockTime()
For testing.
std::string FormatISO8601Date(int64_t nTime)
void SetMockTime(int64_t nMockTimeIn)
DEPRECATED Use SetMockTime with chrono type.
std::string FormatISO8601DateTime(int64_t nTime)
ISO 8601 formatting is preferred.
constexpr int64_t count_milliseconds(std::chrono::milliseconds t)