25 #include <boost/date_time/posix_time/posix_time.hpp> 37 shared_ptr<CustomSystemClock> systemClock)
39 g_systemClock = std::move(systemClock);
40 g_steadyClock = std::move(steadyClock);
48 if (g_systemClock ==
nullptr) {
50 return time_point(boost::chrono::system_clock::now().time_since_epoch());
53 return g_systemClock->getNow();
60 return duration_cast<seconds>(t.time_since_epoch()).count();
82 if (g_steadyClock ==
nullptr) {
84 return time_point(base_steady_clock::now().time_since_epoch());
87 return g_steadyClock->getNow();
94 if (g_steadyClock ==
nullptr) {
99 return g_steadyClock->toWaitDuration(d);
115 return duration_cast<milliseconds>(point -
getUnixEpoch());
124 static boost::posix_time::ptime
127 namespace bpt = boost::posix_time;
128 static bpt::ptime epoch(boost::gregorian::date(1970, 1, 1));
130 using BptResolution =
131 #if defined(BOOST_DATE_TIME_HAS_NANOSECONDS) 136 constexpr
auto unitsPerHour = duration_cast<BptResolution>(1_h).count();
138 auto sinceEpoch = duration_cast<BptResolution>(timePoint -
getUnixEpoch()).count();
139 return epoch + bpt::time_duration(sinceEpoch / unitsPerHour, 0, 0, sinceEpoch % unitsPerHour);
151 namespace bpt = boost::posix_time;
152 static bpt::ptime epoch(boost::gregorian::date(1970, 1, 1));
156 auto sinceEpoch = ptime - epoch;
158 return point + microseconds(sinceEpoch.total_microseconds() % 1000000);
169 const std::string& format,
170 const std::locale& locale)
172 namespace bpt = boost::posix_time;
174 std::ostringstream os;
175 auto* facet =
new bpt::time_facet(format.data());
176 os.imbue(std::locale(locale, facet));
184 const std::string& format,
185 const std::locale& locale)
187 namespace bpt = boost::posix_time;
189 std::istringstream is(timePointStr);
190 auto* facet =
new bpt::time_input_facet(format);
191 is.imbue(std::locale(locale, facet));
204 template<
class CharT>
205 std::basic_string<CharT>
206 clock_string<ndn::time::system_clock, CharT>::since()
210 return clock_string<system_clock, CharT>::since();
217 template<
class CharT>
218 std::basic_string<CharT>
219 clock_string<ndn::time::steady_clock, CharT>::since()
223 return clock_string<ndn::time::base_steady_clock, CharT>::since();
230 template struct clock_string<ndn::time::system_clock, char>;
231 template struct clock_string<ndn::time::steady_clock, char>;
boost::chrono::system_clock::duration duration
system_clock::TimePoint fromUnixTimestamp(milliseconds duration)
Convert UNIX timestamp to system_clock::TimePoint.
system_clock::TimePoint fromIsoString(const std::string &isoString)
Convert from the ISO string (YYYYMMDDTHHMMSS,fffffffff) representation to the internal time format...
boost::chrono::time_point< system_clock > time_point
static time_point now() noexcept
static std::time_t to_time_t(const time_point &t) noexcept
boost::chrono::steady_clock::duration duration
boost::chrono::time_point< steady_clock > time_point
static time_point now() noexcept
system_clock::TimePoint fromString(const std::string &timePointStr, const std::string &format, const std::locale &locale)
Convert from string of specified format into time point.
std::string toString(const system_clock::TimePoint &timePoint, const std::string &format, const std::locale &locale)
Convert time point to string with specified format.
boost::chrono::steady_clock base_steady_clock
static system_clock::TimePoint convertToTimePoint(const boost::posix_time::ptime &ptime)
std::string toIsoString(const system_clock::TimePoint &timePoint)
Convert to the ISO string representation of the time (YYYYMMDDTHHMMSS,fffffffff)
void setCustomClocks(shared_ptr< CustomSteadyClock > steadyClock=nullptr, shared_ptr< CustomSystemClock > systemClock=nullptr)
Set custom system and steady clocks.
static shared_ptr< CustomSteadyClock > g_steadyClock
milliseconds toUnixTimestamp(const system_clock::TimePoint &point)
Convert system_clock::TimePoint to UNIX timestamp.
static boost::posix_time::ptime convertToPosixTime(const system_clock::TimePoint &timePoint)
static shared_ptr< CustomSystemClock > g_systemClock
static time_point from_time_t(std::time_t t) noexcept
const system_clock::TimePoint & getUnixEpoch()
Get system_clock::TimePoint representing UNIX time epoch (00:00:00 on Jan 1, 1970) ...