6 #if defined(HAVE_CONFIG_H)
38 const time_t time_t_epoch{};
39 auto clock = std::chrono::system_clock::from_time_t(time_t_epoch);
40 if (std::chrono::duration_cast<std::chrono::seconds>(clock.time_since_epoch()).count() != 0) {
44 time_t time_val = std::chrono::system_clock::to_time_t(clock);
45 if (time_val != time_t_epoch) {
52 if (gmtime_r(&time_val, &epoch) ==
nullptr) {
54 if (gmtime_s(&epoch, &time_val) != 0) {
59 if ((epoch.tm_sec != 0) ||
60 (epoch.tm_min != 0) ||
61 (epoch.tm_hour != 0) ||
62 (epoch.tm_mday != 1) ||
63 (epoch.tm_mon != 0) ||
64 (epoch.tm_year != 70)) {
72 const std::chrono::seconds mocktime{
nMockTime.load(std::memory_order_relaxed)};
76 std::chrono::system_clock::now().time_since_epoch()};
84 nMockTime.store(nMockTimeIn, std::memory_order_relaxed);
89 nMockTime.store(mock_time_in.count(), std::memory_order_relaxed);
94 return std::chrono::seconds(
nMockTime.load(std::memory_order_relaxed));
97 int64_t
GetTime() {
return GetTime<std::chrono::seconds>().count(); }
101 time_t time_val = nTime;
103 if (gmtime_r(&time_val, &ts) ==
nullptr) {
105 if (gmtime_s(&ts, &time_val) != 0) {
109 return strprintf(
"%04i-%02i-%02iT%02i:%02i:%02iZ", ts.tm_year + 1900, ts.tm_mon + 1, ts.tm_mday, ts.tm_hour, ts.tm_min, ts.tm_sec);
114 time_t time_val = nTime;
116 if (gmtime_r(&time_val, &ts) ==
nullptr) {
118 if (gmtime_s(&ts, &time_val) != 0) {
122 return strprintf(
"%04i-%02i-%02i", ts.tm_year + 1900, ts.tm_mon + 1, ts.tm_mday);
127 struct timeval timeout;
128 timeout.tv_sec = nTimeout / 1000;
129 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.
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)