22 #ifndef NDN_CXX_UTIL_TIME_HPP
23 #define NDN_CXX_UTIL_TIME_HPP
25 #include <boost/asio/wait_traits.hpp>
26 #include <boost/chrono.hpp>
32 #include <type_traits>
37 template<
typename Rep,
typename Period>
38 using duration = ::boost::chrono::duration<Rep, Period>;
40 using ::boost::chrono::duration_cast;
61 template<typename Rep, typename Period, typename = std::enable_if_t<std::numeric_limits<Rep>::is_signed>>
65 return d >= d.zero() ? d : -d;
70 inline namespace literals {
71 inline namespace time_literals {
74 operator ""_day(
unsigned long long days)
79 constexpr time::duration<long double, time::days::period>
80 operator ""_day(
long double days)
86 operator ""_days(
unsigned long long days)
91 constexpr time::duration<long double, time::days::period>
92 operator ""_days(
long double days)
98 operator ""_h(
unsigned long long hrs)
103 constexpr time::duration<long double, time::hours::period>
104 operator ""_h(
long double hrs)
110 operator ""_min(
unsigned long long mins)
115 constexpr time::duration<long double, time::minutes::period>
116 operator ""_min(
long double mins)
122 operator ""_s(
unsigned long long secs)
127 constexpr time::duration<long double, time::seconds::period>
128 operator ""_s(
long double secs)
134 operator ""_ms(
unsigned long long msecs)
139 constexpr time::duration<long double, time::milliseconds::period>
140 operator ""_ms(
long double msecs)
146 operator ""_us(
unsigned long long usecs)
151 constexpr time::duration<long double, time::microseconds::period>
152 operator ""_us(
long double usecs)
158 operator ""_ns(
unsigned long long nsecs)
163 constexpr time::duration<long double, time::nanoseconds::period>
164 operator ""_ns(
long double nsecs)
203 using rep = duration::rep;
205 using time_point = ::boost::chrono::time_point<system_clock>;
206 static constexpr
bool is_steady = ::boost::chrono::system_clock::is_steady;
230 using rep = duration::rep;
232 using time_point = ::boost::chrono::time_point<steady_clock>;
267 return duration_cast<Duration>(tp.time_since_epoch());
336 const std::string& format =
"%Y-%m-%d %H:%M:%S",
337 const std::locale& locale = std::locale(
"C"));
354 const std::string& format =
"%Y-%m-%d %H:%M:%S",
355 const std::locale& locale = std::locale(
"C"));
362 template<
typename CharT>
363 struct clock_string<
ndn::time::system_clock, CharT>
365 static std::basic_string<CharT>
369 template<
typename CharT>
370 struct clock_string<
ndn::time::steady_clock, CharT>
372 static std::basic_string<CharT>
376 extern template struct clock_string<ndn::time::system_clock, char>;
377 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
static time_point now() noexcept
static std::time_t to_time_t(const time_point &t) noexcept
::boost::chrono::time_point< system_clock > time_point
static constexpr bool is_steady
static time_point from_time_t(std::time_t t) noexcept
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)
Returns the absolute value of the duration d.
duration< int_fast32_t, boost::ratio< 86400 > > days
constexpr system_clock::time_point fromUnixTimestamp(system_clock::duration d)
Convert UNIX timestamp to system_clock::time_point.
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::seconds seconds
std::string toIsoString(const system_clock::time_point &timePoint)
Convert to the ISO 8601 string representation, basic format (YYYYMMDDTHHMMSS,fffffffff).
constexpr Duration toUnixTimestamp(const system_clock::time_point &tp)
Convert system_clock::time_point to UNIX timestamp.
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::microseconds microseconds
::boost::chrono::duration< Rep, Period > duration
::boost::chrono::minutes minutes
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...
::boost::chrono::milliseconds milliseconds
duration< int_fast32_t, boost::ratio< 31556952 > > years
::boost::chrono::nanoseconds nanoseconds
duration< int_fast32_t, boost::ratio< 2629746 > > months
::boost::chrono::hours hours