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>;