ndn::time Namespace Reference

Classes

class  CustomClock
 Class implementing custom system or steady clock behavior. More...
 
class  steady_clock
 Steady clock. More...
 
class  system_clock
 System clock. More...
 
class  UnitTestClock
 Clock that can be used in unit tests for time-dependent tests independent of wall clock. More...
 
class  UnitTestClockTraits
 Traits for UnitTestClock, defining default behavior for different clocks. More...
 
class  UnitTestClockTraits< system_clock >
 Specialization of UnitTestClockTraits for system_clock. More...
 

Typedefs

using base_steady_clock = boost::chrono::steady_clock
 
using CustomSteadyClock = CustomClock< steady_clock >
 
using CustomSystemClock = CustomClock< system_clock >
 
using days = duration< int_fast32_t, boost::ratio< 86400 > >
 
template<typename Rep , typename Period >
using duration = ::boost::chrono::duration< Rep, Period >
 
using hours = ::boost::chrono::hours
 
using microseconds = ::boost::chrono::microseconds
 
using milliseconds = ::boost::chrono::milliseconds
 
using minutes = ::boost::chrono::minutes
 
using months = duration< int_fast32_t, boost::ratio< 2629746 > >
 
using nanoseconds = ::boost::chrono::nanoseconds
 
using seconds = ::boost::chrono::seconds
 
using UnitTestSteadyClock = UnitTestClock< steady_clock >
 
using UnitTestSystemClock = UnitTestClock< system_clock >
 
using weeks = duration< int_fast32_t, boost::ratio< 604800 > >
 
using years = duration< int_fast32_t, boost::ratio< 31556952 > >
 

Functions

template<typename Rep , typename Period , typename = std::enable_if_t<std::numeric_limits<Rep>::is_signed>>
constexpr duration< Rep, Period > abs (duration< Rep, Period > d)
 Returns the absolute value of the duration d. More...
 
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 format. More...
 
system_clock::time_point fromIsoString (const std::string &isoString)
 Convert from the ISO 8601 basic string format (YYYYMMDDTHHMMSS,fffffffff) to the internal time format. More...
 
system_clock::time_point fromString (const std::string &timePointStr, const std::string &format="%Y-%m-%d %H:%M:%S", const std::locale &locale=std::locale("C"))
 Convert from string of specified format into time point. More...
 
constexpr system_clock::time_point fromUnixTimestamp (system_clock::duration d)
 Convert UNIX timestamp to system_clock::time_point. More...
 
const system_clock::time_pointgetUnixEpoch ()
 Return a system_clock::time_point representing the UNIX time epoch, i.e., 00:00:00 UTC on 1 January 1970. More...
 
void setCustomClocks (std::shared_ptr< CustomSteadyClock > steadyClock=nullptr, std::shared_ptr< CustomSystemClock > systemClock=nullptr)
 Set custom system and steady clocks. More...
 
std::string toIsoExtendedString (const system_clock::time_point &timePoint)
 Convert to the ISO 8601 string representation, extended format (YYYY-MM-DDTHH:MM:SS,fffffffff). More...
 
std::string toIsoString (const system_clock::time_point &timePoint)
 Convert to the ISO 8601 string representation, basic format (YYYYMMDDTHHMMSS,fffffffff). More...
 
std::string toString (const system_clock::time_point &timePoint, const std::string &format="%Y-%m-%d %H:%M:%S", const std::locale &locale=std::locale("C"))
 Convert time point to string with specified format. More...
 
template<typename Duration = milliseconds>
constexpr Duration toUnixTimestamp (const system_clock::time_point &tp)
 Convert system_clock::time_point to UNIX timestamp. More...
 

Typedef Documentation

◆ base_steady_clock

using ndn::time::base_steady_clock = typedef boost::chrono::steady_clock

Definition at line 75 of file time.cpp.

◆ CustomSteadyClock

Definition at line 55 of file time-custom-clock.hpp.

◆ CustomSystemClock

Definition at line 54 of file time-custom-clock.hpp.

◆ days

using ndn::time::days = typedef duration<int_fast32_t, boost::ratio<86400> >

Definition at line 43 of file time.hpp.

◆ duration

template<typename Rep , typename Period >
using ndn::time::duration = typedef ::boost::chrono::duration<Rep, Period>

Definition at line 38 of file time.hpp.

◆ hours

using ndn::time::hours = typedef ::boost::chrono::hours

Definition at line 49 of file time.hpp.

◆ microseconds

using ndn::time::microseconds = typedef ::boost::chrono::microseconds

Definition at line 53 of file time.hpp.

◆ milliseconds

using ndn::time::milliseconds = typedef ::boost::chrono::milliseconds

Definition at line 52 of file time.hpp.

◆ minutes

using ndn::time::minutes = typedef ::boost::chrono::minutes

Definition at line 50 of file time.hpp.

◆ months

using ndn::time::months = typedef duration<int_fast32_t, boost::ratio<2629746> >

Definition at line 45 of file time.hpp.

◆ nanoseconds

using ndn::time::nanoseconds = typedef ::boost::chrono::nanoseconds

Definition at line 54 of file time.hpp.

