[time.duration.general]

# 30 Time library [[time]](./#time)

## 30.5 Class template duration [[time.duration]](time.duration#general)

### 30.5.1 General [time.duration.general]

[1](#1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L1238)

A duration type measures time between two points in time (time_points)[.](#1.sentence-1)

A duration has a representation which holds a count of ticks and a tick period[.](#1.sentence-2)

The tick period is the amount of time which occurs from one tick to the next, in units
of seconds[.](#1.sentence-3)

It is expressed as a rational constant using the template ratio[.](#1.sentence-4)

[ð](#lib:duration)

namespace std::chrono {template<class Rep, class Period = ratio<1>>class duration {public:using rep = Rep; using period = typename Period::type; private: rep rep_; // *exposition only*public:// [[time.duration.cons]](time.duration.cons "30.5.2 Constructors"), construct/copy/destroyconstexpr duration() = default; template<class Rep2>constexpr explicit duration(const Rep2& r); template<class Rep2, class Period2>constexpr duration(const duration<Rep2, Period2>& d); ~duration() = default;
 duration(const duration&) = default;
 duration& operator=(const duration&) = default; // [[time.duration.observer]](time.duration.observer "30.5.3 Observer"), observerconstexpr rep count() const; // [[time.duration.arithmetic]](time.duration.arithmetic "30.5.4 Arithmetic"), arithmeticconstexpr common_type_t<duration> operator+() const; constexpr common_type_t<duration> operator-() const; constexpr duration& operator++(); constexpr duration operator++(int); constexpr duration& operator--(); constexpr duration operator--(int); constexpr duration& operator+=(const duration& d); constexpr duration& operator-=(const duration& d); constexpr duration& operator*=(const rep& rhs); constexpr duration& operator/=(const rep& rhs); constexpr duration& operator%=(const rep& rhs); constexpr duration& operator%=(const duration& rhs); // [[time.duration.special]](time.duration.special "30.5.5 Special values"), special valuesstatic constexpr duration zero() noexcept; static constexpr duration min() noexcept; static constexpr duration max() noexcept; };}

[2](#2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L1294)

Rep shall be an arithmetic type or a class emulating an arithmetic type[.](#2.sentence-1)

If duration is instantiated with a duration type as the argument for the template
parameter Rep, the program is ill-formed[.](#2.sentence-2)

[3](#3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L1299)

If Period is not a specialization of ratio, the program is ill-formed[.](#3.sentence-1)

If Period​::​num is not positive, the program is ill-formed[.](#3.sentence-2)

[4](#4)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L1303)

Members of duration do not throw exceptions other than
those thrown by the indicated operations on their representations[.](#4.sentence-1)

[5](#5)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L1307)

The defaulted copy constructor of duration shall be a
constexpr function if and only if the required initialization
of the member rep_ for copy and move, respectively, would
be constexpr-suitable ([[dcl.constexpr]](dcl.constexpr "9.2.6 The constexpr and consteval specifiers"))[.](#5.sentence-1)

[6](#6)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L1313)

[*Example [1](#example-1)*: duration<long, ratio<60>> d0; // holds a count of minutes using a long duration<long long, milli> d1; // holds a count of milliseconds using a long long duration<double, ratio<1, 30>> d2; // holds a count with a tick period of 130 of a second// (30 Hz) using a double â *end example*]
