| Home | Libraries | People | FAQ | More

## Class template time_duration

boost::date_time::time_duration — Represents some amount of elapsed time measure to a given resolution.

## Synopsis

    // 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(const time_duration< T, rep_type > &);
      time_duration(special_values);
      explicit time_duration(impl_type);

      // public member functions
      hour_type hours() const;
      min_type minutes() const;
      sec_type seconds() const;
      sec_type total_seconds() const;
      tick_type total_milliseconds() const;
      tick_type total_nanoseconds() const;
      tick_type total_microseconds() const;
      fractional_seconds_type fractional_seconds() const;
      duration_type invert_sign() const;
      bool is_negative() const;
      bool operator<(const time_duration &) const;
      bool operator==(const time_duration &) const;
      duration_type operator-() const;
      duration_type operator-(const duration_type &) const;
      duration_type operator+(const duration_type &) const;
      duration_type operator/(int) const;
      duration_type operator-=(const duration_type &);
      duration_type operator+=(const duration_type &);
      duration_type operator/=(int);
      duration_type operator*(int) const;
      duration_type operator*=(int);
      tick_type ticks() const;
      bool is_special() const;
      bool is_pos_infinity() const;
      bool is_neg_infinity() const;
      bool is_not_a_date_time() const;
      impl_type get_rep() const;

      // public static functions
      static duration_type unit();
      static tick_type ticks_per_second();
      static time_resolutions resolution();
      static unsigned short num_fractional_digits();
    };

## Description

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.

### `time_duration` public construct/copy/destruct

1.     time_duration();

2.     time_duration(hour_type hours_in, min_type minutes_in,
                     sec_type seconds_in = 0,
                     fractional_seconds_type frac_sec_in = 0);

3.     time_duration(const time_duration< T, rep_type > & other);

   Construct from another `time_duration` (Copy constructor)

4.     time_duration(special_values sv);

   Construct from special_values.

5.     explicit time_duration(impl_type in);

### `time_duration` public member functions

1.     hour_type hours() const;

   Returns number of hours in the duration.

2.     min_type minutes() const;

   Returns normalized number of minutes.

3.     sec_type seconds() const;

   Returns normalized number of seconds (0..60)

4.     sec_type total_seconds() const;

   Returns total number of seconds truncating any fractional seconds.

5.     tick_type total_milliseconds() const;

   Returns total number of milliseconds truncating any fractional seconds.

6.     tick_type total_nanoseconds() const;

   Returns total number of nanoseconds truncating any sub millisecond values.

7.     tick_type total_microseconds() const;

   Returns total number of microseconds truncating any sub microsecond values.

8.     fractional_seconds_type fractional_seconds() const;

   Returns count of fractional seconds at given resolution.

9.     duration_type invert_sign() const;

10.     bool is_negative() const;

11.     bool operator<(const time_duration & rhs) const;

12.     bool operator==(const time_duration & rhs) const;

13.     duration_type operator-() const;

    unary- Allows for `time_duration` td = -td1

14.     duration_type operator-(const duration_type & d) const;

15.     duration_type operator+(const duration_type & d) const;

16.     duration_type operator/(int divisor) const;

17.     duration_type operator-=(const duration_type & d);

18.     duration_type operator+=(const duration_type & d);

19.     duration_type operator/=(int divisor);

    Division operations on a duration with an integer.

20.     duration_type operator*(int rhs) const;

    Multiplication operations an a duration with an integer.

21.     duration_type operator*=(int divisor);

22.     tick_type ticks() const;

23.     bool is_special() const;

    Is ticks_ a special value?

24.     bool is_pos_infinity() const;

    Is duration pos-infinity.

25.     bool is_neg_infinity() const;

    Is duration neg-infinity.

26.     bool is_not_a_date_time() const;

    Is duration not-a-date-time.

27.     impl_type get_rep() const;

    Used for special_values output.

### `time_duration` public static functions

1.     static duration_type unit();

   Returns smallest representable duration.

2.     static tick_type ticks_per_second();

   Return the number of ticks in a second.

3.     static time_resolutions resolution();

   Provide the resolution of this duration type.

4.     static unsigned short num_fractional_digits();

   Returns number of possible digits in fractional seconds.