22 #ifndef NDN_CXX_UTIL_TIME_HPP
23 #define NDN_CXX_UTIL_TIME_HPP
27 #include <boost/asio/wait_traits.hpp>
28 #include <boost/chrono.hpp>
33 template<
typename Rep,
typename Period>
34 using duration = boost::chrono::duration<Rep, Period>;
36 using boost::chrono::duration_cast;
56 template<typename Rep, typename Period, typename = std::enable_if_t<std::numeric_limits<Rep>::is_signed>>
60 return d >= d.zero() ? d : -d;
65 inline namespace literals {
66 inline namespace time_literals {
69 operator "" _day(
unsigned long long days)
74 constexpr time::duration<long double, time::days::period>
75 operator "" _day(
long double days)
81 operator "" _days(
unsigned long long days)
86 constexpr time::duration<long double, time::days::period>
87 operator "" _days(
long double days)
93 operator "" _h(
unsigned long long hrs)
98 constexpr time::duration<long double, time::hours::period>
99 operator "" _h(
long double hrs)
105 operator "" _min(
unsigned long long mins)
110 constexpr time::duration<long double, time::minutes::period>
111 operator "" _min(
long double mins)
117 operator "" _s(
unsigned long long secs)
122 constexpr time::duration<long double, time::seconds::period>
123 operator "" _s(
long double secs)
129 operator "" _ms(
unsigned long long msecs)
134 constexpr time::duration<long double, time::milliseconds::period>
135 operator "" _ms(
long double msecs)
141 operator "" _us(
unsigned long long usecs)
146 constexpr time::duration<long double, time::microseconds::period>
147 operator "" _us(
long double usecs)
153 operator "" _ns(
unsigned long long nsecs)
158 constexpr time::duration<long double, time::nanoseconds::period>
159 operator "" _ns(
long double nsecs)
169 using namespace literals::time_literals;
198 using rep = duration::rep;
201 static constexpr
bool is_steady = boost::chrono::system_clock::is_steady;
213 from_time_t(std::time_t t) noexcept;
228 using rep = duration::rep;
231 static constexpr
bool is_steady =
true;
330 const std::
string& format = "%Y-%m-%d %H:%M:%S",
331 const std::locale& locale = std::locale("C"));
348 const std::
string& format = "%Y-%m-%d %H:%M:%S",
349 const std::locale& locale = std::locale("C"));
357 template<
typename CharT>
358 struct clock_string<
ndn::time::system_clock, CharT>
360 static std::basic_string<CharT>
364 template<
typename CharT>
365 struct clock_string<
ndn::time::steady_clock, CharT>
367 static std::basic_string<CharT>
371 extern template struct clock_string<ndn::time::system_clock, char>;
372 extern template struct clock_string<ndn::time::steady_clock, char>;
boost::chrono::steady_clock::duration duration
boost::chrono::time_point< steady_clock > time_point
boost::chrono::system_clock::duration duration
boost::chrono::time_point< system_clock > time_point
Common includes and macros used throughout the library.
std::string toIsoExtendedString(const system_clock::time_point &timePoint)
Convert to the ISO 8601 string representation, extended format (YYYY-MM-DDTHH:MM:SS,...
constexpr duration< Rep, Period > abs(duration< Rep, Period > d)
duration< int_fast32_t, boost::ratio< 86400 > > days
milliseconds toUnixTimestamp(const system_clock::time_point &point)
Convert system_clock::time_point to UNIX timestamp.
std::string toString(const system_clock::time_point &timePoint, const std::string &format, const std::locale &locale)
Convert time point to string with specified format.
boost::chrono::minutes minutes
std::string toIsoString(const system_clock::time_point &timePoint)
Convert to the ISO 8601 string representation, basic format (YYYYMMDDTHHMMSS,fffffffff).
const system_clock::time_point & getUnixEpoch()
Return a system_clock::time_point representing the UNIX time epoch, i.e., 00:00:00 UTC on 1 January 1...
boost::chrono::duration< Rep, Period > duration
boost::chrono::milliseconds milliseconds
boost::chrono::nanoseconds nanoseconds
boost::chrono::microseconds microseconds
system_clock::time_point fromIsoString(const std::string &isoString)
Convert from the ISO 8601 basic string format (YYYYMMDDTHHMMSS,fffffffff) to the internal time format...
system_clock::time_point fromString(const std::string &timePointStr, const std::string &format, const std::locale &locale)
Convert from string of specified format into time point.
duration< int_fast32_t, boost::ratio< 604800 > > weeks
system_clock::time_point fromIsoExtendedString(const std::string &isoString)
Convert from the ISO 8601 extended string format (YYYY-MM-DDTHH:MM:SS,fffffffff) to the internal time...
system_clock::time_point fromUnixTimestamp(milliseconds duration)
Convert UNIX timestamp to system_clock::time_point.
duration< int_fast32_t, boost::ratio< 31556952 > > years
boost::chrono::hours hours
boost::chrono::seconds seconds
duration< int_fast32_t, boost::ratio< 2629746 > > months