25 #include <boost/date_time/posix_time/posix_time.hpp> 37 shared_ptr<CustomSystemClock> systemClock)
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);
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);
157 namespace bpt = boost::posix_time;
158 static bpt::ptime epoch(boost::gregorian::date(1970, 1, 1));
162 auto sinceEpoch = ptime - epoch;
164 return point +
microseconds(sinceEpoch.total_microseconds() % 1000000);
181 const std::string& format,
182 const std::locale& locale)
184 namespace bpt = boost::posix_time;
186 std::ostringstream os;
187 auto* facet =
new bpt::time_facet(format.data());
188 os.imbue(std::locale(locale, facet));
196 const std::string& format,
197 const std::locale& locale)
199 namespace bpt = boost::posix_time;
201 std::istringstream is(timePointStr);
202 auto* facet =
new bpt::time_input_facet(format);
203 is.imbue(std::locale(locale, facet));
216 template<
class CharT>
217 std::basic_string<CharT>
218 clock_string<ndn::time::system_clock, CharT>::since()
222 return clock_string<system_clock, CharT>::since();
229 template<
class CharT>
230 std::basic_string<CharT>
231 clock_string<ndn::time::steady_clock, CharT>::since()
235 return clock_string<ndn::time::base_steady_clock, CharT>::since();
242 template struct clock_string<ndn::time::system_clock, char>;
243 template struct clock_string<ndn::time::steady_clock, char>;
boost::chrono::seconds seconds
boost::chrono::system_clock::duration duration
Copyright (c) 2011-2015 Regents of the University of California.
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
boost::chrono::microseconds microseconds
boost::chrono::duration< Rep, Period > duration
static time_point now() noexcept
milliseconds toUnixTimestamp(const system_clock::time_point &point)
Convert system_clock::time_point to UNIX timestamp.
boost::chrono::steady_clock base_steady_clock
system_clock::time_point fromUnixTimestamp(milliseconds duration)
Convert UNIX timestamp to system_clock::time_point.
std::string toIsoExtendedString(const system_clock::time_point &timePoint)
Convert to the ISO 8601 string representation, extended format (YYYY-MM-DDTHH:MM:SS,fffffffff).
const system_clock::time_point & getUnixEpoch()
Return a system_clock::time_point representing the UNIX time epoch, i.e., 00:00:00 UTC on 1 January 1...
static boost::posix_time::ptime convertToPosixTime(const system_clock::time_point &timePoint)
system_clock::time_point 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::time_point &timePoint, const std::string &format, const std::locale &locale)
Convert time point to string with specified format.
void setCustomClocks(shared_ptr< CustomSteadyClock > steadyClock=nullptr, shared_ptr< CustomSystemClock > systemClock=nullptr)
Set custom system and steady clocks.
static shared_ptr< CustomSteadyClock > g_steadyClock
system_clock::time_point fromIsoString(const std::string &isoString)
Convert from the ISO 8601 basic string format (YYYYMMDDTHHMMSS,fffffffff) to the internal time format...
std::string toIsoString(const system_clock::time_point &timePoint)
Convert to the ISO 8601 string representation, basic format (YYYYMMDDTHHMMSS,fffffffff).
system_clock::time_point fromIsoExtendedString(const std::string &isoString)
Convert from the ISO 8601 extended string format (YYYY-MM-DDTHH:MM:SS,fffffffff) to the internal time...
static system_clock::time_point convertToTimePoint(const boost::posix_time::ptime &ptime)
static shared_ptr< CustomSystemClock > g_systemClock
static time_point from_time_t(std::time_t t) noexcept
boost::chrono::nanoseconds nanoseconds
boost::chrono::milliseconds milliseconds