forked from HowardHinnant/date
Add clock_cast documentation
This commit is contained in:
497
tz.html
497
tz.html
@@ -26,7 +26,7 @@
|
|||||||
<br/>
|
<br/>
|
||||||
<br/>
|
<br/>
|
||||||
<a href="mailto:howard.hinnant@gmail.com">Howard E. Hinnant</a><br/>
|
<a href="mailto:howard.hinnant@gmail.com">Howard E. Hinnant</a><br/>
|
||||||
2017-10-28<br/>
|
2017-11-26<br/>
|
||||||
</address>
|
</address>
|
||||||
<hr/>
|
<hr/>
|
||||||
<h1 align=center>Time Zone Database Parser</h1>
|
<h1 align=center>Time Zone Database Parser</h1>
|
||||||
@@ -61,6 +61,7 @@
|
|||||||
<li><a href="#utc_clock"><code>utc_clock</code></a></li>
|
<li><a href="#utc_clock"><code>utc_clock</code></a></li>
|
||||||
<li><a href="#tai_clock"><code>tai_clock</code></a></li>
|
<li><a href="#tai_clock"><code>tai_clock</code></a></li>
|
||||||
<li><a href="#gps_clock"><code>gps_clock</code></a></li>
|
<li><a href="#gps_clock"><code>gps_clock</code></a></li>
|
||||||
|
<li><a href="#clock_cast"><code>clock_cast</code></a></li>
|
||||||
<li><a href="#leap"><code>leap</code></a></li>
|
<li><a href="#leap"><code>leap</code></a></li>
|
||||||
<li><a href="#link"><code>link</code></a></li>
|
<li><a href="#link"><code>link</code></a></li>
|
||||||
</ul>
|
</ul>
|
||||||
@@ -648,13 +649,13 @@ was in the air. This can be taken into account with the following code:
|
|||||||
int
|
int
|
||||||
main()
|
main()
|
||||||
{
|
{
|
||||||
using namespace std::chrono_literals;
|
using namespace std::chrono;
|
||||||
using namespace date;
|
using namespace date;
|
||||||
|
|
||||||
auto departure = make_zoned("America/New_York", local_days{dec/31/1978} + 12h + 1min);
|
auto departure = make_zoned("America/New_York", local_days{dec/31/1978} + 12h + 1min);
|
||||||
<b>auto departure_utc = to_utc_time(departure.get_sys_time());</b>
|
<b>auto departure_utc = clock_cast<utc_clock>(departure.get_sys_time());</b>
|
||||||
auto flight_length = 14h + 44min;
|
auto flight_length = 14h + 44min;
|
||||||
auto arrival = make_zoned("Asia/Tehran", <b>to_sys_time(departure_utc + flight_length)</b>);
|
auto arrival = make_zoned("Asia/Tehran", <b>clock_cast<system_clock>(departure_utc + flight_length)</b>);
|
||||||
|
|
||||||
std::cout << "departure NYC time: " << departure << '\n';
|
std::cout << "departure NYC time: " << departure << '\n';
|
||||||
std::cout << "flight time is " << make_time(flight_length) << '\n';
|
std::cout << "flight time is " << make_time(flight_length) << '\n';
|
||||||
@@ -2672,13 +2673,23 @@ make_zoned(const std::string& name, const sys_time<Duration>& st)
|
|||||||
class utc_clock
|
class utc_clock
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
using duration = std::chrono::system_clock::duration;
|
using rep = <i>a signed arithmetic type</i>;
|
||||||
using rep = duration::rep;
|
using period = ratio<<i>unspecified</i>, <i>unspecified</i>>;
|
||||||
using period = duration::period;
|
using duration = std::chrono::duration<rep, period>;
|
||||||
using time_point = std::chrono::time_point<utc_clock>;
|
using time_point = std::chrono::time_point<utc_clock>;
|
||||||
static constexpr bool is_steady = false;
|
static constexpr bool is_steady = <i>unspecified</i>;
|
||||||
|
|
||||||
static time_point now() noexcept;
|
static time_point now() noexcept;
|
||||||
|
|
||||||
|
template <class Duration>
|
||||||
|
static
|
||||||
|
sys_time<std::common_type_t<Duration, std::chrono::seconds>>
|
||||||
|
to_sys(const utc_time<Duration>&);
|
||||||
|
|
||||||
|
template <class Duration>
|
||||||
|
static
|
||||||
|
utc_time<std::common_type_t<Duration, std::chrono::seconds>>
|
||||||
|
from_sys(const sys_time<Duration>&);
|
||||||
};
|
};
|
||||||
|
|
||||||
template <class Duration>
|
template <class Duration>
|
||||||
@@ -2708,19 +2719,21 @@ static utc_clock::time_point utc_clock::now() noexcept;
|
|||||||
</pre>
|
</pre>
|
||||||
<blockquote>
|
<blockquote>
|
||||||
<p>
|
<p>
|
||||||
<i>Returns:</i> <code>to_utc_time(system_clock::now())</code>.
|
<i>Returns:</i> <code>from_sys(system_clock::now())</code>, or a more accurate
|
||||||
|
value of <code>utc_time</code>.
|
||||||
</p>
|
</p>
|
||||||
</blockquote>
|
</blockquote>
|
||||||
|
|
||||||
<pre>
|
<pre>
|
||||||
template <class Duration>
|
template <typename Duration>
|
||||||
|
static
|
||||||
sys_time<std::common_type_t<Duration, std::chrono::seconds>>
|
sys_time<std::common_type_t<Duration, std::chrono::seconds>>
|
||||||
to_sys_time(utc_time<Duration> u)
|
utc_clock::to_sys(const utc_time<Duration>& u);
|
||||||
</pre>
|
</pre>
|
||||||
<blockquote>
|
<blockquote>
|
||||||
<p>
|
<p>
|
||||||
<i>Returns:</i> A <code>sys_time</code> <code>t</code>, such that
|
<i>Returns:</i> A <code>sys_time</code> <code>t</code>, such that
|
||||||
<code>to_utc_time(t) == u</code> if such a mapping exists. Otherwise <code>u</code>
|
<code>from_sys(t) == u</code> if such a mapping exists. Otherwise <code>u</code>
|
||||||
represents a <code>time_point</code> during a leap second insertion and the last
|
represents a <code>time_point</code> during a leap second insertion and the last
|
||||||
representable value of <code>sys_time</code> prior to the insertion of the leap
|
representable value of <code>sys_time</code> prior to the insertion of the leap
|
||||||
second is returned.
|
second is returned.
|
||||||
@@ -2728,9 +2741,10 @@ second is returned.
|
|||||||
</blockquote>
|
</blockquote>
|
||||||
|
|
||||||
<pre>
|
<pre>
|
||||||
template <class Duration>
|
template <typename Duration>
|
||||||
|
static
|
||||||
utc_time<std::common_type_t<Duration, std::chrono::seconds>>
|
utc_time<std::common_type_t<Duration, std::chrono::seconds>>
|
||||||
to_utc_time(sys_time<Duration> t)
|
utc_clock::from_sys(const sys_time<Duration>& t);
|
||||||
</pre>
|
</pre>
|
||||||
<blockquote>
|
<blockquote>
|
||||||
<p>
|
<p>
|
||||||
@@ -2742,34 +2756,6 @@ second insertion), then the conversion counts that leap second as inserted.
|
|||||||
</p>
|
</p>
|
||||||
</blockquote>
|
</blockquote>
|
||||||
|
|
||||||
<pre>
|
|
||||||
template <class Duration>
|
|
||||||
utc_time<std::common_type_t<Duration, std::chrono::seconds>>
|
|
||||||
to_utc_time(tai_time<Duration> t) noexcept
|
|
||||||
</pre>
|
|
||||||
<blockquote>
|
|
||||||
<p>
|
|
||||||
<i>Returns:</i> <code>utc_time<common_type_t<Duration, seconds>>{t.time_since_epoch()} - 378691210s</code>
|
|
||||||
</p>
|
|
||||||
<p>
|
|
||||||
<i>Note:</i> <code>378691210s == sys_days{1970y/jan/1} - sys_days{1958y/jan/1} + 10s</code>
|
|
||||||
</p>
|
|
||||||
</blockquote>
|
|
||||||
|
|
||||||
<pre>
|
|
||||||
template <class Duration>
|
|
||||||
utc_time<std::common_type_t<Duration, std::chrono::seconds>>
|
|
||||||
to_utc_time(gps_time<Duration> t) noexcept
|
|
||||||
</pre>
|
|
||||||
<blockquote>
|
|
||||||
<p>
|
|
||||||
<i>Returns:</i> <code>utc_time<common_type_t<Duration, seconds>>{t.time_since_epoch()} + 315964809s</code>
|
|
||||||
</p>
|
|
||||||
<p>
|
|
||||||
<i>Note:</i> <code>315964809s == sys_days{1980y/jan/sun[1]} - sys_days{1970y/jan/1} + 9s</code>
|
|
||||||
</p>
|
|
||||||
</blockquote>
|
|
||||||
|
|
||||||
<pre>
|
<pre>
|
||||||
template <class CharT, class Traits, class Duration>
|
template <class CharT, class Traits, class Duration>
|
||||||
std::basic_ostream<class CharT, class Traits>&
|
std::basic_ostream<class CharT, class Traits>&
|
||||||
@@ -2838,13 +2824,23 @@ If <code>abbrev</code> is not equal to <code>nullptr</code>, the information par
|
|||||||
class tai_clock
|
class tai_clock
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
using duration = std::chrono::system_clock::duration;
|
using rep = <i>a signed arithmetic type</i>;
|
||||||
using rep = duration::rep;
|
using period = ratio<<i>unspecified</i>, <i>unspecified</i>>;
|
||||||
using period = duration::period;
|
using duration = std::chrono::duration<rep, period>;
|
||||||
using time_point = std::chrono::time_point<tai_clock>;
|
using time_point = std::chrono::time_point<tai_clock>;
|
||||||
static constexpr bool is_steady = false;
|
static constexpr bool is_steady = <i>unspecified</i>;
|
||||||
|
|
||||||
static time_point now() noexcept;
|
static time_point now() noexcept;
|
||||||
|
|
||||||
|
template <class Duration>
|
||||||
|
static
|
||||||
|
utc_time<std::common_type_t<Duration, std::chrono::seconds>>
|
||||||
|
to_utc(const std::chrono::time_point<tai_clock, Duration>&) noexcept;
|
||||||
|
|
||||||
|
template <class Duration>
|
||||||
|
static
|
||||||
|
tai_time<std::common_type<Duration, std::chrono::seconds>>
|
||||||
|
from_utc(const utc_time<Duration>&) noexcept;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <class Duration>
|
template <class Duration>
|
||||||
@@ -2872,40 +2868,20 @@ static tai_clock::time_point tai_clock::now() noexcept;
|
|||||||
</pre>
|
</pre>
|
||||||
<blockquote>
|
<blockquote>
|
||||||
<p>
|
<p>
|
||||||
<i>Returns:</i> <code>to_tai_time(system_clock::now())</code>.
|
<i>Returns:</i> <code>from_utc(utc_clock::now())</code>, or a more accurate
|
||||||
|
value of <code>tai_time</code>.
|
||||||
</p>
|
</p>
|
||||||
</blockquote>
|
</blockquote>
|
||||||
|
|
||||||
<pre>
|
<pre>
|
||||||
template <class Duration>
|
template <class Duration>
|
||||||
sys_time<typename std::common_type<Duration, std::chrono::seconds>::type>
|
static
|
||||||
to_sys_time(tai_time<Duration> t)
|
utc_time<std::common_type_t<Duration, std::chrono::seconds>>
|
||||||
|
to_utc(const std::chrono::time_point<tai_clock, Duration>& t) noexcept;
|
||||||
</pre>
|
</pre>
|
||||||
<blockquote>
|
<blockquote>
|
||||||
<p>
|
<p>
|
||||||
<i>Equivalent to:</i> <code>return to_sys_time(to_utc_time(t))</code>.
|
<i>Returns:</i> <code>utc_time<common_type_t<Duration, seconds>>{t.time_since_epoch()} - 378691210s</code>
|
||||||
</p>
|
|
||||||
</blockquote>
|
|
||||||
|
|
||||||
<pre>
|
|
||||||
template <class Duration>
|
|
||||||
tai_time<typename std::common_type<Duration, std::chrono::seconds>::type>
|
|
||||||
to_tai_time(sys_time<Duration> t)
|
|
||||||
</pre>
|
|
||||||
<blockquote>
|
|
||||||
<p>
|
|
||||||
<i>Equivalent to:</i> <code>return to_tai_time(to_utc_time(t))</code>.
|
|
||||||
</p>
|
|
||||||
</blockquote>
|
|
||||||
|
|
||||||
<pre>
|
|
||||||
template <class Duration>
|
|
||||||
tai_time<std::common_type_t<Duration, std::chrono::seconds>>
|
|
||||||
to_tai_time(utc_time<Duration> u) noexcept
|
|
||||||
</pre>
|
|
||||||
<blockquote>
|
|
||||||
<p>
|
|
||||||
<i>Returns:</i> <code>tai_time<common_type_t<Duration, seconds>>{t.time_since_epoch()} + 378691210s</code>
|
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
<i>Note:</i> <code>378691210s == sys_days{1970y/jan/1} - sys_days{1958y/jan/1} + 10s</code>
|
<i>Note:</i> <code>378691210s == sys_days{1970y/jan/1} - sys_days{1958y/jan/1} + 10s</code>
|
||||||
@@ -2914,15 +2890,16 @@ to_tai_time(utc_time<Duration> u) noexcept
|
|||||||
|
|
||||||
<pre>
|
<pre>
|
||||||
template <class Duration>
|
template <class Duration>
|
||||||
tai_time<typename std::common_type<Duration, std::chrono::seconds>::type>
|
static
|
||||||
to_tai_time(gps_time<Duration> t) noexcept
|
tai_time<std::common_type<Duration, std::chrono::seconds>>
|
||||||
|
tai_clock::from_utc(const utc_time<Duration>& t) noexcept;
|
||||||
</pre>
|
</pre>
|
||||||
<blockquote>
|
<blockquote>
|
||||||
<p>
|
<p>
|
||||||
<i>Returns:</i> <code>tai_time<common_type_t<Duration, seconds>>{t.time_since_epoch()} + 694656019s</code>
|
<i>Returns:</i> <code>tai_time<common_type_t<Duration, seconds>>{t.time_since_epoch()} + 378691210s</code>
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
<i>Note:</i> <code>694656019s == sys_days{1980y/jan/sun[1]} - sys_days{1958y/jan/1} + 19s</code>
|
<i>Note:</i> <code>378691210s == sys_days{1970y/jan/1} - sys_days{1958y/jan/1} + 10s</code>
|
||||||
</p>
|
</p>
|
||||||
</blockquote>
|
</blockquote>
|
||||||
|
|
||||||
@@ -2992,13 +2969,23 @@ If <code>abbrev</code> is not equal to <code>nullptr</code>, the information par
|
|||||||
class gps_clock
|
class gps_clock
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
using duration = std::chrono::system_clock::duration;
|
using rep = <i>a signed arithmetic type</i>;
|
||||||
using rep = duration::rep;
|
using period = ratio<<i>unspecified</i>, <i>unspecified</i>>;
|
||||||
using period = duration::period;
|
using duration = std::chrono::duration<rep, period>;
|
||||||
using time_point = std::chrono::time_point<gps_clock>;
|
using time_point = std::chrono::time_point<gps_clock>;
|
||||||
static constexpr bool is_steady = false;
|
static constexpr bool is_steady = <i>unspecified</i>;
|
||||||
|
|
||||||
static time_point now() noexcept;
|
static time_point now() noexcept;
|
||||||
|
|
||||||
|
template <class Duration>
|
||||||
|
static
|
||||||
|
utc_time<std::common_type_t<Duration, std::chrono::seconds>>
|
||||||
|
to_utc(const gps_time<Duration>&) noexcept;
|
||||||
|
|
||||||
|
template <class Duration>
|
||||||
|
static
|
||||||
|
gps_time<std::common_type_t<Duration, std::chrono::seconds>>
|
||||||
|
from_utc(const utc_time<Duration>&) noexcept;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <class Duration>
|
template <class Duration>
|
||||||
@@ -3025,40 +3012,20 @@ static gps_clock::time_point gps_clock::now() noexcept;
|
|||||||
</pre>
|
</pre>
|
||||||
<blockquote>
|
<blockquote>
|
||||||
<p>
|
<p>
|
||||||
<i>Returns:</i> <code>to_gps_time(system_clock::now())</code>.
|
<i>Returns:</i> <code>from_utc(utc_clock::now())</code>, or a more accurate
|
||||||
|
value of <code>gps_time</code>.
|
||||||
</p>
|
</p>
|
||||||
</blockquote>
|
</blockquote>
|
||||||
|
|
||||||
<pre>
|
<pre>
|
||||||
template <class Duration>
|
template <class Duration>
|
||||||
sys_time<typename std::common_type<Duration, std::chrono::seconds>::type>
|
static
|
||||||
to_sys_time(gps_time<Duration> t)
|
utc_time<std::common_type_t<Duration, std::chrono::seconds>>
|
||||||
|
gps_clock::to_utc(const gps_time<Duration>& t) noexcept;
|
||||||
</pre>
|
</pre>
|
||||||
<blockquote>
|
<blockquote>
|
||||||
<p>
|
<p>
|
||||||
<i>Equivalent to:</i> <code>return to_sys_time(to_utc_time(t))</code>.
|
<i>Returns:</i> <code>gps_time<common_type_t<Duration, seconds>>{t.time_since_epoch()} + 315964809s</code>
|
||||||
</p>
|
|
||||||
</blockquote>
|
|
||||||
|
|
||||||
<pre>
|
|
||||||
template <class Duration>
|
|
||||||
gps_time<typename std::common_type<Duration, std::chrono::seconds>::type>
|
|
||||||
to_gps_time(sys_time<Duration> t)
|
|
||||||
</pre>
|
|
||||||
<blockquote>
|
|
||||||
<p>
|
|
||||||
<i>Equivalent to:</i> <code>return to_gps_time(to_utc_time(t))</code>.
|
|
||||||
</p>
|
|
||||||
</blockquote>
|
|
||||||
|
|
||||||
<pre>
|
|
||||||
template <class Duration>
|
|
||||||
gps_time<std::common_type_t<Duration, std::chrono::seconds>>
|
|
||||||
to_gps_time(utc_time<Duration> u) noexcept
|
|
||||||
</pre>
|
|
||||||
<blockquote>
|
|
||||||
<p>
|
|
||||||
<i>Returns:</i> <code>gps_time<common_type_t<Duration, seconds>>{t.time_since_epoch()} - 315964809s</code>
|
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
<i>Note:</i> <code>315964809s == sys_days{1980y/jan/sun[1]} - sys_days{1970y/jan/1} + 9s</code>
|
<i>Note:</i> <code>315964809s == sys_days{1980y/jan/sun[1]} - sys_days{1970y/jan/1} + 9s</code>
|
||||||
@@ -3067,15 +3034,16 @@ to_gps_time(utc_time<Duration> u) noexcept
|
|||||||
|
|
||||||
<pre>
|
<pre>
|
||||||
template <class Duration>
|
template <class Duration>
|
||||||
gps_time<typename std::common_type<Duration, std::chrono::seconds>::type>
|
static
|
||||||
to_gps_time(tai_time<Duration> t) noexcept
|
gps_time<std::common_type_t<Duration, std::chrono::seconds>>
|
||||||
|
gps_clock::from_utc(const utc_time<Duration>& t) noexcept;
|
||||||
</pre>
|
</pre>
|
||||||
<blockquote>
|
<blockquote>
|
||||||
<p>
|
<p>
|
||||||
<i>Returns:</i> <code>gps_time<common_type_t<Duration, seconds>>{t.time_since_epoch()} - 694656019s</code>
|
<i>Returns:</i> <code>gps_time<common_type_t<Duration, seconds>>{t.time_since_epoch()} - 315964809s</code>
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
<i>Note:</i> <code>694656019s == sys_days{1980y/jan/sun[1]} - sys_days{1958y/jan/1} + 19s</code>
|
<i>Note:</i> <code>315964809s == sys_days{1980y/jan/sun[1]} - sys_days{1970y/jan/1} + 9s</code>
|
||||||
</p>
|
</p>
|
||||||
</blockquote>
|
</blockquote>
|
||||||
|
|
||||||
@@ -3156,14 +3124,14 @@ int
|
|||||||
main()
|
main()
|
||||||
{
|
{
|
||||||
using namespace date;
|
using namespace date;
|
||||||
using namespace std::chrono_literals;
|
using namespace std::chrono;
|
||||||
auto start = to_utc_time(sys_days{2015_y/jul/1} - 500ms);
|
auto start = clock_cast<utc_clock>(sys_days{2015_y/jul/1} - 500ms);
|
||||||
auto end = start + 2s;
|
auto end = start + 2s;
|
||||||
for (auto utc = start; utc < end; utc += 100ms)
|
for (auto utc = start; utc < end; utc += 100ms)
|
||||||
{
|
{
|
||||||
auto sys = to_sys_time(utc);
|
auto sys = clock_cast<system_clock>(utc);
|
||||||
auto tai = to_tai_time(utc);
|
auto tai = clock_cast<tai_clock>(utc);
|
||||||
auto gps = to_gps_time(utc);
|
auto gps = clock_cast<gps_clock>(utc);
|
||||||
std::cout << format("%F %T SYS == ", sys)
|
std::cout << format("%F %T SYS == ", sys)
|
||||||
<< format("%F %T %Z == ", utc)
|
<< format("%F %T %Z == ", utc)
|
||||||
<< format("%F %T %Z == ", tai)
|
<< format("%F %T %Z == ", tai)
|
||||||
@@ -3203,6 +3171,303 @@ Output:
|
|||||||
</p>
|
</p>
|
||||||
|
|
||||||
</blockquote>
|
</blockquote>
|
||||||
|
|
||||||
|
<a name="clock_cast"></a><h3><code>clock_cast</code></h3>
|
||||||
|
<blockquote>
|
||||||
|
<pre>
|
||||||
|
template <class DestClock, class SourceClock>
|
||||||
|
struct clock_time_conversion
|
||||||
|
{};
|
||||||
|
</pre>
|
||||||
|
<p>
|
||||||
|
<code>clock_time_conversion</code> serves as trait which can be used to specify how to
|
||||||
|
convert <code>time_point<SourceClock, Duration></code> to
|
||||||
|
<code>time_point<DestClock, Duration></code> via a specialization:
|
||||||
|
<code>clock_time_conversion<DestClock, SourceClock></code>. A specialization of
|
||||||
|
<code>clock_time_conversion<DestClock, SourceClock></code> shall provide a
|
||||||
|
<code>const</code>-qualified <code>operator()</code> that takes a parameter of type
|
||||||
|
<code>time_point<SourceClock, Duration></code> and returns a
|
||||||
|
<code>time_point<DestClock, <i>some duration</i>></code> representing an equivalent
|
||||||
|
point in time. A program may specialize <code>clock_time_conversion</code> if at least
|
||||||
|
one of the template parameters is user-defined clock type.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
Several specializations are provided by the implementation:
|
||||||
|
</p>
|
||||||
|
<pre>
|
||||||
|
// Identity
|
||||||
|
|
||||||
|
template <typename Clock>
|
||||||
|
struct clock_time_conversion<Clock, Clock>
|
||||||
|
{
|
||||||
|
template <class Duration>
|
||||||
|
std::chrono::time_point<Clock, Duration>
|
||||||
|
operator()(const std::chrono::time_point<Clock, Duration>& t) const;
|
||||||
|
};
|
||||||
|
|
||||||
|
template <class Duration>
|
||||||
|
std::chrono::time_point<Clock, Duration>
|
||||||
|
operator()(const std::chrono::time_point<Clock, Duration>& t) const;
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<blockquote>
|
||||||
|
<p>
|
||||||
|
<i>Returns:</i> <code>t</code>.
|
||||||
|
</p>
|
||||||
|
</blockquote>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
template <>
|
||||||
|
struct clock_time_conversion<std::chrono::system_clock, std::chrono::system_clock>
|
||||||
|
{
|
||||||
|
template <class Duration>
|
||||||
|
sys_time<Duration>
|
||||||
|
operator()(const sys_time<Duration>& t) const;
|
||||||
|
};
|
||||||
|
|
||||||
|
template <class Duration>
|
||||||
|
sys_time<Duration>
|
||||||
|
operator()(const sys_time<Duration>& t) const;
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<blockquote>
|
||||||
|
<p>
|
||||||
|
<i>Returns:</i> <code>t</code>.
|
||||||
|
</p>
|
||||||
|
</blockquote>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
template <>
|
||||||
|
struct clock_time_conversion<utc_clock, utc_clock>
|
||||||
|
{
|
||||||
|
template <class Duration>
|
||||||
|
utc_time<Duration>
|
||||||
|
operator()(const utc_time<Duration>& t) const;
|
||||||
|
};
|
||||||
|
|
||||||
|
template <class Duration>
|
||||||
|
utc_time<Duration>
|
||||||
|
operator()(const utc_time<Duration>& t) const;
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<blockquote>
|
||||||
|
<p>
|
||||||
|
<i>Returns:</i> <code>t</code>.
|
||||||
|
</p>
|
||||||
|
</blockquote>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
// system_clock <-> utc_clock
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
template <>
|
||||||
|
struct clock_time_conversion<utc_clock, std::chrono::system_clock>
|
||||||
|
{
|
||||||
|
template <class Duration>
|
||||||
|
utc_time<std::common_type_t<Duration, std::chrono::seconds>>
|
||||||
|
operator()(const sys_time<Duration>& t) const;
|
||||||
|
};
|
||||||
|
|
||||||
|
template <class Duration>
|
||||||
|
utc_time<std::common_type_t<Duration, std::chrono::seconds>>
|
||||||
|
operator()(const sys_time<Duration>& t) const;
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<blockquote>
|
||||||
|
<p>
|
||||||
|
<i>Returns:</i> <code>utc_clock::from_sys(t)</code>.
|
||||||
|
</p>
|
||||||
|
</blockquote>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
template <>
|
||||||
|
struct clock_time_conversion<std::chrono::system_clock, utc_clock>
|
||||||
|
{
|
||||||
|
template <class Duration>
|
||||||
|
sys_time<std::common_type_t<Duration, std::chrono::seconds>>
|
||||||
|
operator()(const utc_time<Duration>& t) const;
|
||||||
|
};
|
||||||
|
|
||||||
|
template <class Duration>
|
||||||
|
sys_time<std::common_type_t<Duration, std::chrono::seconds>>
|
||||||
|
operator()(const utc_time<Duration>& t) const;
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<blockquote>
|
||||||
|
<p>
|
||||||
|
<i>Returns:</i> <code>utc_clock::to_sys(t)</code>.
|
||||||
|
</p>
|
||||||
|
</blockquote>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
// Clock <-> system_clock
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
template <class SourceClock>
|
||||||
|
struct clock_time_conversion<std::chrono::system_clock, SourceClock>
|
||||||
|
{
|
||||||
|
template <class Duration>
|
||||||
|
auto
|
||||||
|
operator()(const std::chrono::time_point<SourceClock, Duration>& t) const
|
||||||
|
-> decltype(SourceClock::to_sys(t));
|
||||||
|
};
|
||||||
|
|
||||||
|
template <class Duration>
|
||||||
|
auto
|
||||||
|
operator()(const std::chrono::time_point<SourceClock, Duration>& t) const
|
||||||
|
-> decltype(SourceClock::to_sys(t));
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<blockquote>
|
||||||
|
<p>
|
||||||
|
<i>Remarks:</i> This function does not participate in overload resolution unless
|
||||||
|
<code>SourceClock::to_sys(t)</code> is well formed. If
|
||||||
|
<code>SourceClock::to_sys(t)</code> does not return
|
||||||
|
<code>sys_time<<i>some duration</i>></code> the program is ill-formed.
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
<i>Returns:</i> <code>SourceClock::to_sys(t)</code>.
|
||||||
|
</p>
|
||||||
|
</blockquote>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
template <class DestClock>
|
||||||
|
struct clock_time_conversion<DestClock, std::chrono::system_clock>
|
||||||
|
{
|
||||||
|
template <class Duration>
|
||||||
|
auto
|
||||||
|
operator()(const sys_time<Duration>& t) const
|
||||||
|
-> decltype(DestClock::from_sys(t));
|
||||||
|
};
|
||||||
|
|
||||||
|
template <class Duration>
|
||||||
|
auto
|
||||||
|
operator()(const sys_time<Duration>& t) const
|
||||||
|
-> decltype(DestClock::from_sys(t));
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<blockquote>
|
||||||
|
<p>
|
||||||
|
<i>Remarks:</i> This function does not participate in overload resolution unless
|
||||||
|
<code>DestClock::from_sys(t)</code> is well formed. If
|
||||||
|
<code>DestClock::from_sys(t)</code> does not return
|
||||||
|
<code>time_point<DestClock, <i>some duration</i>></code> the program is ill-formed.
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
<i>Returns:</i> <code>DestClock::from_sys(t)</code>.
|
||||||
|
</p>
|
||||||
|
</blockquote>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
// Clock <-> utc_clock
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
template <class SourceClock>
|
||||||
|
struct clock_time_conversion<utc_clock, SourceClock>
|
||||||
|
{
|
||||||
|
template <class Duration>
|
||||||
|
auto
|
||||||
|
operator()(const std::chrono::time_point<SourceClock, Duration>& t) const
|
||||||
|
-> decltype(SourceClock::to_utc(t));
|
||||||
|
};
|
||||||
|
|
||||||
|
template <class Duration>
|
||||||
|
auto
|
||||||
|
operator()(const std::chrono::time_point<SourceClock, Duration>& t) const
|
||||||
|
-> decltype(SourceClock::to_utc(t));
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<blockquote>
|
||||||
|
<p>
|
||||||
|
<i>Remarks:</i> This function does not participate in overload resolution unless
|
||||||
|
<code>SourceClock::to_utc(t)</code> is well formed. If
|
||||||
|
<code>SourceClock::to_utc(t)</code> does not return
|
||||||
|
<code>utc_time<<i>some duration</i>></code> the program is ill-formed.
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
<i>Returns:</i> <code>SourceClock::to_utc(t)</code>.
|
||||||
|
</p>
|
||||||
|
</blockquote>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
template <class DestClock>
|
||||||
|
struct clock_time_conversion<DestClock, utc_clock>
|
||||||
|
{
|
||||||
|
template <class Duration>
|
||||||
|
auto
|
||||||
|
operator()(const utc_time<Duration>& t) const
|
||||||
|
-> decltype(DestClock::from_utc(t));
|
||||||
|
};
|
||||||
|
|
||||||
|
template <class Duration>
|
||||||
|
auto
|
||||||
|
operator()(const utc_time<Duration>& t) const
|
||||||
|
-> decltype(DestClock::from_utc(t));
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<blockquote>
|
||||||
|
<p>
|
||||||
|
<i>Remarks:</i> This function does not participate in overload resolution unless
|
||||||
|
<code>DestClock::from_utc(t)</code> is well formed. If
|
||||||
|
<code>DestClock::from_utc(t)</code> does not return
|
||||||
|
<code>time_point<DestClock, <i>some duration</i>></code> the program is ill-formed.
|
||||||
|
<code></code>.
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
<i>Returns:</i> <code>DestClock::from_utc(t)</code>.
|
||||||
|
</p>
|
||||||
|
</blockquote>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
// clock_cast
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
template <class DestClock, class SourceClock, class Duration>
|
||||||
|
std::chrono::time_point<DestClock, <i>some duration</i>>
|
||||||
|
clock_cast(const std::chrono::time_point<SourceClock, Duration>& t);
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<blockquote>
|
||||||
|
<p>
|
||||||
|
<i>Remarks:</i> This function does not participate in overload resolution unless
|
||||||
|
at least one of the following expressions are well formed:
|
||||||
|
</p>
|
||||||
|
<ol>
|
||||||
|
<li><code>clock_time_conversion<DestClock, SourceClock>{}(t)</code></li>
|
||||||
|
<li> Exactly one of:
|
||||||
|
<ul>
|
||||||
|
<li><code>clock_time_conversion<DestClock, system_clock>{}(
|
||||||
|
clock_time_conversion<system_clock, SourceClock>{}(t))</code>
|
||||||
|
</li>
|
||||||
|
<li><code>clock_time_conversion<DestClock, utc_clock>{}(
|
||||||
|
clock_time_conversion<utc_clock, SourceClock>{}(t))</code></li>
|
||||||
|
</ul></li>
|
||||||
|
<li> Exactly one of:
|
||||||
|
<ul>
|
||||||
|
<li><code>clock_time_conversion<DestClock, utc_clock>{}(
|
||||||
|
clock_time_conversion<utc_clock, system_clock>{}(
|
||||||
|
clock_time_conversion<system_clock, SourceClock>{}(t)))</code></li>
|
||||||
|
<li><code>clock_time_conversion<DestClock, system_clock>{}(
|
||||||
|
clock_time_conversion<system_clock, utc_clock>{}(
|
||||||
|
clock_time_conversion<utc_clock, SourceClock>{}(t)))</code></li>
|
||||||
|
</ul></li>
|
||||||
|
</ol>
|
||||||
|
<p>
|
||||||
|
<i>Returns:</i> The first expression in the above list that is well-formed. If item 1 is
|
||||||
|
not well-formed and both expressions in item 2 are well-formed, the
|
||||||
|
<code>clock_cast</code> is ambiguous (ill-formed). If items 1 and 2 are not well-formed
|
||||||
|
and both expressions in item 3 are well-formed, the <code>clock_cast</code> is ambiguous
|
||||||
|
(ill-formed).
|
||||||
|
</p>
|
||||||
|
</blockquote>
|
||||||
|
|
||||||
|
</blockquote>
|
||||||
|
|
||||||
<a name="leap"></a><h3><code>leap</code></h3>
|
<a name="leap"></a><h3><code>leap</code></h3>
|
||||||
<blockquote>
|
<blockquote>
|
||||||
<pre>
|
<pre>
|
||||||
@@ -3556,7 +3821,7 @@ influencing the date.h library.
|
|||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
And I would also especially like to thank contributors to this library: gmcode,
|
And I would also especially like to thank contributors to this library: gmcode,
|
||||||
Ivan Pizhenko, tomy2105 and Ville Voutilainen.
|
Ivan Pizhenko, Tomasz Kamiński, tomy2105 and Ville Voutilainen.
|
||||||
</p>
|
</p>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
Reference in New Issue
Block a user