6 #if defined(HAVE_CONFIG_H) 13 #include <boost/date_time/posix_time/posix_time.hpp> 14 #include <boost/thread.hpp> 18 static std::atomic<int64_t> nMockTime(0);
22 int64_t mocktime = nMockTime.load(std::memory_order_relaxed);
23 if (mocktime)
return mocktime;
25 time_t now = time(
nullptr);
32 nMockTime.store(nMockTimeIn, std::memory_order_relaxed);
37 return nMockTime.load(std::memory_order_relaxed);
42 int64_t now = (boost::posix_time::microsec_clock::universal_time() -
43 boost::posix_time::ptime(boost::gregorian::date(1970,1,1))).total_milliseconds();
50 int64_t now = (boost::posix_time::microsec_clock::universal_time() -
51 boost::posix_time::ptime(boost::gregorian::date(1970,1,1))).total_microseconds();
69 #if defined(HAVE_WORKING_BOOST_SLEEP_FOR) 70 boost::this_thread::sleep_for(boost::chrono::milliseconds(n));
71 #elif defined(HAVE_WORKING_BOOST_SLEEP) 72 boost::this_thread::sleep(boost::posix_time::milliseconds(n));
75 #error missing boost sleep implementation 81 time_t time_val = nTime;
83 gmtime_s(&ts, &time_val);
85 gmtime_r(&time_val, &ts);
87 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);
92 time_t time_val = nTime;
94 gmtime_s(&ts, &time_val);
96 gmtime_r(&time_val, &ts);
98 return strprintf(
"%04i-%02i-%02i", ts.tm_year + 1900, ts.tm_mon + 1, ts.tm_mday);
103 time_t time_val = nTime;
105 gmtime_s(&ts, &time_val);
107 gmtime_r(&time_val, &ts);
109 return strprintf(
"%02i:%02i:%02iZ", ts.tm_hour, ts.tm_min, ts.tm_sec);
void MilliSleep(int64_t n)
void SetMockTime(int64_t nMockTimeIn)
std::string FormatISO8601Date(int64_t nTime)
int64_t GetSystemTimeInSeconds()
std::string FormatISO8601Time(int64_t nTime)
std::string FormatISO8601DateTime(int64_t nTime)
ISO 8601 formatting is preferred.
int64_t GetTime()
GetTimeMicros() and GetTimeMillis() both return the system time, but in different units...