forked from HowardHinnant/date
Document custom time zone capabilities
This commit is contained in:
651
tz.html
651
tz.html
@@ -26,7 +26,7 @@
|
||||
<br/>
|
||||
<br/>
|
||||
<a href="mailto:howard.hinnant@gmail.com">Howard E. Hinnant</a><br/>
|
||||
2017-07-03<br/>
|
||||
2017-09-16<br/>
|
||||
</address>
|
||||
<hr/>
|
||||
<h1 align=center>Time Zone Database Parser</h1>
|
||||
@@ -55,6 +55,7 @@
|
||||
<li><a href="#sys_info"><code>sys_info</code></a></li>
|
||||
<li><a href="#local_info"><code>local_info</code></a></li>
|
||||
<li><a href="#time_zone"><code>time_zone</code></a></li>
|
||||
<li><a href="#zoned_traits"><code>zoned_traits</code></a></li>
|
||||
<li><a href="#zoned_time"><code>zoned_time</code></a></li>
|
||||
<li><a href="#make_zoned"><code>make_zoned</code></a></li>
|
||||
<li><a href="#utc_clock"><code>utc_clock</code></a></li>
|
||||
@@ -558,6 +559,8 @@ formatting strings.
|
||||
|
||||
<a name="Examples"><h3>Examples</h3>
|
||||
|
||||
<h4>Flight time</h4>
|
||||
|
||||
<p>
|
||||
Interesting things can happen to the apparent time when you travel across the globe
|
||||
at high speeds. So departure and arrival times of airplane flights make for good
|
||||
@@ -674,6 +677,8 @@ flight time is 14:44
|
||||
arrival Tehran time: 1979-01-01 11:<b>14:59</b> IRST
|
||||
</pre></blockquote>
|
||||
|
||||
<h4>Format conversion</h4>
|
||||
|
||||
<p>
|
||||
A common task in dealing with dates and times is converting from one string format
|
||||
to another. This library is extremely flexible in handling this task. As an
|
||||
@@ -755,6 +760,247 @@ for extension formatting flags to indicate fractional seconds. <code>%S</code>
|
||||
and <code>%T</code> just work.
|
||||
</p>
|
||||
|
||||
<h4>Custom time zone</h4>
|
||||
|
||||
<p>
|
||||
Occasionally the IANA time zone database doesn't quite do <i>everything</i> you want.
|
||||
This library allows you to use <code>zoned_time</code> with a time zone and/or pointer
|
||||
to time zone of your own making. One common example is the need to have a time zone
|
||||
that has a fixed offset from UTC, but for which that offset isn't known until run time.
|
||||
Below is an example which supplies a custom time zone called <code>OffsetZone</code>
|
||||
which can hold a UTC offset with minutes precision.
|
||||
</p>
|
||||
|
||||
<blockquote><pre>
|
||||
#include "tz.h"
|
||||
#include <iostream>
|
||||
#include <type_traits>
|
||||
|
||||
class OffsetZone
|
||||
{
|
||||
std::chrono::minutes offset_;
|
||||
|
||||
public:
|
||||
explicit OffsetZone(std::chrono::minutes offset)
|
||||
: offset_{offset}
|
||||
{}
|
||||
|
||||
template <class Duration>
|
||||
auto
|
||||
to_local(date::sys_time<Duration> tp) const
|
||||
{
|
||||
using namespace date;
|
||||
using namespace std;
|
||||
using namespace std::chrono;
|
||||
using LT = local_time<common_type_t<Duration, minutes>>;
|
||||
return LT{(tp + offset_).time_since_epoch()};
|
||||
}
|
||||
|
||||
template <class Duration>
|
||||
auto
|
||||
to_sys(date::local_time<Duration> tp) const
|
||||
{
|
||||
using namespace date;
|
||||
using namespace std;
|
||||
using namespace std::chrono;
|
||||
using ST = sys_time<common_type_t<Duration, minutes>>;
|
||||
return ST{(tp - offset_).time_since_epoch()};
|
||||
}
|
||||
};
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
using namespace date;
|
||||
using namespace std::chrono;
|
||||
OffsetZone p3_45{3h + 45min};
|
||||
zoned_time<milliseconds, OffsetZone*> zt{&p3_45, floor<milliseconds>(system_clock::now())};
|
||||
std::cout << zt.get_sys_time() << '\n';
|
||||
std::cout << zt.get_local_time() << '\n';
|
||||
}
|
||||
</pre></blockquote>
|
||||
|
||||
<p>
|
||||
This just output for me:
|
||||
</p>
|
||||
|
||||
<blockquote><pre>
|
||||
2017-09-16 17:34:47.560
|
||||
2017-09-16 21:19:47.560
|
||||
</pre></blockquote>
|
||||
|
||||
<p>
|
||||
The second template parameter to <code>zoned_time</code> is a pointer to a time zone.
|
||||
This example simply creates a <code>OffsetZone</code> with a UTC offset of 3:45, and
|
||||
constructs a <code>OffsetZone</code> which points to that custom time zone and
|
||||
supplies the current time to the desired precision (whatever that may be).
|
||||
</p>
|
||||
|
||||
<p>
|
||||
You don't have to use a built-in pointer to your time zone. You could just as easily use
|
||||
<code>unique_ptr</code>, <code>shared_ptr</code>, or whatever smart pointer is right for
|
||||
your application. And in C++17, you won't need to supply the template parameters for
|
||||
<code>zoned_time</code> (though you still can if you want to). That is, the construction
|
||||
of <code>zt</code> above could be simplified down to just this:
|
||||
</p>
|
||||
|
||||
<blockquote><pre>
|
||||
zoned_time zt{&p3_45, floor<milliseconds>(system_clock::now())};
|
||||
</pre></blockquote>
|
||||
|
||||
<p>
|
||||
One can <i>even</i> have <code>OffsetZone</code> serve as its <i>own</i> smart pointer by
|
||||
giving it a member <code>operator->()</code> that returns itself:
|
||||
</p>
|
||||
|
||||
<blockquote><pre>
|
||||
const OffsetZone* operator->() const {return this;}
|
||||
</pre></blockquote>
|
||||
|
||||
<p>
|
||||
This allows you to embed the <code>OffsetZone</code> <i>directly</i> into the
|
||||
<code>zoned_time</code> instead of pointing to an externally held <code>OffsetZone</code>:
|
||||
</p>
|
||||
|
||||
<blockquote><pre>
|
||||
zoned_time<milliseconds, OffsetZone> zt{OffsetZone{3h + 45min}, floor<milliseconds>(system_clock::now())};
|
||||
</pre></blockquote>
|
||||
|
||||
<p>
|
||||
As it stands, <code>zoned<Duration, OffsetZone></code> can't be streamed with
|
||||
<code>operator<<</code> or formatted with <code>format</code>. But that can be
|
||||
fixed too: Just give <code>OffsetZone</code> a member <code>get_info</code> which
|
||||
takes a <code>sys_time</code> and returns a
|
||||
<a href="#sys_info"><code>sys_info</code></a>:
|
||||
</p>
|
||||
|
||||
<blockquote><pre>
|
||||
template <class Duration>
|
||||
date::sys_info
|
||||
get_info(date::sys_time<Duration>) const
|
||||
{
|
||||
using namespace date;
|
||||
using namespace std::chrono;
|
||||
return {sys_seconds::min(), sys_seconds::max(), offset_,
|
||||
minutes{0}, offset_ >= minutes{0}
|
||||
? "+" + date::format("%H%M", offset_)
|
||||
: "-" + date::format("%H%M", -offset_)};
|
||||
}
|
||||
</pre></blockquote>
|
||||
|
||||
<p>
|
||||
Above I've chosen to make the abbreviation for <code>OffsetZone</code> equivalent to
|
||||
<code>%z</code>, but I could have installed any <code>std::string</code> I wanted to.
|
||||
This allows me to say:
|
||||
</p>
|
||||
|
||||
<blockquote><pre>
|
||||
std::cout << zt << '\n';
|
||||
</pre></blockquote>
|
||||
|
||||
<p>
|
||||
which just output for me:
|
||||
</p>
|
||||
|
||||
<blockquote><pre>
|
||||
2017-09-16 21:36:10.913 +0345
|
||||
</pre></blockquote>
|
||||
|
||||
<p>
|
||||
If I want to make <code>zoned_time<Duration, OffsetZone></code> default constructible,
|
||||
then I need to specialize <code>zoned_traits<OffsetZone></code> with
|
||||
<code>default_zone()</code>:
|
||||
</p>
|
||||
|
||||
<blockquote><pre>
|
||||
namespace date
|
||||
{
|
||||
|
||||
template <>
|
||||
struct zoned_traits<OffsetZone>
|
||||
{
|
||||
static
|
||||
OffsetZone
|
||||
default_zone()
|
||||
{
|
||||
using namespace std::chrono;
|
||||
return OffsetZone{minutes{0}};
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace date
|
||||
</pre></blockquote>
|
||||
|
||||
<p>
|
||||
Now this:
|
||||
</p>
|
||||
|
||||
<blockquote><pre>
|
||||
zoned_time<milliseconds, OffsetZone> zt;
|
||||
std::cout << zt << '\n';
|
||||
</pre></blockquote>
|
||||
|
||||
<p>
|
||||
outputs:
|
||||
</p>
|
||||
|
||||
<blockquote><pre>
|
||||
1970-01-01 00:00:00.000 +0000
|
||||
</pre></blockquote>
|
||||
|
||||
<p>
|
||||
And if I wanted to construct a <code>zoned_time<Duration, OffsetZone></code> from
|
||||
a <code>string</code>, I need to add
|
||||
<code>static OffsetZone locate_zone(string name)</code> to my <code>zoned_traits</code>
|
||||
specialization.
|
||||
</p>
|
||||
|
||||
<blockquote><pre>
|
||||
namespace date
|
||||
{
|
||||
|
||||
template <>
|
||||
struct zoned_traits<OffsetZone>
|
||||
{
|
||||
static
|
||||
OffsetZone
|
||||
default_zone()
|
||||
{
|
||||
using namespace std::chrono;
|
||||
return OffsetZone{minutes{0}};
|
||||
}
|
||||
|
||||
static
|
||||
OffsetZone
|
||||
locate_zone(const std::string& name)
|
||||
{
|
||||
using namespace std::chrono;
|
||||
if (name == "UTC")
|
||||
return OffsetZone{minutes{0}};
|
||||
throw std::runtime_error{"OffsetZone can't handle anything but " + name};
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace date
|
||||
</pre></blockquote>
|
||||
|
||||
<p>
|
||||
Now this:
|
||||
</p>
|
||||
|
||||
<blockquote><pre>
|
||||
zoned_time<seconds, OffsetZone> zt{"UTC", floor<seconds>(system_clock::now())};
|
||||
std::cout << zt << '\n';
|
||||
</pre></blockquote>
|
||||
|
||||
<p>
|
||||
outputs:
|
||||
</p>
|
||||
|
||||
<blockquote><pre>
|
||||
2017-09-16 18:09:22 +0000
|
||||
</pre></blockquote>
|
||||
|
||||
<a name="Reference"></a><h2>Reference</h2>
|
||||
|
||||
<p>
|
||||
@@ -1543,84 +1789,125 @@ useful for debugging this library.
|
||||
|
||||
</blockquote>
|
||||
|
||||
<a name="zoned_traits"></a><h3><code>zoned_traits</code></h3>
|
||||
|
||||
<blockquote>
|
||||
<p>
|
||||
<code>zoned_traits</code> provides a means for customizing the behavior of
|
||||
<code>zoned_time<Duration, TimeZonePtr></code> for the
|
||||
<code>zoned_time</code> default constructor, and constructors taking
|
||||
<code>string_view</code>. A specialization for <code>const time_zone*</code>
|
||||
is provided by the implementation.
|
||||
</p>
|
||||
|
||||
<pre>
|
||||
template <class T> struct zoned_traits {};
|
||||
|
||||
template <>
|
||||
struct zoned_traits<const time_zone*>
|
||||
{
|
||||
static const time_zone* default_zone();
|
||||
static const time_zone* locate_zone(string_view name);
|
||||
};
|
||||
</pre>
|
||||
|
||||
<pre>
|
||||
static const time_zone* zoned_traits<const time_zone*>::default_zone();
|
||||
</pre>
|
||||
<blockquote>
|
||||
<p>
|
||||
<i>Returns:</i> <code>date::locate_zone("UTC")</code>.
|
||||
</p>
|
||||
</blockquote>
|
||||
|
||||
<pre>
|
||||
static const time_zone* zoned_traits<const time_zone*>::locate_zone(string_view name);
|
||||
</pre>
|
||||
<blockquote>
|
||||
<p>
|
||||
<i>Returns:</i> <code>date::locate_zone(name)</code>.
|
||||
</p>
|
||||
</blockquote>
|
||||
|
||||
</blockquote>
|
||||
|
||||
<a name="zoned_time"></a><h3><code>zoned_time</code></h3>
|
||||
|
||||
<blockquote>
|
||||
<p>
|
||||
<code>zoned_time</code> represents a logical paring of <code>time_zone</code> and a
|
||||
<code>time_point</code> with precision <code>Duration</code>. If <code>seconds</code>
|
||||
is not implicitly convertible to <code>Duration</code>, the instantiation is ill-formed.
|
||||
[<i>Note:</i> There exist <code>time_zone</code>s with UTC offsets that require a
|
||||
precision of <code>seconds</code>. <i>— end note:</i>]
|
||||
<code>time_point</code> with precision <code>Duration</code>.
|
||||
</p>
|
||||
|
||||
<pre>
|
||||
template <class Duration>
|
||||
template <class Duration, class TimeZonePtr = const time_zone*>
|
||||
class zoned_time
|
||||
{
|
||||
const time_zone* zone_; // exposition only
|
||||
sys_time<Duration> tp_; // exposition only
|
||||
public:
|
||||
using duration = common_type_t<Duration, seconds>;
|
||||
|
||||
private:
|
||||
TimeZonePtr zone_; // exposition only
|
||||
sys_time<duration> tp_; // exposition only
|
||||
|
||||
public:
|
||||
zoned_time();
|
||||
zoned_time(const zoned_time&) = default;
|
||||
zoned_time& operator=(const zoned_time&) = default;
|
||||
|
||||
zoned_time();
|
||||
zoned_time(sys_time<Duration> st);
|
||||
explicit zoned_time(const time_zone* z);
|
||||
explicit zoned_time(const std::string& name);
|
||||
zoned_time(const sys_time<Duration>& st);
|
||||
explicit zoned_time(TimeZonePtr z);
|
||||
explicit zoned_time(string_view name);
|
||||
|
||||
template <class Duration2,
|
||||
class = std::enable_if_t
|
||||
<
|
||||
std::is_convertible<sys_time<Duration2>,
|
||||
sys_time<Duration>>{}
|
||||
>>
|
||||
template <class Duration2>
|
||||
zoned_time(const zoned_time<Duration2>& zt) noexcept;
|
||||
|
||||
zoned_time(const time_zone* z, local_time<Duration> tp);
|
||||
zoned_time(const std::string& name, local_time<Duration> tp);
|
||||
zoned_time(const time_zone* z, local_time<Duration> tp, choose c);
|
||||
zoned_time(const std::string& name, local_time<Duration> tp, choose c);
|
||||
zoned_time(TimeZonePtr z, const sys_time<Duration>& st);
|
||||
zoned_time(string_view name, const sys_time<Duration>& st);
|
||||
|
||||
zoned_time(const time_zone* z, const zoned_time<Duration>& zt);
|
||||
zoned_time(const std::string& name, const zoned_time<Duration>& zt);
|
||||
zoned_time(const time_zone* z, const zoned_time<Duration>& zt, choose);
|
||||
zoned_time(const std::string& name, const zoned_time<Duration>& zt, choose);
|
||||
zoned_time(TimeZonePtr z, const local_time<Duration>& tp);
|
||||
zoned_time(string_view name, const local_time<Duration>& tp);
|
||||
zoned_time(TimeZonePtr z, const local_time<Duration>& tp, choose c);
|
||||
zoned_time(string_view name, const local_time<Duration>& tp, choose c);
|
||||
|
||||
zoned_time(const time_zone* z, const sys_time<Duration>& st);
|
||||
zoned_time(const std::string& name, const sys_time<Duration>& st);
|
||||
zoned_time(TimeZonePtr z, const zoned_time<Duration>& zt);
|
||||
zoned_time(string_view name, const zoned_time<Duration>& zt);
|
||||
zoned_time(TimeZonePtr z, const zoned_time<Duration>& zt, choose);
|
||||
zoned_time(string_view name, const zoned_time<Duration>& zt, choose);
|
||||
|
||||
zoned_time& operator=(sys_time<Duration> st);
|
||||
zoned_time& operator=(local_time<Duration> ut);
|
||||
zoned_time& operator=(const sys_time<Duration>& st);
|
||||
zoned_time& operator=(const local_time<Duration>& ut);
|
||||
|
||||
operator sys_time<Duration>() const;
|
||||
explicit operator local_time<Duration>() const;
|
||||
operator sys_time<duration>() const;
|
||||
explicit operator local_time<duration>() const;
|
||||
|
||||
const time_zone* get_time_zone() const;
|
||||
local_time<Duration> get_local_time() const;
|
||||
sys_time<Duration> get_sys_time() const;
|
||||
TimeZonePtr get_time_zone() const;
|
||||
local_time<duration> get_local_time() const;
|
||||
sys_time<duration> get_sys_time() const;
|
||||
sys_info get_info() const;
|
||||
};
|
||||
|
||||
using zoned_seconds = zoned_time<std::chrono::seconds>;
|
||||
|
||||
template <class Duration1, class Duration2>
|
||||
template <class Duration1, class Duration2, class TimeZonePtr>
|
||||
bool
|
||||
operator==(const zoned_time<Duration1>& x, const zoned_time<Duration2>& y);
|
||||
operator==(const zoned_time<Duration1, TimeZonePtr>& x,
|
||||
const zoned_time<Duration2, TimeZonePtr>& y);
|
||||
|
||||
template <class Duration1, class Duration2>
|
||||
template <class Duration1, class Duration2, class TimeZonePtr>
|
||||
bool
|
||||
operator!=(const zoned_time<Duration1>& x, const zoned_time<Duration2>& y);
|
||||
operator!=(const zoned_time<Duration1, TimeZonePtr>& x,
|
||||
const zoned_time<Duration2, TimeZonePtr>& y);
|
||||
|
||||
template <class CharT, class Traits, class Duration>
|
||||
std::basic_ostream<class CharT, class Traits>&
|
||||
operator<<(std::basic_ostream<class CharT, class Traits>& os, const zoned_time<Duration>& t)
|
||||
template <class charT, class traits, class Duration, class TimeZonePtr>
|
||||
basic_ostream<charT, traits>&
|
||||
operator<<(basic_ostream<charT, traits>& os,
|
||||
const zoned_time<Duration, TimeZonePtr>& t);
|
||||
|
||||
template <class CharT, class Traits, class Duration>
|
||||
std::basic_ostream<CharT, Traits>&
|
||||
to_stream(std::basic_ostream<CharT, Traits>& os, const CharT* fmt,
|
||||
const zoned_time<Duration>& tp);
|
||||
template <class charT, class traits, class Duration, class TimeZonePtr>
|
||||
basic_ostream<charT, traits>&
|
||||
to_stream(basic_ostream<charT, traits>& os, const charT* fmt,
|
||||
const zoned_time<Duration, TimeZonePtr>& tp);
|
||||
</pre>
|
||||
|
||||
<p>
|
||||
@@ -1630,8 +1917,23 @@ and is not ambiguous.
|
||||
</p>
|
||||
|
||||
<pre>
|
||||
zoned_time<Duration>::zoned_time(const zoned_time&) = default;
|
||||
zoned_time<Duration>& zoned_time<Duration>::operator=(const zoned_time&) = default;
|
||||
zoned_time<Duration, TimeZonePtr>::zoned_time();
|
||||
</pre>
|
||||
<blockquote>
|
||||
<p>
|
||||
<i>Remarks:</i> This constructor does not participate in overload resolution unless
|
||||
the expression <code>zoned_traits<TimeZonePtr>::default_zone()</code> is well formed.
|
||||
</p>
|
||||
<p>
|
||||
<i>Effects:</i> Constructs a <code>zoned_time</code> by initializing
|
||||
<code>zone_</code> with <code>zoned_traits<TimeZonePtr>::default_zone()</code> and
|
||||
default constructing <code>tp_</code>.
|
||||
</p>
|
||||
</blockquote>
|
||||
|
||||
<pre>
|
||||
zoned_time<Duration, TimeZonePtr>::zoned_time(const zoned_time&) = default;
|
||||
zoned_time<Duration, TimeZonePtr>& zoned_time<Duration>::operator=(const zoned_time&) = default;
|
||||
</pre>
|
||||
<blockquote>
|
||||
<p>
|
||||
@@ -1644,151 +1946,214 @@ members.
|
||||
</blockquote>
|
||||
|
||||
<pre>
|
||||
zoned_time<Duration>::zoned_time();
|
||||
zoned_time<Duration, TimeZonePtr>::zoned_time(const sys_time<Duration>& st);
|
||||
</pre>
|
||||
<blockquote>
|
||||
<p>
|
||||
<i>Effects:</i> Constructs a <code>zoned_time</code> <code>zt</code> such that
|
||||
<code>zt.get_time_zone()->name() == "UTC"</code>, and
|
||||
<code>zt.get_sys_time() == sys_seconds{}</code>.
|
||||
<i>Remarks:</i> This constructor does not participate in overload resolution unless
|
||||
the expression <code>zoned_traits<TimeZonePtr>::default_zone()</code> is well formed.
|
||||
</p>
|
||||
<p>
|
||||
<i>Effects:</i> Constructs a <code>zoned_time</code> by initializing
|
||||
<code>zone_</code> with <code>zoned_traits<TimeZonePtr>::default_zone()</code> and
|
||||
<code>tp_</code> with <code>st</code>.
|
||||
</p>
|
||||
</blockquote>
|
||||
|
||||
<pre>
|
||||
zoned_time<Duration>::zoned_time(sys_time<Duration> st);
|
||||
</pre>
|
||||
<blockquote>
|
||||
<p>
|
||||
<i>Effects:</i> Constructs a <code>zoned_time</code> <code>zt</code> such that
|
||||
<code>zt.get_time_zone()->name() == "UTC"</code>, and
|
||||
<code>zt.get_sys_time() == st</code>.
|
||||
</p>
|
||||
</blockquote>
|
||||
|
||||
<pre>
|
||||
explicit zoned_time<Duration>::zoned_time(const time_zone* z);
|
||||
explicit zoned_time<Duration, TimeZonePtr>::zoned_time(TimeZonePtr z);
|
||||
</pre>
|
||||
<blockquote>
|
||||
<p>
|
||||
<i>Requires:</i> <code>z</code> refers to a valid <code>time_zone</code>.
|
||||
</p>
|
||||
<p>
|
||||
<i>Effects:</i> Constructs a <code>zoned_time</code> <code>zt</code> such that
|
||||
<code>zt.get_time_zone()-> == z</code>, and
|
||||
<code>zt.get_sys_time() == sys_seconds{}</code>.
|
||||
<i>Effects:</i> Constructs a <code>zoned_time</code> initializing <code>zone_</code>
|
||||
with <code>std::move(z)</code>.
|
||||
</p>
|
||||
</blockquote>
|
||||
|
||||
<pre>
|
||||
explicit zoned_time<Duration>::zoned_time(const std::string& name);
|
||||
explicit zoned_time<Duration, TimeZonePtr>::zoned_time(string_view name);
|
||||
</pre>
|
||||
<blockquote>
|
||||
<p>
|
||||
<i>Effects:</i> Equivalent to construction with <code>locate_zone(name)</code>.
|
||||
<i>Remarks:</i> This constructor does not participate in overload resolution unless
|
||||
the expression <code>zoned_traits<TimeZonePtr>::locate_zone(string_view{})</code>
|
||||
is well formed and <code>zoned_time</code> is constructible from the return type of
|
||||
<code>zoned_traits<TimeZonePtr>::locate_zone(string_view{})</code>.
|
||||
</p>
|
||||
<p>
|
||||
<i>Throws:</i> Any exception propagating out of <code>locate_zone(name)</code>.
|
||||
<i>Effects:</i> Constructs a <code>zoned_time</code> by initializing
|
||||
<code>zone_</code> with <code>zoned_traits<TimeZonePtr>::locate_zone(name)</code>
|
||||
and default constructing <code>tp_</code>.
|
||||
</p>
|
||||
</blockquote>
|
||||
|
||||
<pre>
|
||||
template <class Duration2,
|
||||
class = std::enable_if_t
|
||||
<
|
||||
std::is_convertible<sys_time<Duration2>,
|
||||
sys_time<Duration>>{}
|
||||
>>
|
||||
zoned_time<Duration>::zoned_time(const zoned_time<Duration2>& y) noexcept;
|
||||
template <class Duration2, TimeZonePtr>
|
||||
zoned_time<Duration>::zoned_time(const zoned_time<Duration2, TimeZonePtr>& y) noexcept;
|
||||
</pre>
|
||||
<blockquote>
|
||||
<p>
|
||||
<i>Remarks:</i> Does not participate in overload resolution unless
|
||||
<code>sys_time<Duration2></code> is implicitly convertible to
|
||||
<code>sys_time<Duration></code>.
|
||||
</p>
|
||||
<p>
|
||||
<i>Effects:</i> Constructs a <code>zoned_time</code> <code>x</code> such that
|
||||
<code>x == y</code>.
|
||||
</p>
|
||||
</blockquote>
|
||||
|
||||
<pre>
|
||||
zoned_time<Duration>::zoned_time(const time_zone* z, local_time<Duration> tp);
|
||||
zoned_time<Duration, TimeZonePtr>::zoned_time(TimeZonePtr z, const sys_time<Duration>& st);
|
||||
</pre>
|
||||
<blockquote>
|
||||
<p>
|
||||
<i>Requires:</i> <code>z</code> refers to a valid <code>time_zone</code>.
|
||||
</p>
|
||||
<p>
|
||||
<i>Effects:</i> Constructs a <code>zoned_time</code> <code>zt</code> such that
|
||||
<code>zt.get_time_zone()-> == z</code>, and <code>zt.get_local_time() == tp</code>.
|
||||
</p>
|
||||
<p>
|
||||
<i>Throws:</i> Any exception that <code>z->to_sys(tp)</code> would throw.
|
||||
<i>Effects:</i> Constructs a <code>zoned_time</code> by initializing <code>zone_</code>
|
||||
with <code>std::move(z)</code> and <code>tp_</code> with <code>st</code>.
|
||||
</p>
|
||||
</blockquote>
|
||||
|
||||
<pre>
|
||||
zoned_time<Duration>::zoned_time(const std::string& name, local_time<Duration> tp);
|
||||
zoned_time<Duration, TimeZonePtr>::zoned_time(string_view name, const sys_time<Duration>& st);
|
||||
</pre>
|
||||
<blockquote>
|
||||
<p>
|
||||
<i>Effects:</i> Equivalent to construction with <code>{locate_zone(name), tp}</code>.
|
||||
<i>Remarks:</i> This constructor does not participate in overload resolution unless
|
||||
<code>zoned_time</code> is constructible from the return type of
|
||||
<code>zoned_traits<TimeZonePtr>::locate_zone(name)</code> and <code>st</code>.
|
||||
</p>
|
||||
<p>
|
||||
<i>Effects:</i> Equivalent to construction with <code>{zoned_traits<TimeZonePtr>::locate_zone(name), st}</code>.
|
||||
</p>
|
||||
</blockquote>
|
||||
|
||||
<pre>
|
||||
zoned_time<Duration>::zoned_time(const time_zone* z, local_time<Duration> tp, choose c);
|
||||
zoned_time<Duration, TimeZonePtr>::zoned_time(TimeZonePtr z, const local_time<Duration>& tp);
|
||||
</pre>
|
||||
<blockquote>
|
||||
<p>
|
||||
<i>Requires:</i> <code>z</code> refers to a valid <code>time_zone</code>.
|
||||
</p>
|
||||
<p>
|
||||
<i>Effects:</i> Constructs a <code>zoned_time</code> <code>zt</code> such that
|
||||
<code>zt.get_time_zone()-> == z</code>, and
|
||||
<code>zt.get_sys_time() == z->to_sys(tp, c)</code>.
|
||||
<i>Remarks:</i> This constructor does not participate in overload resolution unless
|
||||
<code>declval<TimeZonePtr&>()->to_sys(local_time<Duration>{})</code>
|
||||
is convertible to <code>sys_time<duration></code>.
|
||||
</p>
|
||||
<p>
|
||||
<i>Effects:</i> Constructs a <code>zoned_time</code> by initializing <code>zone_</code>
|
||||
with <code>std::move(z)</code> and <code>tp_</code> with <code>zone_->to_sys(t)</code>.
|
||||
</p>
|
||||
</blockquote>
|
||||
|
||||
<pre>
|
||||
zoned_time<Duration>::zoned_time(const std::string& name, local_time<Duration> tp, choose c);
|
||||
zoned_time<Duration, TimeZonePtr>::zoned_time(string_view name, const local_time<Duration>& tp);
|
||||
</pre>
|
||||
<blockquote>
|
||||
<p>
|
||||
<i>Effects:</i> Equivalent to construction with <code>{locate_zone(name), tp, c}</code>.
|
||||
<i>Remarks:</i> This constructor does not participate in overload resolution unless
|
||||
<code>zoned_time</code> is constructible from the return type of
|
||||
<code>zoned_traits<TimeZonePtr>::locate_zone(name)</code> and <code>tp</code>.
|
||||
</p>
|
||||
<p>
|
||||
<i>Effects:</i> Equivalent to construction with <code>{zoned_traits<TimeZonePtr>::locate_zone(name), tp}</code>.
|
||||
</p>
|
||||
</blockquote>
|
||||
|
||||
<pre>
|
||||
zoned_time<Duration>::zoned_time(const time_zone* z, const zoned_time<Duration>& y);
|
||||
zoned_time<Duration, TimeZonePtr>::zoned_time(TimeZonePtr z, const local_time<Duration>& tp, choose c);
|
||||
</pre>
|
||||
<blockquote>
|
||||
<p>
|
||||
<i>Requires:</i> <code>z</code> refers to a valid <code>time_zone</code>.
|
||||
</p>
|
||||
<p>
|
||||
<i>Effects:</i> Constructs a <code>zoned_time</code> <code>zt</code> such that
|
||||
<code>zt.get_time_zone()-> == z</code>, and
|
||||
<code>zt.get_sys_time() == y.get_sys_time()</code>.
|
||||
<i>Remarks:</i> This constructor does not participate in overload resolution unless
|
||||
<code>decltype(declval<TimeZonePtr&>()->to_sys(local_time<Duration>{}, choose::earliest))</code>
|
||||
is convertible to <code>sys_time<duration></code>.
|
||||
</p>
|
||||
<p>
|
||||
<i>Effects:</i> Constructs a <code>zoned_time</code> by initializing <code>zone_</code>
|
||||
with <code>std::move(z)</code> and <code>tp_</code> with <code>zone_->to_sys(t, c)</code>.
|
||||
</p>
|
||||
</blockquote>
|
||||
|
||||
<pre>
|
||||
zoned_time<Duration>::zoned_time(const std::string& name, const zoned_time<Duration>& y);
|
||||
zoned_time<Duration, TimeZonePtr>::zoned_time(string_view name, const local_time<Duration>& tp, choose c);
|
||||
</pre>
|
||||
<blockquote>
|
||||
<p>
|
||||
<i>Effects:</i> Equivalent to construction with <code>{locate_zone(name), y}</code>.
|
||||
<i>Remarks:</i> This constructor does not participate in overload resolution unless
|
||||
<code>zoned_time</code> is constructible from the return type of
|
||||
<code>zoned_traits<TimeZonePtr>::locate_zone(name)</code>,
|
||||
<code>local_time<Duration></code> and <code>choose</code>.
|
||||
</p>
|
||||
<p>
|
||||
<i>Effects:</i> Equivalent to construction with
|
||||
<code>{zoned_traits<TimeZonePtr>::locate_zone(name), tp, c}</code>.
|
||||
</p>
|
||||
</blockquote>
|
||||
|
||||
<pre>
|
||||
zoned_time<Duration>::zoned_time(const time_zone* z, const zoned_time<Duration>& y, choose);
|
||||
zoned_time<Duration, TimeZonePtr>::zoned_time(TimeZonePtr z, const zoned_time<Duration>& y);
|
||||
</pre>
|
||||
<blockquote>
|
||||
<p>
|
||||
<i>Requires:</i> <code>z</code> refers to a valid <code>time_zone</code>.
|
||||
</p>
|
||||
<p>
|
||||
<i>Effects:</i> Constructs a <code>zoned_time</code> <code>zt</code> such that
|
||||
<code>zt.get_time_zone()-> == z</code>, and
|
||||
<code>zt.get_sys_time() == y.get_sys_time()</code>.
|
||||
<i>Effects:</i> Constructs a <code>zoned_time</code> by initializing <code>zone_</code>
|
||||
with <code>std::move(z)</code> and <code>tp_</code> with <code>z.tp_</code>.
|
||||
</p>
|
||||
</blockquote>
|
||||
|
||||
<pre>
|
||||
zoned_time<Duration, TimeZonePtr>::zoned_time(string_view name, const zoned_time<Duration>& y);
|
||||
</pre>
|
||||
<blockquote>
|
||||
<p>
|
||||
<i>Remarks:</i> This constructor does not participate in overload resolution unless
|
||||
<code>zoned_time</code> is constructible from the return type of
|
||||
<code>zoned_traits<TimeZonePtr>::locate_zone(name)</code>
|
||||
and <code>zoned_time</code>.
|
||||
</p>
|
||||
<p>
|
||||
<i>Effects:</i> Equivalent to construction with
|
||||
<code>{zoned_traits<TimeZonePtr>::locate_zone(name), y}</code>.
|
||||
</p>
|
||||
</blockquote>
|
||||
|
||||
<pre>
|
||||
zoned_time<Duration, TimeZonePtr>::zoned_time(TimeZonePtr z, const zoned_time<Duration>& y, choose);
|
||||
</pre>
|
||||
<blockquote>
|
||||
<p>
|
||||
<i>Requires:</i> <code>z</code> refers to a valid <code>time_zone</code>.
|
||||
</p>
|
||||
<p>
|
||||
<i>Effects:</i> Equivalent to construction with <code>{z, y}</code>.
|
||||
</p>
|
||||
<i>Note:</i> The <code>choose</code> parameter is allowed here, but has no impact.
|
||||
</p>
|
||||
</blockquote>
|
||||
|
||||
<pre>
|
||||
zoned_time<Duration, TimeZonePtr>::zoned_time(string_view name, const zoned_time<Duration>& y, choose c);
|
||||
</pre>
|
||||
<blockquote>
|
||||
<p>
|
||||
<i>Remarks:</i> This constructor does not participate in overload resolution unless
|
||||
<code>zoned_time</code> is constructible from the return type of
|
||||
<code>zoned_traits<TimeZonePtr>::locate_zone(name)</code>, <code>zoned_time</code>,
|
||||
and <code>choose</code>.
|
||||
</p>
|
||||
<p>
|
||||
<i>Effects:</i> Equivalent to construction with <code>{locate_zone(name), y, c}</code>.
|
||||
</p>
|
||||
<p>
|
||||
<i>Note:</i> The <code>choose</code> parameter is allowed here, but has no impact.
|
||||
@@ -1796,41 +2161,7 @@ zoned_time<Duration>::zoned_time(const time_zone* z, const zoned_time<D
|
||||
</blockquote>
|
||||
|
||||
<pre>
|
||||
zoned_time<Duration>::zoned_time(const std::string& name, const zoned_time<Duration>& y, choose);
|
||||
</pre>
|
||||
<blockquote>
|
||||
<p>
|
||||
<i>Effects:</i> Equivalent to construction with <code>{locate_zone(name), y}</code>.
|
||||
</p>
|
||||
<p>
|
||||
<i>Note:</i> The <code>choose</code> parameter is allowed here, but has no impact.
|
||||
</p>
|
||||
</blockquote>
|
||||
|
||||
<pre>
|
||||
zoned_time<Duration>::zoned_time(const time_zone* z, const sys_time<Duration>& st);
|
||||
</pre>
|
||||
<blockquote>
|
||||
<p>
|
||||
<i>Requires:</i> <code>z</code> refers to a valid <code>time_zone</code>.
|
||||
</p>
|
||||
<p>
|
||||
<i>Effects:</i> Constructs a <code>zoned_time</code> <code>zt</code> such that
|
||||
<code>zt.get_time_zone()-> == z</code>, and <code>zt.get_sys_time() == st</code>.
|
||||
</p>
|
||||
</blockquote>
|
||||
|
||||
<pre>
|
||||
zoned_time<Duration>::zoned_time(const std::string& name, const sys_time<Duration>& st);
|
||||
</pre>
|
||||
<blockquote>
|
||||
<p>
|
||||
<i>Effects:</i> Equivalent to construction with <code>{locate_zone(name), st}</code>.
|
||||
</p>
|
||||
</blockquote>
|
||||
|
||||
<pre>
|
||||
zoned_time<Duration>& zoned_time<Duration>::operator=(sys_time<Duration> st);
|
||||
zoned_time<Duration, TimeZonePtr>& zoned_time<Duration, TimeZonePtr>::operator=(const sys_time<Duration>& st);
|
||||
</pre>
|
||||
<blockquote>
|
||||
<p>
|
||||
@@ -1843,7 +2174,7 @@ no effect on the return value of <code>get_time_zone()</code>.
|
||||
</blockquote>
|
||||
|
||||
<pre>
|
||||
zoned_time<Duration>& zoned_time<Duration>::operator=(local_time<Duration> lt);
|
||||
zoned_time<Duration, TimeZonePtr>& zoned_time<Duration, TimeZonePtr>::operator=(const local_time<Duration>& lt);
|
||||
</pre>
|
||||
<blockquote>
|
||||
<p>
|
||||
@@ -1856,7 +2187,7 @@ no effect on the return value of <code>get_time_zone()</code>.
|
||||
</blockquote>
|
||||
|
||||
<pre>
|
||||
zoned_time<Duration>::operator sys_time<Duration>() const;
|
||||
zoned_time<Duration, TimeZonePtr>::operator sys_time<duration>() const;
|
||||
</pre>
|
||||
<blockquote>
|
||||
<p>
|
||||
@@ -1865,7 +2196,7 @@ zoned_time<Duration>::operator sys_time<Duration>() const;
|
||||
</blockquote>
|
||||
|
||||
<pre>
|
||||
explicit zoned_time<Duration>::operator local_time<Duration>() const;
|
||||
explicit zoned_time<Duration, TimeZonePtr>::operator local_time<duration>() const;
|
||||
</pre>
|
||||
<blockquote>
|
||||
<p>
|
||||
@@ -1874,7 +2205,7 @@ explicit zoned_time<Duration>::operator local_time<Duration>() const
|
||||
</blockquote>
|
||||
|
||||
<pre>
|
||||
const time_zone* zoned_time<Duration>::get_time_zone() const;
|
||||
TimeZonePtr zoned_time<Duration, TimeZonePtr>::get_time_zone() const;
|
||||
</pre>
|
||||
<blockquote>
|
||||
<p>
|
||||
@@ -1883,7 +2214,7 @@ const time_zone* zoned_time<Duration>::get_time_zone() const;
|
||||
</blockquote>
|
||||
|
||||
<pre>
|
||||
local_time<Duration> zoned_time<Duration>::get_local_time() const;
|
||||
local_time<typename zoned_time<Duration, TimeZonePtr>::duration> zoned_time<Duration, TimeZonePtr>::get_local_time() const;
|
||||
</pre>
|
||||
<blockquote>
|
||||
<p>
|
||||
@@ -1892,7 +2223,7 @@ local_time<Duration> zoned_time<Duration>::get_local_time() const;
|
||||
</blockquote>
|
||||
|
||||
<pre>
|
||||
sys_time<Duration> zoned_time<Duration>::get_sys_time() const;
|
||||
sys_time<typename zoned_time<Duration, TimeZonePtr>::duration> zoned_time<Duration, TimeZonePtr>::get_sys_time() const;
|
||||
</pre>
|
||||
<blockquote>
|
||||
<p>
|
||||
@@ -1901,7 +2232,7 @@ sys_time<Duration> zoned_time<Duration>::get_sys_time() const;
|
||||
</blockquote>
|
||||
|
||||
<pre>
|
||||
sys_info zoned_time<Duration>::get_info() const;
|
||||
sys_info zoned_time<Duration, TimeZonePtr>::get_info() const;
|
||||
</pre>
|
||||
<blockquote>
|
||||
<p>
|
||||
@@ -1910,9 +2241,10 @@ sys_info zoned_time<Duration>::get_info() const;
|
||||
</blockquote>
|
||||
|
||||
<pre>
|
||||
template <class Duration1, class Duration2>
|
||||
template <class Duration1, class Duration2, class TimeZonePtr>
|
||||
bool
|
||||
operator==(const zoned_time<Duration1>& x, const zoned_time<Duration2>& y);
|
||||
operator==(const zoned_time<Duration1, TimeZonePtr>& x,
|
||||
const zoned_time<Duration2, TimeZonePtr>& y);
|
||||
</pre>
|
||||
<blockquote>
|
||||
<p>
|
||||
@@ -1921,9 +2253,10 @@ operator==(const zoned_time<Duration1>& x, const zoned_time<Duratio
|
||||
</blockquote>
|
||||
|
||||
<pre>
|
||||
template <class Duration1, class Duration2>
|
||||
template <class Duration1, class Duration2, class TimeZonePtr>
|
||||
bool
|
||||
operator!=(const zoned_time<Duration1>& x, const zoned_time<Duration2>& y);
|
||||
operator!=(const zoned_time<Duration1, TimeZonePtr>& x,
|
||||
const zoned_time<Duration2, TimeZonePtr>& y);
|
||||
</pre>
|
||||
<blockquote>
|
||||
<p>
|
||||
@@ -1932,13 +2265,15 @@ operator!=(const zoned_time<Duration1>& x, const zoned_time<Duratio
|
||||
</blockquote>
|
||||
|
||||
<pre>
|
||||
template <class CharT, class Traits, class Duration>
|
||||
std::basic_ostream<class CharT, class Traits>&
|
||||
operator<<(std::basic_ostream<class CharT, class Traits>& os, const zoned_time<Duration>& t)
|
||||
template <class charT, class traits, class Duration, class TimeZonePtr>
|
||||
basic_ostream<charT, traits>&
|
||||
operator<<(basic_ostream<charT, traits>& os,
|
||||
const zoned_time<Duration, TimeZonePtr>& t)
|
||||
</pre>
|
||||
<blockquote>
|
||||
<p>
|
||||
<i>Effects:</i> Calls <code>to_stream(os, "%F %T %Z", t)</code>.
|
||||
<i>Effects:</i> Streams <code>t</code> to <code>os</code> using the format "%F %T %Z"
|
||||
and the value returned from <code>t.get_local_time()</code>.
|
||||
</p>
|
||||
<p>
|
||||
<i>Returns:</i> <code>os</code>.
|
||||
@@ -1946,17 +2281,17 @@ operator<<(std::basic_ostream<class CharT, class Traits>& os, co
|
||||
</blockquote>
|
||||
|
||||
<pre>
|
||||
template <class CharT, class Traits, class Duration>
|
||||
std::basic_ostream<CharT, Traits>&
|
||||
to_stream(std::basic_ostream<CharT, Traits>& os, const CharT* fmt,
|
||||
const zoned_time<Duration>& tp);
|
||||
template <class charT, class traits, class Duration, class TimeZonePtr>
|
||||
basic_ostream<charT, traits>&
|
||||
to_stream(basic_ostream<charT, traits>& os, const charT* fmt,
|
||||
const zoned_time<Duration, TimeZonePtr>& tp);
|
||||
</pre>
|
||||
|
||||
<blockquote>
|
||||
<p>
|
||||
<i>Effects:</i> Constructs a copy of the <code>sys_info</code> object by calling
|
||||
<code>tp.get_info()</code> (stored in a local named <code>info</code> for example).
|
||||
Then calls <code>to_stream(os, fmt, tp.get_local_time(), &info.abbrev, &info.offset)</code>.
|
||||
<i>Effects:</i> First obtains a <code>sys_info</code> via <code>tp.get_info()</code>
|
||||
which for exposition purposes will be referred to as <code>info</code>. Then calls
|
||||
<code>to_stream(os, fmt, tp.get_local_time(), &info.abbrev, &info.offset)</code>.
|
||||
</p>
|
||||
<p>
|
||||
<i>Returns:</i> <code>os</code>.
|
||||
|
Reference in New Issue
Block a user