From 5eb10b747fdc3c10cb13f55f833c4ea96eac2684 Mon Sep 17 00:00:00 2001 From: Howard Hinnant Date: Thu, 24 Nov 2016 19:43:35 -0500 Subject: [PATCH] Unify and simplify fractional decimal seconds formatting * Many of the ideas and some of the code herein is credited to Adrian Colomitchi * Decouple fractional decimal seconds formatting from time_of_day formatting so that it can be more easily used elsewhere in the future. * Include super-second durations such as nanocenturies and microfortnights in the class of durations that will get formatted with fractional decimal seconds. * If a duration is exactly representable with fractional decimal seconds not exceeding 18 decimal fractional digits, format it exactly. Otherwise format it to 6 fractional decimal digits (microseconds precision). The number 18 is chosen as this is the limit of std::ratio using 64 bits (i.e. atto). * The above bullet implies that durations with ratio<1, 4> will now be formatted with 2 fractional decimal digits instead of 1. ratio<1, 8> will be formatted with 3, and ratio<1, 3> with 6. * Unify the implementation into one C++11 implementation that works equally well with C++14. * Drive-by fix a couple formatting bugs dealing with negative durations. * Deprecate the make_time functions taking unsigned md by removing their documentation. Also deprecate the corresponding time_of_day constructors taking unsigned md. * This change paves the way for future formatting improvements. --- date.html | 187 +++--------------------------------------------------- 1 file changed, 8 insertions(+), 179 deletions(-) diff --git a/date.html b/date.html index 92d7408..fe73905 100644 --- a/date.html +++ b/date.html @@ -26,7 +26,7 @@

Howard E. Hinnant
-2016-09-13
+2016-11-24

date

@@ -1573,7 +1573,7 @@ and predictable.  constexpr year_month_weekday_last operator/(const month_weekday_last& mwdl, int y) noexcept;    -time_of_day
factory functions  +time_of_day
factory function   
 template <class Rep, class Period>
@@ -1582,38 +1582,6 @@ time_of_day<std::chrono::duration<Rep, Period>>
 make_time(std::chrono::duration<Rep, Period> d) noexcept;
 
-
-constexpr
-time_of_day<std::chrono::hours>
-make_time(std::chrono::hours h, unsigned md) noexcept;
-
- -  -
-constexpr
-time_of_day<std::chrono::minutes>
-make_time(std::chrono::hours h, std::chrono::minutes m, unsigned md) noexcept;
-
- -  -
-constexpr
-time_of_day<std::chrono::seconds>
-make_time(std::chrono::hours h, std::chrono::minutes m, std::chrono::seconds s,
-          unsigned md) noexcept;
-
- -  -
-template <class Rep, class Period,
-          class = std::enable_if_t<std::ratio_less<Period, std::ratio<1>>::value>>
-constexpr
-time_of_day<std::chrono::duration<Rep, Period>>
-make_time(std::chrono::hours h, std::chrono::minutes m, std::chrono::seconds s,
-          std::chrono::duration<Rep, Period> sub_s, unsigned md) noexcept
-
-    convenience
streaming operators  @@ -6332,8 +6300,8 @@ This specialization handles hours:minutes:seconds since midnight. time_of_day<std::chrono::duration<Rep, Period>>

-This specialization is restricted to Periods that are shorter than 1 -second. Typical uses are with milliseconds, microseconds and nanoseconds. This +This specialization is restricted to Periods that fractions of a second +to represent. Typical uses are with milliseconds, microseconds and nanoseconds. This specialization handles hours:minute:seconds.fractional_seconds since midnight.

@@ -6359,7 +6327,6 @@ public: using precision = std::chrono::hours; constexpr explicit time_of_day(std::chrono::hours since_midnight) noexcept; - constexpr time_of_day(std::chrono::hours h, unsigned md) noexcept; constexpr std::chrono::hours hours() const noexcept; constexpr unsigned mode() const noexcept; @@ -6387,24 +6354,6 @@ corresponding to since_midnight hours after 00:00:00.

-
-constexpr time_of_day<std::chrono::hours>::time_of_day(std::chrono::hours h, unsigned md) noexcept;
-
- -
-

-Preconditions: md == am or md == pm. -

-

-Effects: Constructs an object of type time_of_day in 12-hour format -corresponding to h hours after 00:00:00. -

-

-Postconditions: hours() returns h, and mode() -returns md. -

-
-
 constexpr std::chrono::hours time_of_day<std::chrono::hours>::hours() const noexcept;
 
