26 const auto mocktime{
g_mock_time.load(std::memory_order_relaxed)};
30 std::chrono::system_clock::now().time_since_epoch()};
39 g_mock_time.store(mock_time_in, std::memory_order_relaxed);
47int64_t
GetTime() {
return GetTime<std::chrono::seconds>().count(); }
51 const std::chrono::sys_seconds secs{std::chrono::seconds{nTime}};
52 const auto days{std::chrono::floor<std::chrono::days>(secs)};
53 const std::chrono::year_month_day ymd{days};
54 const std::chrono::hh_mm_ss hms{secs - days};
55 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());
60 const std::chrono::sys_seconds secs{std::chrono::seconds{nTime}};
61 const auto days{std::chrono::floor<std::chrono::days>(secs)};
62 const std::chrono::year_month_day ymd{days};
63 return strprintf(
"%04i-%02u-%02u",
signed{ymd.year()},
unsigned{ymd.month()},
unsigned{ymd.day()});
68 constexpr auto FMT_SIZE{std::string_view{
"2000-01-01T01:01:01Z"}.size()};
69 if (str.size() != FMT_SIZE || str[4] !=
'-' || str[7] !=
'-' || str[10] !=
'T' || str[13] !=
':' || str[16] !=
':' || str[19] !=
'Z') {
72 const auto year{ToIntegral<uint16_t>(str.substr(0, 4))};
73 const auto month{ToIntegral<uint8_t>(str.substr(5, 2))};
74 const auto day{ToIntegral<uint8_t>(str.substr(8, 2))};
75 const auto hour{ToIntegral<uint8_t>(str.substr(11, 2))};
76 const auto min{ToIntegral<uint8_t>(str.substr(14, 2))};
77 const auto sec{ToIntegral<uint8_t>(str.substr(17, 2))};
78 if (!year || !month || !day || !hour || !min || !sec) {
81 const std::chrono::year_month_day ymd{std::chrono::year{*year}, std::chrono::month{*month}, std::chrono::day{*day}};
85 const auto time{std::chrono::hours{*hour} + std::chrono::minutes{*min} + std::chrono::seconds{*sec}};
86 const auto tp{std::chrono::sys_days{ymd} + time};
87 return int64_t{TicksSinceEpoch<std::chrono::seconds>(tp)};
92 struct timeval timeout;
93 timeout.tv_sec = nTimeout / 1000;
94 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
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.
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.
std::optional< int64_t > ParseISO8601DateTime(std::string_view str)
static std::atomic< std::chrono::seconds > g_mock_time
For testing.
std::string FormatISO8601DateTime(int64_t nTime)
ISO 8601 formatting is preferred.
constexpr int64_t count_milliseconds(std::chrono::milliseconds t)