[time.duration.cons]

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

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

### 30.5.2 Constructors [time.duration.cons]

[ð](#lib:duration,constructor)

`template<class Rep2>
  constexpr explicit duration(const Rep2& r);
`

[1](#1)

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

*Constraints*: is_convertible_v<const Rep2&, rep> is true and

- [(1.1)](#1.1)

treat_as_floating_point_v<rep> is true or

- [(1.2)](#1.2)

treat_as_floating_point_v<Rep2> is false[.](#1.sentence-1)

[*Example [1](#example-1)*: duration<int, milli> d(3); // OK duration<int, milli> d2(3.5); // error â *end example*]

[2](#2)

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

*Effects*: Initializes rep_ with r[.](#2.sentence-1)

[ð](#lib:duration,constructor_)

`template<class Rep2, class Period2>
  constexpr duration(const duration<Rep2, Period2>& d);
`

[3](#3)

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

*Constraints*: No overflow is induced in the conversion andtreat_as_floating_point_v<rep> is true or bothratio_divide<Period2, period>​::​den is 1 andtreat_as_floating_point_v<Rep2> is false[.](#3.sentence-1)

[*Note [1](#note-1)*:

This
requirement prevents implicit truncation error when converting between
integral-based duration types[.](#3.sentence-2)

Such a construction could easily lead to
confusion about the value of the duration[.](#3.sentence-3)

â *end note*]

[*Example [2](#example-2)*: duration<int, milli> ms(3);
duration<int, micro> us = ms; // OK duration<int, milli> ms2 = us; // error â *end example*]

[4](#4)

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

*Effects*: Initializes rep_ with duration_cast<duration>(d).count()[.](#4.sentence-1)
