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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
### Class `utc_clock` <a id="time.clock.utc">[[time.clock.utc]]</a>
|
| 2 |
+
|
| 3 |
+
#### Overview <a id="time.clock.utc.overview">[[time.clock.utc.overview]]</a>
|
| 4 |
+
|
| 5 |
+
``` cpp
|
| 6 |
+
namespace std::chrono {
|
| 7 |
+
class utc_clock {
|
| 8 |
+
public:
|
| 9 |
+
using rep = a signed arithmetic type;
|
| 10 |
+
using period = ratio<unspecified, unspecified>;
|
| 11 |
+
using duration = chrono::duration<rep, period>;
|
| 12 |
+
using time_point = chrono::time_point<utc_clock>;
|
| 13 |
+
static constexpr bool is_steady = unspecified;
|
| 14 |
+
|
| 15 |
+
static time_point now();
|
| 16 |
+
|
| 17 |
+
template<class Duration>
|
| 18 |
+
static sys_time<common_type_t<Duration, seconds>>
|
| 19 |
+
to_sys(const utc_time<Duration>& t);
|
| 20 |
+
template<class Duration>
|
| 21 |
+
static utc_time<common_type_t<Duration, seconds>>
|
| 22 |
+
from_sys(const sys_time<Duration>& t);
|
| 23 |
+
};
|
| 24 |
+
}
|
| 25 |
+
```
|
| 26 |
+
|
| 27 |
+
In contrast to `sys_time`, which does not take leap seconds into
|
| 28 |
+
account, `utc_clock` and its associated `time_point`, `utc_time`, count
|
| 29 |
+
time, including leap seconds, since 1970-01-01 00:00:00 UTC.
|
| 30 |
+
|
| 31 |
+
[*Note 1*: The UTC time standard began on 1972-01-01 00:00:10 TAI. To
|
| 32 |
+
measure time since this epoch instead, one can add/subtract the constant
|
| 33 |
+
`sys_days{1972y/1/1} - sys_days{1970y/1/1}` (`63'072'000s`) from the
|
| 34 |
+
`utc_time`. — *end note*]
|
| 35 |
+
|
| 36 |
+
[*Example 1*:
|
| 37 |
+
`clock_cast<utc_clock>(sys_seconds{sys_days{1970y/January/1}}).time_since_epoch()`
|
| 38 |
+
is `0s`.
|
| 39 |
+
`clock_cast<utc_clock>(sys_seconds{sys_days{2000y/January/1}}).time_since_epoch()`
|
| 40 |
+
is `946'684'822s`, which is `10'957 * 86'400s + 22s`.
|
| 41 |
+
— *end example*]
|
| 42 |
+
|
| 43 |
+
`utc_clock` is not a *Cpp17TrivialClock* unless the implementation can
|
| 44 |
+
guarantee that `utc_clock::now()` does not propagate an exception.
|
| 45 |
+
|
| 46 |
+
[*Note 2*: `noexcept(from_sys(system_clock::now()))` is
|
| 47 |
+
`false`. — *end note*]
|
| 48 |
+
|
| 49 |
+
#### Member functions <a id="time.clock.utc.members">[[time.clock.utc.members]]</a>
|
| 50 |
+
|
| 51 |
+
``` cpp
|
| 52 |
+
static time_point now();
|
| 53 |
+
```
|
| 54 |
+
|
| 55 |
+
*Returns:* `from_sys(system_clock::now())`, or a more accurate value of
|
| 56 |
+
`utc_time`.
|
| 57 |
+
|
| 58 |
+
``` cpp
|
| 59 |
+
template<class Duration>
|
| 60 |
+
static sys_time<common_type_t<Duration, seconds>>
|
| 61 |
+
to_sys(const utc_time<Duration>& u);
|
| 62 |
+
```
|
| 63 |
+
|
| 64 |
+
*Returns:* A `sys_time` `t`, such that `from_sys(t) == u` if such a
|
| 65 |
+
mapping exists. Otherwise `u` represents a `time_point` during a
|
| 66 |
+
positive leap second insertion, the conversion counts that leap second
|
| 67 |
+
as not inserted, and the last representable value of `sys_time` prior to
|
| 68 |
+
the insertion of the leap second is returned.
|
| 69 |
+
|
| 70 |
+
``` cpp
|
| 71 |
+
template<class Duration>
|
| 72 |
+
static utc_time<common_type_t<Duration, seconds>>
|
| 73 |
+
from_sys(const sys_time<Duration>& t);
|
| 74 |
+
```
|
| 75 |
+
|
| 76 |
+
*Returns:* A `utc_time` `u`, such that
|
| 77 |
+
`u.time_since_epoch() - t.time_since_epoch()` is equal to the sum of
|
| 78 |
+
leap seconds that were inserted between `t` and 1970-01-01. If `t` is
|
| 79 |
+
exactly the date of leap second insertion, then the conversion counts
|
| 80 |
+
that leap second as inserted.
|
| 81 |
+
|
| 82 |
+
[*Example 1*:
|
| 83 |
+
|
| 84 |
+
``` cpp
|
| 85 |
+
auto t = sys_days{July/1/2015} - 2ns;
|
| 86 |
+
auto u = utc_clock::from_sys(t);
|
| 87 |
+
assert(u.time_since_epoch() - t.time_since_epoch() == 25s);
|
| 88 |
+
t += 1ns;
|
| 89 |
+
u = utc_clock::from_sys(t);
|
| 90 |
+
assert(u.time_since_epoch() - t.time_since_epoch() == 25s);
|
| 91 |
+
t += 1ns;
|
| 92 |
+
u = utc_clock::from_sys(t);
|
| 93 |
+
assert(u.time_since_epoch() - t.time_since_epoch() == 26s);
|
| 94 |
+
t += 1ns;
|
| 95 |
+
u = utc_clock::from_sys(t);
|
| 96 |
+
assert(u.time_since_epoch() - t.time_since_epoch() == 26s);
|
| 97 |
+
```
|
| 98 |
+
|
| 99 |
+
— *end example*]
|
| 100 |
+
|
| 101 |
+
#### Non-member functions <a id="time.clock.utc.nonmembers">[[time.clock.utc.nonmembers]]</a>
|
| 102 |
+
|
| 103 |
+
``` cpp
|
| 104 |
+
template<class charT, class traits, class Duration>
|
| 105 |
+
basic_ostream<charT, traits>&
|
| 106 |
+
operator<<(basic_ostream<charT, traits>& os, const utc_time<Duration>& t);
|
| 107 |
+
```
|
| 108 |
+
|
| 109 |
+
*Effects:* Equivalent to:
|
| 110 |
+
|
| 111 |
+
``` cpp
|
| 112 |
+
return os << format(STATICALLY-WIDEN<charT>("{:%F %T}"), t);
|
| 113 |
+
```
|
| 114 |
+
|
| 115 |
+
[*Example 1*:
|
| 116 |
+
|
| 117 |
+
``` cpp
|
| 118 |
+
auto t = sys_days{July/1/2015} - 500ms;
|
| 119 |
+
auto u = clock_cast<utc_clock>(t);
|
| 120 |
+
for (auto i = 0; i < 8; ++i, u += 250ms)
|
| 121 |
+
cout << u << " UTC\n";
|
| 122 |
+
```
|
| 123 |
+
|
| 124 |
+
Produces this output:
|
| 125 |
+
|
| 126 |
+
``` text
|
| 127 |
+
2015-06-30 23:59:59.500 UTC
|
| 128 |
+
2015-06-30 23:59:59.750 UTC
|
| 129 |
+
2015-06-30 23:59:60.000 UTC
|
| 130 |
+
2015-06-30 23:59:60.250 UTC
|
| 131 |
+
2015-06-30 23:59:60.500 UTC
|
| 132 |
+
2015-06-30 23:59:60.750 UTC
|
| 133 |
+
2015-07-01 00:00:00.000 UTC
|
| 134 |
+
2015-07-01 00:00:00.250 UTC
|
| 135 |
+
```
|
| 136 |
+
|
| 137 |
+
— *end example*]
|
| 138 |
+
|
| 139 |
+
``` cpp
|
| 140 |
+
template<class charT, class traits, class Duration, class Alloc = allocator<charT>>
|
| 141 |
+
basic_istream<charT, traits>&
|
| 142 |
+
from_stream(basic_istream<charT, traits>& is, const charT* fmt,
|
| 143 |
+
utc_time<Duration>& tp, basic_string<charT, traits, Alloc>* abbrev = nullptr,
|
| 144 |
+
minutes* offset = nullptr);
|
| 145 |
+
```
|
| 146 |
+
|
| 147 |
+
*Effects:* Attempts to parse the input stream `is` into the `utc_time`
|
| 148 |
+
`tp` using the format flags given in the NTCTS `fmt` as specified in
|
| 149 |
+
[[time.parse]]. If the parse fails to decode a valid date,
|
| 150 |
+
`is.setstate(ios_base::failbit)` is called and `tp` is not modified. If
|
| 151 |
+
`%Z` is used and successfully parsed, that value will be assigned to
|
| 152 |
+
`*abbrev` if `abbrev` is non-null. If `%z` (or a modified variant) is
|
| 153 |
+
used and successfully parsed, that value will be assigned to `*offset`
|
| 154 |
+
if `offset` is non-null. Additionally, the parsed offset will be
|
| 155 |
+
subtracted from the successfully parsed timestamp prior to assigning
|
| 156 |
+
that difference to `tp`.
|
| 157 |
+
|
| 158 |
+
*Returns:* `is`.
|
| 159 |
+
|
| 160 |
+
``` cpp
|
| 161 |
+
struct leap_second_info {
|
| 162 |
+
bool is_leap_second;
|
| 163 |
+
seconds elapsed;
|
| 164 |
+
};
|
| 165 |
+
```
|
| 166 |
+
|
| 167 |
+
The type `leap_second_info` has data members and special members
|
| 168 |
+
specified above. It has no base classes or members other than those
|
| 169 |
+
specified.
|
| 170 |
+
|
| 171 |
+
``` cpp
|
| 172 |
+
template<class Duration>
|
| 173 |
+
leap_second_info get_leap_second_info(const utc_time<Duration>& ut);
|
| 174 |
+
```
|
| 175 |
+
|
| 176 |
+
*Returns:* A `leap_second_info` `lsi`, where `lsi.is_leap_second` is
|
| 177 |
+
`true` if `ut` is during a positive leap second insertion, and otherwise
|
| 178 |
+
`false`. `lsi.elapsed` is the sum of leap seconds between 1970-01-01 and
|
| 179 |
+
`ut`. If `lsi.is_leap_second` is `true`, the leap second referred to by
|
| 180 |
+
`ut` is included in the sum.
|
| 181 |
+
|