5.8 KiB
[time.hms.members]
30 Time library [time]
30.9 Class template hh_mm_ss [time.hms]
30.9.2 Members [time.hms.members]
static constexpr unsigned fractional_width = see below;
fractional_width is the number of fractional decimal digits represented by precision.
fractional_width has the value of the smallest possible integer in the range [0, 18] such thatprecision will exactly represent all values of Duration.
If no such value of fractional_width exists, thenfractional_width is 6.
[Example 1:
See Table 132 for some durations, the resulting fractional_width, and the formatted fractional second output of Duration{1}.
Table 132 — Examples for fractional_width [tab:time.hms.width]
| ð Duration |
fractional_width | Formatted fractional second output |
|---|---|---|
| ð hours, minutes, and seconds |
0 | |
| ð milliseconds |
3 | 0.001 |
| ð microseconds |
6 | 0.000001 |
| ð nanoseconds |
9 | 0.000000001 |
| ð duration<int, ratio<1, 2>> |
1 | 0.5 |
| ð duration<int, ratio<1, 3>> |
6 | 0.333333 |
| ð duration<int, ratio<1, 4>> |
2 | 0.25 |
| ð duration<int, ratio<1, 5>> |
1 | 0.2 |
| ð duration<int, ratio<1, 6>> |
6 | 0.166666 |
| ð duration<int, ratio<1, 7>> |
6 | 0.142857 |
| ð duration<int, ratio<1, 8>> |
3 | 0.125 |
| ð duration<int, ratio<1, 9>> |
6 | 0.111111 |
| ð duration<int, ratio<1, 10>> |
1 | 0.1 |
| ð duration<int, ratio<756, 625>> |
4 | 0.2096 |
â end example]
using precision = see below;
precision isduration<common_type_t<Duration::rep, seconds::rep>, ratio<1, 10fractional_width>>
constexpr explicit hh_mm_ss(Duration d);
Effects: Constructs an object of type hh_mm_ss which represents the Duration d with precision precision.
-
Initializes is_neg with d < Duration::zero().
-
Initializes h with duration_cast<chrono::hours>(abs(d)).
-
Initializes m with duration_cast<chrono::minutes>(abs(d) - hours()).
-
Initializes s with duration_cast<chrono::seconds>(abs(d) - hours() - minutes()).
-
If treat_as_floating_point_v<precision::rep> is true, initializes ss with abs(d) - hours() - minutes() - seconds(). Otherwise, initializes ss with duration_cast(abs(d) - hours() - minutes() - seconds()).
[Note 1:
When precision::rep is integral andprecision::period is ratio<1>,subseconds() always returns a value equal to 0s.
â end note]
Postconditions: If treat_as_floating_point_v<precision::rep> is true,to_duration() returns d, otherwise to_duration() returns duration_cast(d).
constexpr bool is_negative() const noexcept;
Returns: is_neg.
constexpr chrono::hours hours() const noexcept;
Returns: h.
constexpr chrono::minutes minutes() const noexcept;
Returns: m.
constexpr chrono::seconds seconds() const noexcept;
Returns: s.
constexpr precision subseconds() const noexcept;
Returns: ss.
constexpr precision to_duration() const noexcept;
Returns: If is_neg, returns -(h + m + s + ss), otherwise returns h + m + s + ss.
constexpr explicit operator precision() const noexcept;
Returns: to_duration().