22 #ifndef NDN_UTIL_TIME_HPP    23 #define NDN_UTIL_TIME_HPP    27 #include <boost/asio/wait_traits.hpp>    28 #include <boost/chrono.hpp>    33 using boost::chrono::duration;
    34 using boost::chrono::duration_cast;
    36 using days = duration<int_fast32_t, boost::ratio<86400>>;
    37 using boost::chrono::hours;
    38 using boost::chrono::minutes;
    39 using boost::chrono::seconds;
    40 using boost::chrono::milliseconds;
    41 using boost::chrono::microseconds;
    42 using boost::chrono::nanoseconds;
    48 template<typename Rep, typename Period, typename = std::enable_if_t<std::numeric_limits<Rep>::is_signed>>
    49 constexpr duration<Rep, Period>
    50 abs(duration<Rep, Period> d)
    52   return d >= d.zero() ? d : -d;
    57 inline namespace literals {
    58 inline namespace time_literals {
    61 operator "" _day(
unsigned long long days)
    66 constexpr time::duration<long double, time::days::period>
    67 operator "" _day(
long double days)
    69   return time::duration<long double, time::days::period>{days};
    73 operator "" _days(
unsigned long long days)
    78 constexpr time::duration<long double, time::days::period>
    79 operator "" _days(
long double days)
    81   return time::duration<long double, time::days::period>{days};
    85 operator "" _h(
unsigned long long hrs)
    87   return time::hours{hrs};
    90 constexpr time::duration<long double, time::hours::period>
    91 operator "" _h(
long double hrs)
    93   return time::duration<long double, time::hours::period>{hrs};
    96 constexpr time::minutes
    97 operator "" _min(
unsigned long long mins)
    99   return time::minutes{mins};
   102 constexpr time::duration<long double, time::minutes::period>
   103 operator "" _min(
long double mins)
   105   return time::duration<long double, time::minutes::period>{mins};
   108 constexpr time::seconds
   109 operator "" _s(
unsigned long long secs)
   111   return time::seconds{secs};
   114 constexpr time::duration<long double, time::seconds::period>
   115 operator "" _s(
long double secs)
   117   return time::duration<long double, time::seconds::period>{secs};
   120 constexpr time::milliseconds
   121 operator "" _ms(
unsigned long long msecs)
   123   return time::milliseconds{msecs};
   126 constexpr time::duration<long double, time::milliseconds::period>
   127 operator "" _ms(
long double msecs)
   129   return time::duration<long double, time::milliseconds::period>{msecs};
   132 constexpr time::microseconds
   133 operator "" _us(
unsigned long long usecs)
   135   return time::microseconds{usecs};
   138 constexpr time::duration<long double, time::microseconds::period>
   139 operator "" _us(
long double usecs)
   141   return time::duration<long double, time::microseconds::period>{usecs};
   144 constexpr time::nanoseconds
   145 operator "" _ns(
unsigned long long nsecs)
   147   return time::nanoseconds{nsecs};
   150 constexpr time::duration<long double, time::nanoseconds::period>
   151 operator "" _ns(
long double nsecs)
   153   return time::duration<long double, time::nanoseconds::period>{nsecs};
   161 using namespace literals::time_literals;
   189   using duration   = boost::chrono::system_clock::duration;
   190   using rep        = duration::rep;
   193   static constexpr 
bool is_steady = boost::chrono::system_clock::is_steady;
   205   from_time_t(
std::time_t t) noexcept;
   219   using duration   = boost::chrono::steady_clock::duration;
   220   using rep        = duration::rep;
   223   static constexpr 
bool is_steady = 
true;
   243   friend struct 
boost::asio::wait_traits<steady_clock>; 
   310          const 
std::
string& format = "%Y-%m-%d %H:%M:%S",
   311          const 
std::locale& locale = 
std::locale("C"));
   328            const 
std::
string& format = "%Y-%m-%d %H:%M:%S",
   329            const 
std::locale& locale = 
std::locale("C"));
   337 template<
class CharT>
   338 struct clock_string<
ndn::time::system_clock, CharT>
   340   static std::basic_string<CharT>
   344 template<
class CharT>
   345 struct clock_string<
ndn::time::steady_clock, CharT>
   347   static std::basic_string<CharT>
   351 extern template struct clock_string<ndn::time::system_clock, char>;
   352 extern template struct clock_string<ndn::time::steady_clock, char>;
   357 #endif // NDN_UTIL_TIME_HPP 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
boost::chrono::steady_clock::duration duration
boost::chrono::time_point< steady_clock > time_point
constexpr duration< Rep, Period > abs(duration< Rep, Period > d)
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. 
Common includes and macros used throughout the library. 
std::string toIsoString(const system_clock::TimePoint &timePoint)
Convert to the ISO string representation of the time (YYYYMMDDTHHMMSS,fffffffff) 
duration< int_fast32_t, boost::ratio< 86400 > > days
milliseconds toUnixTimestamp(const system_clock::TimePoint &point)
Convert system_clock::TimePoint to UNIX timestamp. 
const system_clock::TimePoint & getUnixEpoch()
Get system_clock::TimePoint representing UNIX time epoch (00:00:00 on Jan 1, 1970) ...