...one of the most highly
regarded and expertly designed C++ library projects in the
world.
— Herb Sutter and Andrei
Alexandrescu, C++
Coding Standards
boost::date_time::time_duration — Represents some amount of elapsed time measure to a given resolution.
// In header: <boost/date_time/time_duration.hpp> template<typename T, typename rep_type> class time_duration : private boost::less_than_comparable< T, boost::equality_comparable< T > > { public: // types typedef void _is_boost_date_time_duration; typedef T duration_type; typedef rep_type traits_type; typedef rep_type::day_type day_type; typedef rep_type::hour_type hour_type; typedef rep_type::min_type min_type; typedef rep_type::sec_type sec_type; typedef rep_type::fractional_seconds_type fractional_seconds_type; typedef rep_type::tick_type tick_type; typedef rep_type::impl_type impl_type; // construct/copy/destruct time_duration(); time_duration(hour_type, min_type, sec_type = 0, fractional_seconds_type = 0); time_duration(special_values); explicit time_duration(impl_type); // public member functions BOOST_CXX14_CONSTEXPR hour_type hours() const; BOOST_CXX14_CONSTEXPR min_type minutes() const; BOOST_CXX14_CONSTEXPR sec_type seconds() const; BOOST_CXX14_CONSTEXPR sec_type total_seconds() const; BOOST_CXX14_CONSTEXPR tick_type total_milliseconds() const; BOOST_CXX14_CONSTEXPR tick_type total_nanoseconds() const; BOOST_CXX14_CONSTEXPR tick_type total_microseconds() const; BOOST_CXX14_CONSTEXPR fractional_seconds_type fractional_seconds() const; BOOST_CXX14_CONSTEXPR duration_type invert_sign() const; BOOST_CXX14_CONSTEXPR duration_type abs() const; BOOST_CONSTEXPR bool is_negative() const; BOOST_CONSTEXPR bool is_zero() const; BOOST_CONSTEXPR bool is_positive() const; BOOST_CONSTEXPR bool operator<(const time_duration &) const; BOOST_CONSTEXPR bool operator==(const time_duration &) const; BOOST_CONSTEXPR duration_type operator-() const; BOOST_CONSTEXPR duration_type operator-(const duration_type &) const; BOOST_CONSTEXPR duration_type operator+(const duration_type &) const; BOOST_CONSTEXPR duration_type operator/(int) const; BOOST_CXX14_CONSTEXPR duration_type operator-=(const duration_type &); BOOST_CXX14_CONSTEXPR duration_type operator+=(const duration_type &); BOOST_CXX14_CONSTEXPR duration_type operator/=(int); BOOST_CXX14_CONSTEXPR duration_type operator *(int) const; BOOST_CXX14_CONSTEXPR duration_type operator *=(int); BOOST_CXX14_CONSTEXPR tick_type ticks() const; BOOST_CXX14_CONSTEXPR bool is_special() const; BOOST_CXX14_CONSTEXPR bool is_pos_infinity() const; BOOST_CXX14_CONSTEXPR bool is_neg_infinity() const; BOOST_CXX14_CONSTEXPR bool is_not_a_date_time() const; BOOST_CONSTEXPR impl_type get_rep() const; // public static functions static BOOST_CXX14_CONSTEXPR duration_type unit(); static BOOST_CXX14_CONSTEXPR tick_type ticks_per_second(); static BOOST_CXX14_CONSTEXPR time_resolutions resolution(); static BOOST_CXX14_CONSTEXPR unsigned short num_fractional_digits(); };
This class represents a standard set of capabilities for all counted time durations. Time duration implementations should derive from this class passing their type as the first template parameter. This design allows the subclass duration types to provide custom construction policies or other custom features not provided here.
typename T
The subclass type
typename rep_type
The time resolution traits for this duration type.
time_duration
public member functionsBOOST_CXX14_CONSTEXPR hour_type hours() const;Returns number of hours in the duration.
BOOST_CXX14_CONSTEXPR min_type minutes() const;Returns normalized number of minutes.
BOOST_CXX14_CONSTEXPR sec_type seconds() const;Returns normalized number of seconds (0..60)
BOOST_CXX14_CONSTEXPR sec_type total_seconds() const;Returns total number of seconds truncating any fractional seconds.
BOOST_CXX14_CONSTEXPR tick_type total_milliseconds() const;Returns total number of milliseconds truncating any fractional seconds.
BOOST_CXX14_CONSTEXPR tick_type total_nanoseconds() const;Returns total number of nanoseconds truncating any sub millisecond values.
BOOST_CXX14_CONSTEXPR tick_type total_microseconds() const;Returns total number of microseconds truncating any sub microsecond values.
BOOST_CXX14_CONSTEXPR fractional_seconds_type fractional_seconds() const;Returns count of fractional seconds at given resolution.
BOOST_CXX14_CONSTEXPR duration_type invert_sign() const;
BOOST_CXX14_CONSTEXPR duration_type abs() const;
BOOST_CONSTEXPR bool is_negative() const;
BOOST_CONSTEXPR bool is_zero() const;
BOOST_CONSTEXPR bool is_positive() const;
BOOST_CONSTEXPR bool operator<(const time_duration & rhs) const;
BOOST_CONSTEXPR bool operator==(const time_duration & rhs) const;
BOOST_CONSTEXPR duration_type operator-() const;unary- Allows for
time_duration
td = -td1 BOOST_CONSTEXPR duration_type operator-(const duration_type & d) const;
BOOST_CONSTEXPR duration_type operator+(const duration_type & d) const;
BOOST_CONSTEXPR duration_type operator/(int divisor) const;
BOOST_CXX14_CONSTEXPR duration_type operator-=(const duration_type & d);
BOOST_CXX14_CONSTEXPR duration_type operator+=(const duration_type & d);
BOOST_CXX14_CONSTEXPR duration_type operator/=(int divisor);Division operations on a duration with an integer.
BOOST_CXX14_CONSTEXPR duration_type operator *(int rhs) const;Multiplication operations an a duration with an integer.
BOOST_CXX14_CONSTEXPR duration_type operator *=(int divisor);
BOOST_CXX14_CONSTEXPR tick_type ticks() const;
BOOST_CXX14_CONSTEXPR bool is_special() const;Is ticks_ a special value?
BOOST_CXX14_CONSTEXPR bool is_pos_infinity() const;Is duration pos-infinity.
BOOST_CXX14_CONSTEXPR bool is_neg_infinity() const;Is duration neg-infinity.
BOOST_CXX14_CONSTEXPR bool is_not_a_date_time() const;Is duration not-a-date-time.
BOOST_CONSTEXPR impl_type get_rep() const;Used for special_values output.
time_duration
public static functionsstatic BOOST_CXX14_CONSTEXPR duration_type unit();Returns smallest representable duration.
static BOOST_CXX14_CONSTEXPR tick_type ticks_per_second();Return the number of ticks in a second.
static BOOST_CXX14_CONSTEXPR time_resolutions resolution();Provide the resolution of this duration type.
static BOOST_CXX14_CONSTEXPR unsigned short num_fractional_digits();Returns number of possible digits in fractional seconds.