@@ -6505,8 +6454,6 @@ public: using precision = std::chrono::minutes; constexpr explicit time_of_day(std::chrono::minutes since_midnight) noexcept; - constexpr time_of_day(std::chrono::hours h, std::chrono::minutes m, - unsigned md) noexcept; constexpr std::chrono::hours hours() const noexcept; constexpr std::chrono::minutes minutes() const noexcept; @@ -6537,25 +6484,6 @@ integral number of minutes since_midnight is after (00:00:00 +

-
-constexpr time_of_day<std::chrono::minutes>::time_of_day(std::chrono::hours h, std::chrono::minutes m,
-                                                               unsigned md) noexcept;
-
- -
-

-Preconditions: md == am or md == pm. -

-

-Effects: Constructs an object of type time_of_day in 12-hour format -corresponding to h hours and m minutes after 00:00:00. -

-

-Postconditions: hours() returns h, minutes() -returns m, and mode() returns md. -

-
-
 constexpr std::chrono::hours time_of_day<std::chrono::minutes>::hours() const noexcept;
 
@@ -6666,8 +6594,6 @@ public: using precision = std::chrono::seconds; constexpr explicit time_of_day(std::chrono::seconds since_midnight) noexcept; - constexpr time_of_day(std::chrono::hours h, std::chrono::minutes m, - std::chrono::seconds s, unsigned md) noexcept; constexpr std::chrono::hours hours() const noexcept; constexpr std::chrono::minutes minutes() const noexcept; @@ -6701,27 +6627,6 @@ integral number of minutes since_midnight is after (00:00:00 +

-
-constexpr time_of_day<std::chrono::seconds>::time_of_day(std::chrono::hours h, std::chrono::minutes m,
-                                                               std::chrono::seconds s, unsigned md) noexcept;
-
- -
-

-Preconditions: md == am or md == pm. -

-

-Effects: Constructs an object of type time_of_day in 12-hour format -corresponding to h hours, m minutes, and s seconds -after 00:00:00. -

-

-Postconditions: hours() returns h. minutes() -returns m. seconds() returns s. -mode() returns md. -

-
-
 constexpr std::chrono::hours time_of_day<std::chrono::seconds>::hours() const noexcept;
 
@@ -6839,11 +6744,9 @@ that no leading zero is output for hours less than 10. time_of_day<std::chrono::duration<Rep, Period>> { public: - using precision = std::chrono::duration<Rep, Period>; + using precision = The decimal-based duration used to format - constexpr explicit time_of_day(precision since_midnight) noexcept; - constexpr time_of_day(std::chrono::hours h, std::chrono::minutes m, - std::chrono::seconds s, precision sub_s, unsigned md) noexcept; + constexpr explicit time_of_day(std::chrono::duration<Rep, Period> since_midnight) noexcept; constexpr std::chrono::hours hours() const noexcept; constexpr std::chrono::minutes minutes() const noexcept; @@ -6864,7 +6767,8 @@ This specialization shall not exist unless Period < 1s.

-constexpr explicit time_of_day<std::chrono::duration<Rep, Period>>::time_of_day(precision since_midnight) noexcept;
+constexpr explicit 
+time_of_day<std::chrono::duration<Rep, Period>>::time_of_day(std::chrono::duration<Rep, Period> since_midnight) noexcept;
 
@@ -6885,29 +6789,6 @@ returns 0.

-
-constexpr time_of_day<std::chrono::duration<Rep, Period>>::time_of_day(std::chrono::hours h, std::chrono::minutes m,
-                                                                       std::chrono::seconds s, precision sub_s,
-                                                                       unsigned md) noexcept;
-
- -
-

-Preconditions: md == am or md == pm. -

-

-Effects: Constructs an object of type time_of_day in 12-hour format -corresponding to h hours, m minutes, and s + sub_s -seconds after 00:00:00. -

-

-Postconditions: hours() returns h. minutes() -returns m. seconds() returns s. -subseconds() returns sub_s. mode() returns -md. -

-
-
 constexpr std::chrono::hours time_of_day<std::chrono::duration<Rep, Period>>::hours() const noexcept;
 
@@ -7053,58 +6934,6 @@ make_time(std::chrono::duration<Rep, Period> d) noexcept;

-
-constexpr
-time_of_day<std::chrono::hours>
-make_time(std::chrono::hours h, unsigned md) noexcept;
-
- -
-

-Returns: time_of_day<std::chrono::hours>(h, md). -

-
- -
-constexpr
-time_of_day<std::chrono::minutes>
-make_time(std::chrono::hours h, std::chrono::minutes m, unsigned md) noexcept;
-
- -
-

-Returns: time_of_day<std::chrono::minutes>(h, m, md). -

-
- -
-constexpr
-time_of_day<std::chrono::seconds>
-make_time(std::chrono::hours h, std::chrono::minutes m, std::chrono::seconds s,
-          unsigned md) noexcept;
-
- -
-

-Returns: time_of_day<std::chrono::seconds>(h, m, s, md). -

-
- -
-template <class Rep, class Period,
-          class = std::enable_if_t<std::ratio_less<Period, std::ratio<1>>::value>>
-constexpr
-time_of_day<std::chrono::duration<Rep, Period>>
-make_time(std::chrono::hours h, std::chrono::minutes m, std::chrono::seconds s,
-          std::chrono::duration<Rep, Period> sub_s, unsigned md) noexcept
-
- -
-

-Returns: time_of_day<std::chrono::duration<Rep, Period>>(h, m, s, sub_s, md). -

-
-