25 #include <boost/date_time/posix_time/posix_time.hpp> 37 shared_ptr<CustomSystemClock> systemClock)
50 return time_point(boost::chrono::system_clock::now().time_since_epoch());
60 return duration_cast<seconds>(t.time_since_epoch()).count();
84 return time_point(base_steady_clock::now().time_since_epoch());
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) 133 #elif defined(BOOST_DATE_TIME_HAS_MICROSECONDS) 138 constexpr
auto unitsPerHour = duration_cast<BptResolution>(1_h).count();
140 auto sinceEpoch = duration_cast<BptResolution>(timePoint -
getUnixEpoch()).count();
141 return epoch + bpt::time_duration(sinceEpoch / unitsPerHour, 0, 0, sinceEpoch % unitsPerHour);
153 namespace bpt = boost::posix_time;
154 static bpt::ptime epoch(boost::gregorian::date(1970, 1, 1));
158 auto sinceEpoch = ptime - epoch;
160 return point + microseconds(sinceEpoch.total_microseconds() % 1000000);
171 const std::string& format,
172 const std::locale& locale)
174 namespace bpt = boost::posix_time;
176 std::ostringstream os;
177 auto* facet =
new bpt::time_facet(format.data());
178 os.imbue(std::locale(locale, facet));
186 const std::string& format,
187 const std::locale& locale)
189 namespace bpt = boost::posix_time;
191 std::istringstream is(timePointStr);
192 auto* facet =
new bpt::time_input_facet(format);
193 is.imbue(std::locale(locale, facet));
206 template<
class CharT>
207 std::basic_string<CharT>
212 return clock_string<system_clock, CharT>::since();
219 template<
class CharT>
220 std::basic_string<CharT>
225 return clock_string<ndn::time::base_steady_clock, CharT>::since();
232 template struct clock_string<ndn::time::system_clock, char>;
233 template struct clock_string<ndn::time::steady_clock, char>;
Copyright (c) 2011-2015 Regents of the University of California.
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 std::basic_string< CharT > since()
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 std::basic_string< CharT > since()
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)