22 #ifndef NDN_UTIL_TIME_HPP 23 #define NDN_UTIL_TIME_HPP 25 #include "../common.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,
49 typename =
typename std::enable_if<std::numeric_limits<Rep>::is_signed>::type>
50 constexpr duration<Rep, Period>
51 abs(duration<Rep, Period> d)
53 return d >= d.zero() ? d : -d;
58 inline namespace literals {
59 inline namespace time_literals {
62 operator "" _day(
unsigned long long days)
67 constexpr time::duration<long double, time::days::period>
68 operator "" _day(
long double days)
70 return time::duration<long double, time::days::period>{
days};
74 operator "" _days(
unsigned long long days)
79 constexpr time::duration<long double, time::days::period>
80 operator "" _days(
long double days)
82 return time::duration<long double, time::days::period>{
days};
86 operator "" _h(
unsigned long long hrs)
88 return time::hours{hrs};
91 constexpr time::duration<long double, time::hours::period>
92 operator "" _h(
long double hrs)
94 return time::duration<long double, time::hours::period>{hrs};
97 constexpr time::minutes
98 operator "" _min(
unsigned long long mins)
100 return time::minutes{mins};
103 constexpr time::duration<long double, time::minutes::period>
104 operator "" _min(
long double mins)
106 return time::duration<long double, time::minutes::period>{mins};
109 constexpr time::seconds
110 operator "" _s(
unsigned long long secs)
112 return time::seconds{secs};
115 constexpr time::duration<long double, time::seconds::period>
116 operator "" _s(
long double secs)
118 return time::duration<long double, time::seconds::period>{secs};
121 constexpr time::milliseconds
122 operator "" _ms(
unsigned long long msecs)
124 return time::milliseconds{msecs};
127 constexpr time::duration<long double, time::milliseconds::period>
128 operator "" _ms(
long double msecs)
130 return time::duration<long double, time::milliseconds::period>{msecs};
133 constexpr time::microseconds
134 operator "" _us(
unsigned long long usecs)
136 return time::microseconds{usecs};
139 constexpr time::duration<long double, time::microseconds::period>
140 operator "" _us(
long double usecs)
142 return time::duration<long double, time::microseconds::period>{usecs};
145 constexpr time::nanoseconds
146 operator "" _ns(
unsigned long long nsecs)
148 return time::nanoseconds{nsecs};
151 constexpr time::duration<long double, time::nanoseconds::period>
152 operator "" _ns(
long double nsecs)
154 return time::duration<long double, time::nanoseconds::period>{nsecs};
162 using namespace literals::time_literals;
190 using duration = boost::chrono::system_clock::duration;
191 using rep = duration::rep;
194 static constexpr
bool is_steady = boost::chrono::system_clock::is_steady;
206 from_time_t(
std::time_t t) noexcept;
220 using duration = boost::chrono::steady_clock::duration;
221 using rep = duration::rep;
224 static constexpr
bool is_steady =
true;
311 const
std::
string& format = "%Y-%m-%d %H:%M:%S",
312 const
std::locale& locale =
std::locale("C"));
329 const
std::
string& format = "%Y-%m-%d %H:%M:%S",
330 const
std::locale& locale =
std::locale("C"));
338 template<
class CharT>
341 static std::basic_string<CharT>
345 template<
class CharT>
348 static std::basic_string<CharT>
352 extern template struct clock_string<ndn::time::system_clock, char>;
353 extern template struct clock_string<ndn::time::steady_clock, char>;
358 #endif // NDN_UTIL_TIME_HPP boost::chrono::system_clock::duration duration
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
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.
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) ...