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;
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>
340 static std::basic_string<CharT>
344 template<
class 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