29 Time library [time]

29.5 Class template duration[time.duration]

29.5.8 Conversions [time.duration.cast]

```template<class ToDuration, class Rep, class Period> constexpr ToDuration duration_cast(const duration<Rep, Period>& d); ```
Constraints: ToDuration is a specialization of duration.
Returns: Let CF be ratio_divide<Period, typename ToDuration​::​period>, and CR be common_type<typename ToDuration​::​rep, Rep, intmax_t>​::​type.
• If CF​::​num == 1 and CF​::​den == 1, returns ToDuration(static_cast<typename ToDuration::rep>(d.count()))
• otherwise, if CF​::​num != 1 and CF​::​den == 1, returns ToDuration(static_cast<typename ToDuration::rep>( static_cast<CR>(d.count()) * static_cast<CR>(CF::num)))
• otherwise, if CF​::​num == 1 and CF​::​den != 1, returns ToDuration(static_cast<typename ToDuration::rep>( static_cast<CR>(d.count()) / static_cast<CR>(CF::den)))
• otherwise, returns ToDuration(static_cast<typename ToDuration::rep>( static_cast<CR>(d.count()) * static_cast<CR>(CF::num) / static_cast<CR>(CF::den)))
[Note 1:
This function does not use any implicit conversions; all conversions are done with static_cast.
It avoids multiplications and divisions when it is known at compile time that one or more arguments is 1.
Intermediate computations are carried out in the widest representation and only converted to the destination representation at the final step.
â€” end note]
```template<class ToDuration, class Rep, class Period> constexpr ToDuration floor(const duration<Rep, Period>& d); ```
Constraints: ToDuration is a specialization of duration.
Returns: The greatest result t representable in ToDuration for which t <= d.
```template<class ToDuration, class Rep, class Period> constexpr ToDuration ceil(const duration<Rep, Period>& d); ```
Constraints: ToDuration is a specialization of duration.
Returns: The least result t representable in ToDuration for which t >= d.
```template<class ToDuration, class Rep, class Period> constexpr ToDuration round(const duration<Rep, Period>& d); ```
Constraints: ToDuration is a specialization of duration and treat_as_floating_point_v<typename ToDuration​::​rep> is false.
Returns: The value of ToDuration that is closest to d.
If there are two closest values, then return the value t for which t % 2 == 0.