◆ seconds

using ndn::time::seconds = typedef ::boost::chrono::seconds

Definition at line 51 of file time.hpp.

◆ UnitTestSteadyClock

◆ UnitTestSystemClock

◆ weeks

using ndn::time::weeks = typedef duration<int_fast32_t, boost::ratio<604800> >

Definition at line 44 of file time.hpp.

◆ years

using ndn::time::years = typedef duration<int_fast32_t, boost::ratio<31556952> >

Definition at line 46 of file time.hpp.

Function Documentation

◆ abs()

template<typename Rep , typename Period , typename = std::enable_if_t<std::numeric_limits<Rep>::is_signed>>
constexpr duration<Rep, Period> ndn::time::abs ( duration< Rep, Period >  d)
constexpr

Returns the absolute value of the duration d.

Note
This function does not participate in overload resolution unless std::numeric_limits<Rep>::is_signed is true.

Definition at line 63 of file time.hpp.

◆ fromIsoExtendedString()

system_clock::time_point ndn::time::fromIsoExtendedString ( const std::string &  isoString)

Convert from the ISO 8601 extended string format (YYYY-MM-DDTHH:MM:SS,fffffffff) to the internal time format.

Definition at line 161 of file time.cpp.

◆ fromIsoString()

system_clock::time_point ndn::time::fromIsoString ( const std::string &  isoString)

Convert from the ISO 8601 basic string format (YYYYMMDDTHHMMSS,fffffffff) to the internal time format.

Examples of accepted strings:

  • with fractional nanoseconds: 20020131T100001,123456789
  • with fractional microseconds: 20020131T100001,123456
  • with fractional milliseconds: 20020131T100001,123
  • without fractional seconds: 20020131T100001

Definition at line 155 of file time.cpp.

◆ fromString()

system_clock::time_point ndn::time::fromString ( const std::string &  timePointStr,
const std::string &  format = "%Y-%m-%d %H:%M:%S",
const std::locale &  locale = std::locale("C") 
)

Convert from string of specified format into time point.

By default, Y-m-d H:M:S is used, accepting dates like 2014-04-10 22:51:00

Parameters
timePointStrstring representing time point
formatinput output format (default: Y-m-d H:M:S)
localeinput locale (default: "C" locale)
See also
https://www.boost.org/doc/libs/1_71_0/doc/html/date_time/date_time_io.html#date_time.format_flags describes possible formatting flags

Definition at line 182 of file time.cpp.

◆ fromUnixTimestamp()

constexpr system_clock::time_point ndn::time::fromUnixTimestamp ( system_clock::duration  d)
constexpr

Convert UNIX timestamp to system_clock::time_point.

Definition at line 274 of file time.hpp.

◆ getUnixEpoch()

const system_clock::time_point & ndn::time::getUnixEpoch ( )

Return a system_clock::time_point representing the UNIX time epoch, i.e., 00:00:00 UTC on 1 January 1970.

Definition at line 105 of file time.cpp.

◆ setCustomClocks()

void ndn::time::setCustomClocks ( std::shared_ptr< CustomSteadyClock steadyClock = nullptr,
std::shared_ptr< CustomSystemClock systemClock = nullptr 
)

Set custom system and steady clocks.

When steadyClock or systemClock set to nullptr, the default implementation of the corresponding clock will be used

Definition at line 35 of file time.cpp.

◆ toIsoExtendedString()

std::string ndn::time::toIsoExtendedString ( const system_clock::time_point timePoint)

Convert to the ISO 8601 string representation, extended format (YYYY-MM-DDTHH:MM:SS,fffffffff).

Definition at line 136 of file time.cpp.

◆ toIsoString()

std::string ndn::time::toIsoString ( const system_clock::time_point timePoint)

Convert to the ISO 8601 string representation, basic format (YYYYMMDDTHHMMSS,fffffffff).

If timePoint does not contain any fractional seconds, the output format is YYYYMMDDTHHMMSS.

Examples:

  • with fractional nanoseconds: 20020131T100001,123456789
  • with fractional microseconds: 20020131T100001,123456
  • with fractional milliseconds: 20020131T100001,123
  • without fractional seconds: 20020131T100001

Definition at line 130 of file time.cpp.

◆ toString()

std::string ndn::time::toString ( const system_clock::time_point timePoint,
const std::string &  format = "%Y-%m-%d %H:%M:%S",
const std::locale &  locale = std::locale("C") 
)

Convert time point to string with specified format.

By default, Y-m-d H:M:S is used, producing dates like 2014-04-10 22:51:00

Parameters
timePointtime point of system_clock
formatdesired output format (default: Y-m-d H:M:S)
localedesired locale (default: "C" locale)
See also
https://www.boost.org/doc/libs/1_71_0/doc/html/date_time/date_time_io.html#date_time.format_flags describes possible formatting flags

Definition at line 167 of file time.cpp.

◆ toUnixTimestamp()

template<typename Duration = milliseconds>
constexpr Duration ndn::time::toUnixTimestamp ( const system_clock::time_point tp)
constexpr

Convert system_clock::time_point to UNIX timestamp.

Definition at line 265 of file time.hpp.