forked from HowardHinnant/date
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.
This commit is contained in:
187
date.html
187
date.html
@@ -26,7 +26,7 @@
|
||||
<br/>
|
||||
<br/>
|
||||
<a href="mailto:howard.hinnant@gmail.com">Howard E. Hinnant</a><br/>
|
||||
2016-09-13<br/>
|
||||
2016-11-24<br/>
|
||||
</address>
|
||||
<hr/>
|
||||
<h1 align=center><code>date</code></h1>
|
||||
@@ -1573,7 +1573,7 @@ and predictable.
|
||||
<tr><td> </td><td><a href="#_40"><code>constexpr year_month_weekday_last operator/(const month_weekday_last& mwdl, int y) noexcept;</code></a></td></tr>
|
||||
|
||||
<tr><td> </td><td> </td></tr>
|
||||
<tr><td><code>time_of_day</code><br/> factory functions</td><td> </td></tr>
|
||||
<tr><td><code>time_of_day</code><br/> factory function</td><td> </td></tr>
|
||||
<tr><td> </td><td><a href="#_41">
|
||||
<pre>
|
||||
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;
|
||||
</pre></a></td></tr>
|
||||
|
||||
<tr><td> </td><td><a href="#_42">
|
||||
<pre>
|
||||
constexpr
|
||||
time_of_day<std::chrono::hours>
|
||||
make_time(std::chrono::hours h, unsigned md) noexcept;
|
||||
</pre></a></td></tr>
|
||||
|
||||
<tr><td> </td><td><a href="#_43">
|
||||
<pre>
|
||||
constexpr
|
||||
time_of_day<std::chrono::minutes>
|
||||
make_time(std::chrono::hours h, std::chrono::minutes m, unsigned md) noexcept;
|
||||
</pre></a></td></tr>
|
||||
|
||||
<tr><td> </td><td><a href="#_44">
|
||||
<pre>
|
||||
constexpr
|
||||
time_of_day<std::chrono::seconds>
|
||||
make_time(std::chrono::hours h, std::chrono::minutes m, std::chrono::seconds s,
|
||||
unsigned md) noexcept;
|
||||
</pre></a></td></tr>
|
||||
|
||||
<tr><td> </td><td><a href="#_45">
|
||||
<pre>
|
||||
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
|
||||
</pre></a></td></tr>
|
||||
|
||||
<tr><td> </td><td> </td></tr>
|
||||
<tr><td>convenience<br/>streaming operators</td><td> </td></tr>
|
||||
|
||||
@@ -6332,8 +6300,8 @@ This specialization handles hours:minutes:seconds since midnight.
|
||||
time_of_day<std::chrono::duration<Rep, Period>>
|
||||
</pre>
|
||||
<blockquote><p>
|
||||
This specialization is restricted to <code>Period</code>s that are shorter than 1
|
||||
second. Typical uses are with milliseconds, microseconds and nanoseconds. This
|
||||
This specialization is restricted to <code>Period</code>s 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.
|
||||
</p></blockquote>
|
||||
</li>
|
||||
@@ -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 <code>since_midnight</code> hours after 00:00:00.
|
||||
</p>
|
||||
</blockquote>
|
||||
|
||||
<pre>
|
||||
constexpr time_of_day<std::chrono::hours>::time_of_day(std::chrono::hours h, unsigned md) noexcept;
|
||||
</pre>
|
||||
|
||||
<blockquote>
|
||||
<p>
|
||||
<i>Preconditions:</i> <code>md == am</code> or <code>md == pm</code>.
|
||||
</p>
|
||||
<p>
|
||||
<i>Effects:</i> Constructs an object of type <code>time_of_day</code> in 12-hour format
|
||||
corresponding to <code>h</code> hours after 00:00:00.
|
||||
</p>
|
||||
<p>
|
||||
<i>Postconditions:</i> <code>hours()</code> returns <code>h</code>, and <code>mode()</code>
|
||||
returns <code>md</code>.
|
||||
</p>
|
||||
</blockquote>
|
||||
|
||||
<pre>
|
||||
constexpr std::chrono::hours time_of_day<std::chrono::hours>::hours() const noexcept;
|
||||
</pre>
|
||||
@@ -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 <code>since_midnight</code> is after (00:00:00 +
|
||||
</p>
|
||||
</blockquote>
|
||||
|
||||
<pre>
|
||||
constexpr time_of_day<std::chrono::minutes>::time_of_day(std::chrono::hours h, std::chrono::minutes m,
|
||||
unsigned md) noexcept;
|
||||
</pre>
|
||||
|
||||
<blockquote>
|
||||
<p>
|
||||
<i>Preconditions:</i> <code>md == am</code> or <code>md == pm</code>.
|
||||
</p>
|
||||
<p>
|
||||
<i>Effects:</i> Constructs an object of type <code>time_of_day</code> in 12-hour format
|
||||
corresponding to <code>h</code> hours and <code>m</code> minutes after 00:00:00.
|
||||
</p>
|
||||
<p>
|
||||
<i>Postconditions:</i> <code>hours()</code> returns <code>h</code>, <code>minutes()</code>
|
||||
returns <code>m</code>, and <code>mode()</code> returns <code>md</code>.
|
||||
</p>
|
||||
</blockquote>
|
||||
|
||||
<pre>
|
||||
constexpr std::chrono::hours time_of_day<std::chrono::minutes>::hours() const noexcept;
|
||||
</pre>
|
||||
@@ -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 <code>since_midnight</code> is after (00:00:00 +
|
||||
</p>
|
||||
</blockquote>
|
||||
|
||||
<pre>
|
||||
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;
|
||||
</pre>
|
||||
|
||||
<blockquote>
|
||||
<p>
|
||||
<i>Preconditions:</i> <code>md == am</code> or <code>md == pm</code>.
|
||||
</p>
|
||||
<p>
|
||||
<i>Effects:</i> Constructs an object of type <code>time_of_day</code> in 12-hour format
|
||||
corresponding to <code>h</code> hours, <code>m</code> minutes, and <code>s</code> seconds
|
||||
after 00:00:00.
|
||||
</p>
|
||||
<p>
|
||||
<i>Postconditions:</i> <code>hours()</code> returns <code>h</code>. <code>minutes()</code>
|
||||
returns <code>m</code>. <code>seconds()</code> returns <code>s</code>.
|
||||
<code>mode()</code> returns <code>md</code>.
|
||||
</p>
|
||||
</blockquote>
|
||||
|
||||
<pre>
|
||||
constexpr std::chrono::hours time_of_day<std::chrono::seconds>::hours() const noexcept;
|
||||
</pre>
|
||||
@@ -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 = <i>The decimal-based duration used to format</i>
|
||||
|
||||
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 <code>Period < 1s</code>.
|
||||
</p>
|
||||
|
||||
<pre>
|
||||
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;
|
||||
</pre>
|
||||
|
||||
<blockquote>
|
||||
@@ -6885,29 +6789,6 @@ returns <code>0</code>.
|
||||
</p>
|
||||
</blockquote>
|
||||
|
||||
<pre>
|
||||
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;
|
||||
</pre>
|
||||
|
||||
<blockquote>
|
||||
<p>
|
||||
<i>Preconditions:</i> <code>md == am</code> or <code>md == pm</code>.
|
||||
</p>
|
||||
<p>
|
||||
<i>Effects:</i> Constructs an object of type <code>time_of_day</code> in 12-hour format
|
||||
corresponding to <code>h</code> hours, <code>m</code> minutes, and <code>s + sub_s</code>
|
||||
seconds after 00:00:00.
|
||||
</p>
|
||||
<p>
|
||||
<i>Postconditions:</i> <code>hours()</code> returns <code>h</code>. <code>minutes()</code>
|
||||
returns <code>m</code>. <code>seconds()</code> returns <code>s</code>.
|
||||
<code>subseconds()</code> returns <code>sub_s</code>. <code>mode()</code> returns
|
||||
<code>md</code>.
|
||||
</p>
|
||||
</blockquote>
|
||||
|
||||
<pre>
|
||||
constexpr std::chrono::hours time_of_day<std::chrono::duration<Rep, Period>>::hours() const noexcept;
|
||||
</pre>
|
||||
@@ -7053,58 +6934,6 @@ make_time(std::chrono::duration<Rep, Period> d) noexcept;
|
||||
</p>
|
||||
</blockquote>
|
||||
|
||||
<a name="_42"></a><pre>
|
||||
constexpr
|
||||
time_of_day<std::chrono::hours>
|
||||
make_time(std::chrono::hours h, unsigned md) noexcept;
|
||||
</pre>
|
||||
|
||||
<blockquote>
|
||||
<p>
|
||||
<i>Returns:</i> <code>time_of_day<std::chrono::hours>(h, md)</code>.
|
||||
</p>
|
||||
</blockquote>
|
||||
|
||||
<a name="_43"></a><pre>
|
||||
constexpr
|
||||
time_of_day<std::chrono::minutes>
|
||||
make_time(std::chrono::hours h, std::chrono::minutes m, unsigned md) noexcept;
|
||||
</pre>
|
||||
|
||||
<blockquote>
|
||||
<p>
|
||||
<i>Returns:</i> <code>time_of_day<std::chrono::minutes>(h, m, md)</code>.
|
||||
</p>
|
||||
</blockquote>
|
||||
|
||||
<a name="_44"></a><pre>
|
||||
constexpr
|
||||
time_of_day<std::chrono::seconds>
|
||||
make_time(std::chrono::hours h, std::chrono::minutes m, std::chrono::seconds s,
|
||||
unsigned md) noexcept;
|
||||
</pre>
|
||||
|
||||
<blockquote>
|
||||
<p>
|
||||
<i>Returns:</i> <code>time_of_day<std::chrono::seconds>(h, m, s, md)</code>.
|
||||
</p>
|
||||
</blockquote>
|
||||
|
||||
<a name="_45"></a><pre>
|
||||
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
|
||||
</pre>
|
||||
|
||||
<blockquote>
|
||||
<p>
|
||||
<i>Returns:</i> <code>time_of_day<std::chrono::duration<Rep, Period>>(h, m, s, sub_s, md)</code>.
|
||||
</p>
|
||||
</blockquote>
|
||||
|
||||
</blockquote>
|
||||
|
||||
<a name="_46"></a><pre>
|
||||
|
Reference in New Issue
Block a user