This commit is contained in:
2025-10-25 03:02:53 +03:00
commit 043225d523
3416 changed files with 681196 additions and 0 deletions

274
cppdraft/time/clock/cast.md Normal file
View File

@@ -0,0 +1,274 @@
[time.clock.cast]
# 30 Time library [[time]](./#time)
## 30.7 Clocks [[time.clock]](time.clock#cast)
### 30.7.10 time_point conversions [time.clock.cast]
#### [30.7.10.1](#time.clock.conv) Class template clock_time_conversion [[time.clock.conv]](time.clock.conv)
namespace std::chrono {template<class DestClock, class SourceClock>struct clock_time_conversion {};}
[1](#time.clock.conv-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L3583)
clock_time_conversion serves as a trait
which can be used to specify how to convert
a source time_point of typetime_point<SourceClock, Duration> to a destination time_point of typetime_point<DestClock, Duration> via a specialization:clock_time_conversion<DestClock, SourceClock>[.](#time.clock.conv-1.sentence-1)
A specialization of clock_time_conversion<DestClock, SourceClock> shall provide a const-qualified operator() that takes a parameter of type time_point<SourceClock, Duration> and returns a time_point<DestClock, OtherDuration> representing an equivalent point in time[.](#time.clock.conv-1.sentence-2)
OtherDuration is a chrono::duration whose specialization is computed from the input Duration in a manner which can vary for each clock_time_conversion specialization[.](#time.clock.conv-1.sentence-3)
A program may specialize clock_time_conversion if at least one of the template parameters is a user-defined clock type[.](#time.clock.conv-1.sentence-4)
[2](#time.clock.conv-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L3603)
Several specializations are provided by the implementation,
as described in[[time.clock.cast.id]](#id "30.7.10.2Identity conversions"),[[time.clock.cast.sys.utc]](#sys.utc "30.7.10.3Conversions between system_­clock and utc_­clock"),[[time.clock.cast.sys]](#sys "30.7.10.4Conversions between system_­clock and other clocks"), and[[time.clock.cast.utc]](#utc "30.7.10.5Conversions between utc_­clock and other clocks")[.](#time.clock.conv-2.sentence-1)
#### [30.7.10.2](#id) Identity conversions [[time.clock.cast.id]](time.clock.cast.id)
template<class Clock>struct clock_time_conversion<Clock, Clock> {template<class Duration> time_point<Clock, Duration>operator()(const time_point<Clock, Duration>& t) const;};
[🔗](#lib:operator(),clock_time_conversion)
`template<class Duration>
time_point<Clock, Duration>
operator()(const time_point<Clock, Duration>& t) const;
`
[1](#id-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L3630)
*Returns*: t[.](#id-1.sentence-1)
template<>struct clock_time_conversion<system_clock, system_clock> {template<class Duration> sys_time<Duration>operator()(const sys_time<Duration>& t) const;};
[🔗](#lib:operator(),clock_time_conversion_)
`template<class Duration>
sys_time<Duration>
operator()(const sys_time<Duration>& t) const;
`
[2](#id-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L3652)
*Returns*: t[.](#id-2.sentence-1)
template<>struct clock_time_conversion<utc_clock, utc_clock> {template<class Duration> utc_time<Duration>operator()(const utc_time<Duration>& t) const;};
[🔗](#lib:operator(),clock_time_conversion__)
`template<class Duration>
utc_time<Duration>
operator()(const utc_time<Duration>& t) const;
`
[3](#id-3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L3674)
*Returns*: t[.](#id-3.sentence-1)
#### [30.7.10.3](#sys.utc) Conversions between system_clock and utc_clock [[time.clock.cast.sys.utc]](time.clock.cast.sys.utc)
template<>struct clock_time_conversion<utc_clock, system_clock> {template<class Duration> utc_time<common_type_t<Duration, seconds>>operator()(const sys_time<Duration>& t) const;};
[🔗](#lib:operator(),clock_time_conversion___)
`template<class Duration>
utc_time<common_type_t<Duration, seconds>>
operator()(const sys_time<Duration>& t) const;
`
[1](#sys.utc-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L3698)
*Returns*: utc_clock::from_sys(t)[.](#sys.utc-1.sentence-1)
template<>struct clock_time_conversion<system_clock, utc_clock> {template<class Duration> sys_time<common_type_t<Duration, seconds>>operator()(const utc_time<Duration>& t) const;};
[🔗](#lib:operator(),clock_time_conversion____)
`template<class Duration>
sys_time<common_type_t<Duration, seconds>>
operator()(const utc_time<Duration>& t) const;
`
[2](#sys.utc-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L3720)
*Returns*: utc_clock::to_sys(t)[.](#sys.utc-2.sentence-1)
#### [30.7.10.4](#sys) Conversions between system_clock and other clocks [[time.clock.cast.sys]](time.clock.cast.sys)
template<class SourceClock>struct clock_time_conversion<system_clock, SourceClock> {template<class Duration>auto operator()(const time_point<SourceClock, Duration>& t) const-> decltype(SourceClock::to_sys(t));};
[🔗](#lib:operator(),clock_time_conversion_____)
`template<class Duration>
auto operator()(const time_point<SourceClock, Duration>& t) const
-> decltype(SourceClock::to_sys(t));
`
[1](#sys-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L3744)
*Constraints*: SourceClock::to_sys(t) is well-formed[.](#sys-1.sentence-1)
[2](#sys-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L3748)
*Mandates*: SourceClock::to_sys(t) returns a sys_time<Duration2> for some type Duration2 ([[time.point.general]](time.point.general "30.6.1General"))[.](#sys-2.sentence-1)
[3](#sys-3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L3753)
*Returns*: SourceClock::to_sys(t)[.](#sys-3.sentence-1)
template<class DestClock>struct clock_time_conversion<DestClock, system_clock> {template<class Duration>auto operator()(const sys_time<Duration>& t) const-> decltype(DestClock::from_sys(t));};
[🔗](#lib:operator(),clock_time_conversion______)
`template<class Duration>
auto operator()(const sys_time<Duration>& t) const
-> decltype(DestClock::from_sys(t));
`
[4](#sys-4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L3775)
*Constraints*: DestClock::from_sys(t) is well-formed[.](#sys-4.sentence-1)
[5](#sys-5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L3779)
*Mandates*: DestClock::from_sys(t) returns a time_point<DestClock, Duration2> for some type Duration2 ([[time.point.general]](time.point.general "30.6.1General"))[.](#sys-5.sentence-1)
[6](#sys-6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L3784)
*Returns*: DestClock::from_sys(t)[.](#sys-6.sentence-1)
#### [30.7.10.5](#utc) Conversions between utc_clock and other clocks [[time.clock.cast.utc]](time.clock.cast.utc)
template<class SourceClock>struct clock_time_conversion<utc_clock, SourceClock> {template<class Duration>auto operator()(const time_point<SourceClock, Duration>& t) const-> decltype(SourceClock::to_utc(t));};
[🔗](#lib:operator(),clock_time_conversion_______)
`template<class Duration>
auto operator()(const time_point<SourceClock, Duration>& t) const
-> decltype(SourceClock::to_utc(t));
`
[1](#utc-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L3808)
*Constraints*: SourceClock::to_utc(t) is well-formed[.](#utc-1.sentence-1)
[2](#utc-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L3812)
*Mandates*: SourceClock::to_utc(t) returns a utc_time<Duration2> for some type Duration2 ([[time.point.general]](time.point.general "30.6.1General"))[.](#utc-2.sentence-1)
[3](#utc-3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L3817)
*Returns*: SourceClock::to_utc(t)[.](#utc-3.sentence-1)
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));};
[🔗](#lib:operator(),clock_time_conversion________)
`template<class Duration>
auto operator()(const utc_time<Duration>& t) const
-> decltype(DestClock::from_utc(t));
`
[4](#utc-4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L3839)
*Constraints*: DestClock::from_utc(t) is well-formed[.](#utc-4.sentence-1)
[5](#utc-5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L3843)
*Mandates*: DestClock::from_utc(t) returns a time_point<DestClock, Duration2> for some type Duration2 ([[time.point.general]](time.point.general "30.6.1General"))[.](#utc-5.sentence-1)
[6](#utc-6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L3848)
*Returns*: DestClock::from_utc(t)[.](#utc-6.sentence-1)
#### [30.7.10.6](#fn) Function template clock_cast [[time.clock.cast.fn]](time.clock.cast.fn)
[🔗](#lib:clock_cast)
`template<class DestClock, class SourceClock, class Duration>
auto clock_cast(const time_point<SourceClock, Duration>& t);
`
[1](#fn-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L3862)
*Constraints*: At least one of the following clock time conversion expressions
is well-formed:
- [(1.1)](#fn-1.1)
clock_time_conversion<DestClock, SourceClock>{}(t)
- [(1.2)](#fn-1.2)
clock_time_conversion<DestClock, system_clock>{}( clock_time_conversion<system_clock, SourceClock>{}(t))
- [(1.3)](#fn-1.3)
clock_time_conversion<DestClock, utc_clock>{}( clock_time_conversion<utc_clock, SourceClock>{}(t))
- [(1.4)](#fn-1.4)
clock_time_conversion<DestClock, utc_clock>{}( clock_time_conversion<utc_clock, system_clock>{}( clock_time_conversion<system_clock, SourceClock>{}(t)))
- [(1.5)](#fn-1.5)
clock_time_conversion<DestClock, system_clock>{}( clock_time_conversion<system_clock, utc_clock>{}( clock_time_conversion<utc_clock, SourceClock>{}(t)))
A clock time conversion expression is considered better than
another clock time conversion expression if it involves feweroperator() calls on clock_time_conversion specializations[.](#fn-1.sentence-2)
[2](#fn-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L3904)
*Mandates*: Among the well-formed clock time conversion expressions
from the above list, there is a unique best expression[.](#fn-2.sentence-1)
[3](#fn-3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L3909)
*Returns*: The best well-formed clock time conversion expression in the above list[.](#fn-3.sentence-1)

View File

@@ -0,0 +1,58 @@
[time.clock.cast.fn]
# 30 Time library [[time]](./#time)
## 30.7 Clocks [[time.clock]](time.clock#cast.fn)
### 30.7.10 time_point conversions [[time.clock.cast]](time.clock.cast#fn)
#### 30.7.10.6 Function template clock_cast [time.clock.cast.fn]
[🔗](#lib:clock_cast)
`template<class DestClock, class SourceClock, class Duration>
auto clock_cast(const time_point<SourceClock, Duration>& t);
`
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L3862)
*Constraints*: At least one of the following clock time conversion expressions
is well-formed:
- [(1.1)](#1.1)
clock_time_conversion<DestClock, SourceClock>{}(t)
- [(1.2)](#1.2)
clock_time_conversion<DestClock, system_clock>{}( clock_time_conversion<system_clock, SourceClock>{}(t))
- [(1.3)](#1.3)
clock_time_conversion<DestClock, utc_clock>{}( clock_time_conversion<utc_clock, SourceClock>{}(t))
- [(1.4)](#1.4)
clock_time_conversion<DestClock, utc_clock>{}( clock_time_conversion<utc_clock, system_clock>{}( clock_time_conversion<system_clock, SourceClock>{}(t)))
- [(1.5)](#1.5)
clock_time_conversion<DestClock, system_clock>{}( clock_time_conversion<system_clock, utc_clock>{}( clock_time_conversion<utc_clock, SourceClock>{}(t)))
A clock time conversion expression is considered better than
another clock time conversion expression if it involves feweroperator() calls on clock_time_conversion specializations[.](#1.sentence-2)
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L3904)
*Mandates*: Among the well-formed clock time conversion expressions
from the above list, there is a unique best expression[.](#2.sentence-1)
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L3909)
*Returns*: The best well-formed clock time conversion expression in the above list[.](#3.sentence-1)

View File

@@ -0,0 +1,54 @@
[time.clock.cast.id]
# 30 Time library [[time]](./#time)
## 30.7 Clocks [[time.clock]](time.clock#cast.id)
### 30.7.10 time_point conversions [[time.clock.cast]](time.clock.cast#id)
#### 30.7.10.2 Identity conversions [time.clock.cast.id]
template<class Clock>struct clock_time_conversion<Clock, Clock> {template<class Duration> time_point<Clock, Duration>operator()(const time_point<Clock, Duration>& t) const;};
[🔗](#lib:operator(),clock_time_conversion)
`template<class Duration>
time_point<Clock, Duration>
operator()(const time_point<Clock, Duration>& t) const;
`
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L3630)
*Returns*: t[.](#1.sentence-1)
template<>struct clock_time_conversion<system_clock, system_clock> {template<class Duration> sys_time<Duration>operator()(const sys_time<Duration>& t) const;};
[🔗](#lib:operator(),clock_time_conversion_)
`template<class Duration>
sys_time<Duration>
operator()(const sys_time<Duration>& t) const;
`
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L3652)
*Returns*: t[.](#2.sentence-1)
template<>struct clock_time_conversion<utc_clock, utc_clock> {template<class Duration> utc_time<Duration>operator()(const utc_time<Duration>& t) const;};
[🔗](#lib:operator(),clock_time_conversion__)
`template<class Duration>
utc_time<Duration>
operator()(const utc_time<Duration>& t) const;
`
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L3674)
*Returns*: t[.](#3.sentence-1)

View File

@@ -0,0 +1,63 @@
[time.clock.cast.sys]
# 30 Time library [[time]](./#time)
## 30.7 Clocks [[time.clock]](time.clock#cast.sys)
### 30.7.10 time_point conversions [[time.clock.cast]](time.clock.cast#sys)
#### 30.7.10.4 Conversions between system_clock and other clocks [time.clock.cast.sys]
template<class SourceClock>struct clock_time_conversion<system_clock, SourceClock> {template<class Duration>auto operator()(const time_point<SourceClock, Duration>& t) const-> decltype(SourceClock::to_sys(t));};
[🔗](#lib:operator(),clock_time_conversion)
`template<class Duration>
auto operator()(const time_point<SourceClock, Duration>& t) const
-> decltype(SourceClock::to_sys(t));
`
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L3744)
*Constraints*: SourceClock::to_sys(t) is well-formed[.](#1.sentence-1)
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L3748)
*Mandates*: SourceClock::to_sys(t) returns a sys_time<Duration2> for some type Duration2 ([[time.point.general]](time.point.general "30.6.1General"))[.](#2.sentence-1)
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L3753)
*Returns*: SourceClock::to_sys(t)[.](#3.sentence-1)
template<class DestClock>struct clock_time_conversion<DestClock, system_clock> {template<class Duration>auto operator()(const sys_time<Duration>& t) const-> decltype(DestClock::from_sys(t));};
[🔗](#lib:operator(),clock_time_conversion_)
`template<class Duration>
auto operator()(const sys_time<Duration>& t) const
-> decltype(DestClock::from_sys(t));
`
[4](#4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L3775)
*Constraints*: DestClock::from_sys(t) is well-formed[.](#4.sentence-1)
[5](#5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L3779)
*Mandates*: DestClock::from_sys(t) returns a time_point<DestClock, Duration2> for some type Duration2 ([[time.point.general]](time.point.general "30.6.1General"))[.](#5.sentence-1)
[6](#6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L3784)
*Returns*: DestClock::from_sys(t)[.](#6.sentence-1)

View File

@@ -0,0 +1,39 @@
[time.clock.cast.sys.utc]
# 30 Time library [[time]](./#time)
## 30.7 Clocks [[time.clock]](time.clock#cast.sys.utc)
### 30.7.10 time_point conversions [[time.clock.cast]](time.clock.cast#sys.utc)
#### 30.7.10.3 Conversions between system_clock and utc_clock [time.clock.cast.sys.utc]
template<>struct clock_time_conversion<utc_clock, system_clock> {template<class Duration> utc_time<common_type_t<Duration, seconds>>operator()(const sys_time<Duration>& t) const;};
[🔗](#lib:operator(),clock_time_conversion)
`template<class Duration>
utc_time<common_type_t<Duration, seconds>>
operator()(const sys_time<Duration>& t) const;
`
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L3698)
*Returns*: utc_clock::from_sys(t)[.](#1.sentence-1)
template<>struct clock_time_conversion<system_clock, utc_clock> {template<class Duration> sys_time<common_type_t<Duration, seconds>>operator()(const utc_time<Duration>& t) const;};
[🔗](#lib:operator(),clock_time_conversion_)
`template<class Duration>
sys_time<common_type_t<Duration, seconds>>
operator()(const utc_time<Duration>& t) const;
`
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L3720)
*Returns*: utc_clock::to_sys(t)[.](#2.sentence-1)

View File

@@ -0,0 +1,63 @@
[time.clock.cast.utc]
# 30 Time library [[time]](./#time)
## 30.7 Clocks [[time.clock]](time.clock#cast.utc)
### 30.7.10 time_point conversions [[time.clock.cast]](time.clock.cast#utc)
#### 30.7.10.5 Conversions between utc_clock and other clocks [time.clock.cast.utc]
template<class SourceClock>struct clock_time_conversion<utc_clock, SourceClock> {template<class Duration>auto operator()(const time_point<SourceClock, Duration>& t) const-> decltype(SourceClock::to_utc(t));};
[🔗](#lib:operator(),clock_time_conversion)
`template<class Duration>
auto operator()(const time_point<SourceClock, Duration>& t) const
-> decltype(SourceClock::to_utc(t));
`
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L3808)
*Constraints*: SourceClock::to_utc(t) is well-formed[.](#1.sentence-1)
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L3812)
*Mandates*: SourceClock::to_utc(t) returns a utc_time<Duration2> for some type Duration2 ([[time.point.general]](time.point.general "30.6.1General"))[.](#2.sentence-1)
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L3817)
*Returns*: SourceClock::to_utc(t)[.](#3.sentence-1)
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));};
[🔗](#lib:operator(),clock_time_conversion_)
`template<class Duration>
auto operator()(const utc_time<Duration>& t) const
-> decltype(DestClock::from_utc(t));
`
[4](#4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L3839)
*Constraints*: DestClock::from_utc(t) is well-formed[.](#4.sentence-1)
[5](#5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L3843)
*Mandates*: DestClock::from_utc(t) returns a time_point<DestClock, Duration2> for some type Duration2 ([[time.point.general]](time.point.general "30.6.1General"))[.](#5.sentence-1)
[6](#6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L3848)
*Returns*: DestClock::from_utc(t)[.](#6.sentence-1)

View File

@@ -0,0 +1,32 @@
[time.clock.conv]
# 30 Time library [[time]](./#time)
## 30.7 Clocks [[time.clock]](time.clock#conv)
### 30.7.10 time_point conversions [[time.clock.cast]](time.clock.cast#time.clock.conv)
#### 30.7.10.1 Class template clock_time_conversion [time.clock.conv]
namespace std::chrono {template<class DestClock, class SourceClock>struct clock_time_conversion {};}
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L3583)
clock_time_conversion serves as a trait
which can be used to specify how to convert
a source time_point of typetime_point<SourceClock, Duration> to a destination time_point of typetime_point<DestClock, Duration> via a specialization:clock_time_conversion<DestClock, SourceClock>[.](#1.sentence-1)
A specialization of clock_time_conversion<DestClock, SourceClock> shall provide a const-qualified operator() that takes a parameter of type time_point<SourceClock, Duration> and returns a time_point<DestClock, OtherDuration> representing an equivalent point in time[.](#1.sentence-2)
OtherDuration is a chrono::duration whose specialization is computed from the input Duration in a manner which can vary for each clock_time_conversion specialization[.](#1.sentence-3)
A program may specialize clock_time_conversion if at least one of the template parameters is a user-defined clock type[.](#1.sentence-4)
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L3603)
Several specializations are provided by the implementation,
as described in[[time.clock.cast.id]](time.clock.cast.id "30.7.10.2Identity conversions"),[[time.clock.cast.sys.utc]](time.clock.cast.sys.utc "30.7.10.3Conversions between system_­clock and utc_­clock"),[[time.clock.cast.sys]](time.clock.cast.sys "30.7.10.4Conversions between system_­clock and other clocks"), and[[time.clock.cast.utc]](time.clock.cast.utc "30.7.10.5Conversions between utc_­clock and other clocks")[.](#2.sentence-1)

View File

@@ -0,0 +1,94 @@
[time.clock.file]
# 30 Time library [[time]](./#time)
## 30.7 Clocks [[time.clock]](time.clock#file)
### 30.7.6 Type file_clock [time.clock.file]
#### [30.7.6.1](#overview) Overview [[time.clock.file.overview]](time.clock.file.overview)
namespace std::chrono {using file_clock = *see below*;}
[1](#overview-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L3369)
file_clock is an alias for a type
meeting the [*Cpp17TrivialClock*](time.clock.req#:Cpp17TrivialClock "30.3Cpp17Clock requirements[time.clock.req]") requirements ([[time.clock.req]](time.clock.req "30.3Cpp17Clock requirements")), and
using a signed arithmetic type for file_clock::rep[.](#overview-1.sentence-1)
file_clock is used to create the time_point system
used for file_time_type ([[filesystems]](filesystems "31.12File systems"))[.](#overview-1.sentence-2)
Its epoch is unspecified, andnoexcept(file_clock::now()) is true[.](#overview-1.sentence-3)
[*Note [1](#overview-note-1)*:
The type that file_clock denotes can be
in a different namespace than std::chrono,
such as std::filesystem[.](#overview-1.sentence-4)
— *end note*]
#### [30.7.6.2](#members) Member functions [[time.clock.file.members]](time.clock.file.members)
[1](#members-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L3386)
The type denoted by file_clock provides
precisely one of the following two sets of static member functions:template<class Duration>static sys_time<*see below*> to_sys(const file_time<Duration>&);template<class Duration>static file_time<*see below*> from_sys(const sys_time<Duration>&); or:template<class Duration>static utc_time<*see below*> to_utc(const file_time<Duration>&);template<class Duration>static file_time<*see below*> from_utc(const utc_time<Duration>&);
These member functions shall provide time_point conversions
consistent with those specified byutc_clock, tai_clock, and gps_clock[.](#members-1.sentence-2)
The Duration of the resultant time_point is computed from the Duration of the input time_point[.](#members-1.sentence-3)
#### [30.7.6.3](#nonmembers) Non-member functions [[time.clock.file.nonmembers]](time.clock.file.nonmembers)
[🔗](#lib:operator%3c%3c,file_time)
`template<class charT, class traits, class Duration>
basic_ostream<charT, traits>&
operator<<(basic_ostream<charT, traits>& os, const file_time<Duration>& t);
`
[1](#nonmembers-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L3423)
*Effects*: Equivalent to:return os << format(os.getloc(), *STATICALLY-WIDEN*<charT>("{:L%F %T}"), t);
[🔗](#lib:from_stream,file_time)
`template<class charT, class traits, class Duration, class Alloc = allocator<charT>>
basic_istream<charT, traits>&
from_stream(basic_istream<charT, traits>& is, const charT* fmt,
file_time<Duration>& tp, basic_string<charT, traits, Alloc>* abbrev = nullptr,
minutes* offset = nullptr);
`
[2](#nonmembers-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L3441)
*Effects*: Attempts to parse the input stream is into the file_time tp using
the format flags given in the NTCTS fmt as specified in [[time.parse]](time.parse "30.13Parsing")[.](#nonmembers-2.sentence-1)
If the parse fails to decode a valid date,is.setstate(ios_base::failbit) is called andtp is not modified[.](#nonmembers-2.sentence-2)
If %Z is used and successfully parsed,
that value will be assigned to *abbrev if abbrev is non-null[.](#nonmembers-2.sentence-3)
If %z (or a modified variant) is used and successfully parsed,
that value will be assigned to *offset if offset is non-null[.](#nonmembers-2.sentence-4)
Additionally, the parsed offset will be subtracted from
the successfully parsed timestamp prior to assigning that difference to tp[.](#nonmembers-2.sentence-5)
[3](#nonmembers-3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L3457)
*Returns*: is[.](#nonmembers-3.sentence-1)

View File

@@ -0,0 +1,21 @@
[time.clock.file.members]
# 30 Time library [[time]](./#time)
## 30.7 Clocks [[time.clock]](time.clock#file.members)
### 30.7.6 Type file_clock [[time.clock.file]](time.clock.file#members)
#### 30.7.6.2 Member functions [time.clock.file.members]
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L3386)
The type denoted by file_clock provides
precisely one of the following two sets of static member functions:template<class Duration>static sys_time<*see below*> to_sys(const file_time<Duration>&);template<class Duration>static file_time<*see below*> from_sys(const sys_time<Duration>&); or:template<class Duration>static utc_time<*see below*> to_utc(const file_time<Duration>&);template<class Duration>static file_time<*see below*> from_utc(const utc_time<Duration>&);
These member functions shall provide time_point conversions
consistent with those specified byutc_clock, tai_clock, and gps_clock[.](#1.sentence-2)
The Duration of the resultant time_point is computed from the Duration of the input time_point[.](#1.sentence-3)

View File

@@ -0,0 +1,55 @@
[time.clock.file.nonmembers]
# 30 Time library [[time]](./#time)
## 30.7 Clocks [[time.clock]](time.clock#file.nonmembers)
### 30.7.6 Type file_clock [[time.clock.file]](time.clock.file#nonmembers)
#### 30.7.6.3 Non-member functions [time.clock.file.nonmembers]
[🔗](#lib:operator%3c%3c,file_time)
`template<class charT, class traits, class Duration>
basic_ostream<charT, traits>&
operator<<(basic_ostream<charT, traits>& os, const file_time<Duration>& t);
`
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L3423)
*Effects*: Equivalent to:return os << format(os.getloc(), *STATICALLY-WIDEN*<charT>("{:L%F %T}"), t);
[🔗](#lib:from_stream,file_time)
`template<class charT, class traits, class Duration, class Alloc = allocator<charT>>
basic_istream<charT, traits>&
from_stream(basic_istream<charT, traits>& is, const charT* fmt,
file_time<Duration>& tp, basic_string<charT, traits, Alloc>* abbrev = nullptr,
minutes* offset = nullptr);
`
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L3441)
*Effects*: Attempts to parse the input stream is into the file_time tp using
the format flags given in the NTCTS fmt as specified in [[time.parse]](time.parse "30.13Parsing")[.](#2.sentence-1)
If the parse fails to decode a valid date,is.setstate(ios_base::failbit) is called andtp is not modified[.](#2.sentence-2)
If %Z is used and successfully parsed,
that value will be assigned to *abbrev if abbrev is non-null[.](#2.sentence-3)
If %z (or a modified variant) is used and successfully parsed,
that value will be assigned to *offset if offset is non-null[.](#2.sentence-4)
Additionally, the parsed offset will be subtracted from
the successfully parsed timestamp prior to assigning that difference to tp[.](#2.sentence-5)
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L3457)
*Returns*: is[.](#3.sentence-1)

View File

@@ -0,0 +1,32 @@
[time.clock.file.overview]
# 30 Time library [[time]](./#time)
## 30.7 Clocks [[time.clock]](time.clock#file.overview)
### 30.7.6 Type file_clock [[time.clock.file]](time.clock.file#overview)
#### 30.7.6.1 Overview [time.clock.file.overview]
namespace std::chrono {using file_clock = *see below*;}
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L3369)
file_clock is an alias for a type
meeting the [*Cpp17TrivialClock*](time.clock.req#:Cpp17TrivialClock "30.3Cpp17Clock requirements[time.clock.req]") requirements ([[time.clock.req]](time.clock.req "30.3Cpp17Clock requirements")), and
using a signed arithmetic type for file_clock::rep[.](#1.sentence-1)
file_clock is used to create the time_point system
used for file_time_type ([[filesystems]](filesystems "31.12File systems"))[.](#1.sentence-2)
Its epoch is unspecified, andnoexcept(file_clock::now()) is true[.](#1.sentence-3)
[*Note [1](#note-1)*:
The type that file_clock denotes can be
in a different namespace than std::chrono,
such as std::filesystem[.](#1.sentence-4)
— *end note*]

View File

@@ -0,0 +1,14 @@
[time.clock.general]
# 30 Time library [[time]](./#time)
## 30.7 Clocks [[time.clock]](time.clock#general)
### 30.7.1 General [time.clock.general]
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L2633)
The types defined in [[time.clock]](time.clock "30.7Clocks") meet the[*Cpp17TrivialClock*](time.clock.req#:Cpp17TrivialClock "30.3Cpp17Clock requirements[time.clock.req]") requirements ([[time.clock.req]](time.clock.req "30.3Cpp17Clock requirements"))
unless otherwise specified[.](#1.sentence-1)

146
cppdraft/time/clock/gps.md Normal file
View File

@@ -0,0 +1,146 @@
[time.clock.gps]
# 30 Time library [[time]](./#time)
## 30.7 Clocks [[time.clock]](time.clock#gps)
### 30.7.5 Class gps_clock [time.clock.gps]
#### [30.7.5.1](#overview) Overview [[time.clock.gps.overview]](time.clock.gps.overview)
namespace std::chrono {class gps_clock {public:using rep = *a signed arithmetic type*; using period = ratio<*unspecified*, *unspecified*>; using duration = chrono::duration<rep, period>; using time_point = chrono::time_point<gps_clock>; static constexpr bool is_steady = *unspecified*; static time_point now(); template<class Duration>static utc_time<common_type_t<Duration, seconds>> to_utc(const gps_time<Duration>&) noexcept; template<class Duration>static gps_time<common_type_t<Duration, seconds>> from_utc(const utc_time<Duration>&) noexcept; };}
[1](#overview-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L3223)
The clock gps_clock measures
seconds since the first Sunday of January, 1980 00:00:00 UTC[.](#overview-1.sentence-1)
Leap seconds are not inserted into GPS[.](#overview-1.sentence-2)
Therefore every time a leap second is inserted into UTC,
UTC shifts another second with respect to GPS[.](#overview-1.sentence-3)
Aside from the offset from 1958y/January/1 to 1980y/January/Sunday[1],
GPS is behind TAI by 19s due to the 10s offset between 1958 and 1970
and the additional 9 leap seconds inserted between 1970 and 1980[.](#overview-1.sentence-4)
[2](#overview-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L3233)
gps_clock is not a [*Cpp17TrivialClock*](time.clock.req#:Cpp17TrivialClock "30.3Cpp17Clock requirements[time.clock.req]") unless the implementation can guarantee thatgps_clock::now() does not propagate an exception[.](#overview-2.sentence-1)
[*Note [1](#overview-note-1)*:
noexcept(from_utc(utc_clock::now())) is false[.](#overview-2.sentence-2)
— *end note*]
#### [30.7.5.2](#members) Member functions [[time.clock.gps.members]](time.clock.gps.members)
[🔗](#lib:now,gps_clock)
`static time_point now();
`
[1](#members-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L3249)
*Returns*: from_utc(utc_clock::now()), or a more accurate value of gps_time[.](#members-1.sentence-1)
[🔗](#lib:to_utc,gps_clock)
`template<class Duration>
static utc_time<common_type_t<Duration, seconds>>
to_utc(const gps_time<Duration>& t) noexcept;
`
[2](#members-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L3262)
*Returns*: utc_time<common_type_t<Duration, seconds>>{t.time_since_epoch()} + 315964809s
[*Note [1](#members-note-1)*: 315964809s == sys_days{1980y/January/Sunday[1]} - sys_days{1970y/January/1} + 9s — *end note*]
[🔗](#lib:from_utc,gps_clock)
`template<class Duration>
static gps_time<common_type_t<Duration, seconds>>
from_utc(const utc_time<Duration>& t) noexcept;
`
[3](#members-3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L3282)
*Returns*: gps_time<common_type_t<Duration, seconds>>{t.time_since_epoch()} - 315964809s
[*Note [2](#members-note-2)*: 315964809s == sys_days{1980y/January/Sunday[1]} - sys_days{1970y/January/1} + 9s — *end note*]
#### [30.7.5.3](#nonmembers) Non-member functions [[time.clock.gps.nonmembers]](time.clock.gps.nonmembers)
[🔗](#lib:operator%3c%3c,gps_time)
`template<class charT, class traits, class Duration>
basic_ostream<charT, traits>&
operator<<(basic_ostream<charT, traits>& os, const gps_time<Duration>& t);
`
[1](#nonmembers-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L3304)
*Effects*: Equivalent to:return os << format(os.getloc(), *STATICALLY-WIDEN*<charT>("{:L%F %T}"), t);
[2](#nonmembers-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L3311)
[*Example [1](#nonmembers-example-1)*: auto st = sys_days{2000y/January/1};auto gt = clock_cast<gps_clock>(st);
cout << format("{0:%F %T %Z} == {1:%F %T %Z}\n", st, gt);
Produces this output:
```
2000-01-01 00:00:00 UTC == 2000-01-01 00:00:13 GPS
```
— *end example*]
[🔗](#lib:from_stream,gps_time)
`template<class charT, class traits, class Duration, class Alloc = allocator<charT>>
basic_istream<charT, traits>&
from_stream(basic_istream<charT, traits>& is, const charT* fmt,
gps_time<Duration>& tp, basic_string<charT, traits, Alloc>* abbrev = nullptr,
minutes* offset = nullptr);
`
[3](#nonmembers-3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L3337)
*Effects*: Attempts to parse the input stream is into the gps_time tp using
the format flags given in the NTCTS fmt as specified in [[time.parse]](time.parse "30.13Parsing")[.](#nonmembers-3.sentence-1)
If the parse fails to decode a valid date,is.setstate(ios_base::failbit) is called andtp is not modified[.](#nonmembers-3.sentence-2)
If %Z is used and successfully parsed,
that value will be assigned to *abbrev if abbrev is non-null[.](#nonmembers-3.sentence-3)
If %z (or a modified variant) is used and successfully parsed,
that value will be assigned to *offset if offset is non-null[.](#nonmembers-3.sentence-4)
Additionally, the parsed offset will be subtracted from
the successfully parsed timestamp prior to assigning that difference to tp[.](#nonmembers-3.sentence-5)
[4](#nonmembers-4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L3353)
*Returns*: is[.](#nonmembers-4.sentence-1)

View File

@@ -0,0 +1,50 @@
[time.clock.gps.members]
# 30 Time library [[time]](./#time)
## 30.7 Clocks [[time.clock]](time.clock#gps.members)
### 30.7.5 Class gps_clock [[time.clock.gps]](time.clock.gps#members)
#### 30.7.5.2 Member functions [time.clock.gps.members]
[🔗](#lib:now,gps_clock)
`static time_point now();
`
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L3249)
*Returns*: from_utc(utc_clock::now()), or a more accurate value of gps_time[.](#1.sentence-1)
[🔗](#lib:to_utc,gps_clock)
`template<class Duration>
static utc_time<common_type_t<Duration, seconds>>
to_utc(const gps_time<Duration>& t) noexcept;
`
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L3262)
*Returns*: utc_time<common_type_t<Duration, seconds>>{t.time_since_epoch()} + 315964809s
[*Note [1](#note-1)*: 315964809s == sys_days{1980y/January/Sunday[1]} - sys_days{1970y/January/1} + 9s — *end note*]
[🔗](#lib:from_utc,gps_clock)
`template<class Duration>
static gps_time<common_type_t<Duration, seconds>>
from_utc(const utc_time<Duration>& t) noexcept;
`
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L3282)
*Returns*: gps_time<common_type_t<Duration, seconds>>{t.time_since_epoch()} - 315964809s
[*Note [2](#note-2)*: 315964809s == sys_days{1980y/January/Sunday[1]} - sys_days{1970y/January/1} + 9s — *end note*]

View File

@@ -0,0 +1,71 @@
[time.clock.gps.nonmembers]
# 30 Time library [[time]](./#time)
## 30.7 Clocks [[time.clock]](time.clock#gps.nonmembers)
### 30.7.5 Class gps_clock [[time.clock.gps]](time.clock.gps#nonmembers)
#### 30.7.5.3 Non-member functions [time.clock.gps.nonmembers]
[🔗](#lib:operator%3c%3c,gps_time)
`template<class charT, class traits, class Duration>
basic_ostream<charT, traits>&
operator<<(basic_ostream<charT, traits>& os, const gps_time<Duration>& t);
`
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L3304)
*Effects*: Equivalent to:return os << format(os.getloc(), *STATICALLY-WIDEN*<charT>("{:L%F %T}"), t);
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L3311)
[*Example [1](#example-1)*: auto st = sys_days{2000y/January/1};auto gt = clock_cast<gps_clock>(st);
cout << format("{0:%F %T %Z} == {1:%F %T %Z}\n", st, gt);
Produces this output:
```
2000-01-01 00:00:00 UTC == 2000-01-01 00:00:13 GPS
```
— *end example*]
[🔗](#lib:from_stream,gps_time)
`template<class charT, class traits, class Duration, class Alloc = allocator<charT>>
basic_istream<charT, traits>&
from_stream(basic_istream<charT, traits>& is, const charT* fmt,
gps_time<Duration>& tp, basic_string<charT, traits, Alloc>* abbrev = nullptr,
minutes* offset = nullptr);
`
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L3337)
*Effects*: Attempts to parse the input stream is into the gps_time tp using
the format flags given in the NTCTS fmt as specified in [[time.parse]](time.parse "30.13Parsing")[.](#3.sentence-1)
If the parse fails to decode a valid date,is.setstate(ios_base::failbit) is called andtp is not modified[.](#3.sentence-2)
If %Z is used and successfully parsed,
that value will be assigned to *abbrev if abbrev is non-null[.](#3.sentence-3)
If %z (or a modified variant) is used and successfully parsed,
that value will be assigned to *offset if offset is non-null[.](#3.sentence-4)
Additionally, the parsed offset will be subtracted from
the successfully parsed timestamp prior to assigning that difference to tp[.](#3.sentence-5)
[4](#4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L3353)
*Returns*: is[.](#4.sentence-1)

View File

@@ -0,0 +1,39 @@
[time.clock.gps.overview]
# 30 Time library [[time]](./#time)
## 30.7 Clocks [[time.clock]](time.clock#gps.overview)
### 30.7.5 Class gps_clock [[time.clock.gps]](time.clock.gps#overview)
#### 30.7.5.1 Overview [time.clock.gps.overview]
namespace std::chrono {class gps_clock {public:using rep = *a signed arithmetic type*; using period = ratio<*unspecified*, *unspecified*>; using duration = chrono::duration<rep, period>; using time_point = chrono::time_point<gps_clock>; static constexpr bool is_steady = *unspecified*; static time_point now(); template<class Duration>static utc_time<common_type_t<Duration, seconds>> to_utc(const gps_time<Duration>&) noexcept; template<class Duration>static gps_time<common_type_t<Duration, seconds>> from_utc(const utc_time<Duration>&) noexcept; };}
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L3223)
The clock gps_clock measures
seconds since the first Sunday of January, 1980 00:00:00 UTC[.](#1.sentence-1)
Leap seconds are not inserted into GPS[.](#1.sentence-2)
Therefore every time a leap second is inserted into UTC,
UTC shifts another second with respect to GPS[.](#1.sentence-3)
Aside from the offset from 1958y/January/1 to 1980y/January/Sunday[1],
GPS is behind TAI by 19s due to the 10s offset between 1958 and 1970
and the additional 9 leap seconds inserted between 1970 and 1980[.](#1.sentence-4)
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L3233)
gps_clock is not a [*Cpp17TrivialClock*](time.clock.req#:Cpp17TrivialClock "30.3Cpp17Clock requirements[time.clock.req]") unless the implementation can guarantee thatgps_clock::now() does not propagate an exception[.](#2.sentence-1)
[*Note [1](#note-1)*:
noexcept(from_utc(utc_clock::now())) is false[.](#2.sentence-2)
— *end note*]

View File

@@ -0,0 +1,18 @@
[time.clock.hires]
# 30 Time library [[time]](./#time)
## 30.7 Clocks [[time.clock]](time.clock#hires)
### 30.7.8 Class high_resolution_clock [time.clock.hires]
namespace std::chrono {class high_resolution_clock {public:using rep = *unspecified*; using period = ratio<*unspecified*, *unspecified*>; using duration = chrono::duration<rep, period>; using time_point = chrono::time_point<*unspecified*, duration>; static constexpr bool is_steady = *unspecified*; static time_point now() noexcept; };}
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L3503)
Objects of class high_resolution_clock represent clocks with the
shortest tick period[.](#1.sentence-1)
high_resolution_clock may be a synonym forsystem_clock or steady_clock[.](#1.sentence-2)

View File

@@ -0,0 +1,72 @@
[time.clock.local]
# 30 Time library [[time]](./#time)
## 30.7 Clocks [[time.clock]](time.clock#local)
### 30.7.9 Local time [time.clock.local]
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L3511)
The family of time points
denoted by local_time<Duration> are based on the pseudo clock local_t[.](#1.sentence-1)
local_t has no member now() and thus does not meet the clock requirements[.](#1.sentence-2)
Nevertheless local_time<Duration> serves the vital role of
representing local time with respect to a not-yet-specified time zone[.](#1.sentence-3)
Aside from being able to get the current time,
the complete time_point algebra is available
for local_time<Duration> (just as for sys_time<Duration>)[.](#1.sentence-4)
[🔗](#lib:operator%3c%3c,local_time)
`template<class charT, class traits, class Duration>
basic_ostream<charT, traits>&
operator<<(basic_ostream<charT, traits>& os, const local_time<Duration>& lt);
`
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L3531)
*Effects*: os << sys_time<Duration>{lt.time_since_epoch()};
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L3537)
*Returns*: os[.](#3.sentence-1)
[🔗](#lib:from_stream,local_time)
`template<class charT, class traits, class Duration, class Alloc = allocator<charT>>
basic_istream<charT, traits>&
from_stream(basic_istream<charT, traits>& is, const charT* fmt,
local_time<Duration>& tp, basic_string<charT, traits, Alloc>* abbrev = nullptr,
minutes* offset = nullptr);
`
[4](#4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L3552)
*Effects*: Attempts to parse the input stream is into the local_time tp using
the format flags given in the NTCTS fmt as specified in [[time.parse]](time.parse "30.13Parsing")[.](#4.sentence-1)
If the parse fails to decode a valid date,is.setstate(ios_base::failbit) is called andtp is not modified[.](#4.sentence-2)
If %Z is used and successfully parsed,
that value will be assigned to *abbrev if abbrev is non-null[.](#4.sentence-3)
If %z (or a modified variant) is used and successfully parsed,
that value will be assigned to *offset if offset is non-null[.](#4.sentence-4)
[5](#5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L3566)
*Returns*: is[.](#5.sentence-1)

View File

@@ -0,0 +1,83 @@
[time.clock.req]
# 30 Time library [[time]](./#time)
## 30.3 *Cpp17Clock* requirements [time.clock.req]
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L976)
A clock is a bundle consisting of a duration, atime_point, and a function now() to get the current time_point[.](#1.sentence-1)
The origin of the clock's time_point is referred to as the clock's [*epoch*](#def:epoch "30.3Cpp17Clock requirements[time.clock.req]")[.](#1.sentence-2)
A clock shall meet the requirements in Table [131](#tab:time.clock "Table 131: Cpp17Clock requirements")[.](#1.sentence-3)
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L982)
In Table [131](#tab:time.clock "Table 131: Cpp17Clock requirements") C1 and C2 denote clock types[.](#2.sentence-1)
t1 andt2 are values returned by C1::now() where the call returning t1 happens
before ([[intro.multithread]](intro.multithread "6.10.2Multi-threaded executions and data races")) the call returning t2 and both of these calls
occur
before C1::time_point::max()[.](#2.sentence-2)
[*Note [1](#note-1)*:
This means C1 did not wrap around between t1 andt2[.](#2.sentence-3)
— *end note*]
Table [131](#tab:time.clock) — *Cpp17Clock* requirements [[tab:time.clock]](./tab:time.clock)
| [🔗](#tab:time.clock-row-1)<br>**Expression** | **Return type** | **Operational semantics** |
| --- | --- | --- |
| [🔗](#tab:time.clock-row-2)<br>C1::rep | An arithmetic type or a class emulating an arithmetic type | The representation type of C1::duration[.](#tab:time.clock-row-2-column-3-sentence-1) |
| [🔗](#tab:time.clock-row-3)<br>C1::period | a specialization of ratio | The tick period of the clock in seconds[.](#tab:time.clock-row-3-column-3-sentence-1) |
| [🔗](#tab:time.clock-row-4)<br>C1::duration | chrono::duration<C1::rep, C1::period> | The duration type of the clock[.](#tab:time.clock-row-4-column-3-sentence-1) |
| [🔗](#tab:time.clock-row-5)<br>C1::time_point | chrono::time_point<C1> or chrono::time_point<C2, C1::duration> | The time_point type of the clock[.](#tab:time.clock-row-5-column-3-sentence-1)<br>C1 and C2 shall refer to the same epoch[.](#tab:time.clock-row-5-column-3-sentence-2) |
| [🔗](#tab:time.clock-row-6)<br>C1::is_steady | const bool | true if t1 <= t2 is always true and the time between clock ticks is constant, otherwise false[.](#tab:time.clock-row-6-column-3-sentence-1) |
| [🔗](#tab:time.clock-row-7)<br>C1::now() | C1::time_point | Returns a time_point object representing the current point in time[.](#tab:time.clock-row-7-column-3-sentence-1) |
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L1032)
[*Note [2](#note-2)*:
The relative difference in durations between those reported by a given clock and the
SI definition is a measure of the quality of implementation[.](#3.sentence-1)
— *end note*]
[4](#4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L1038)
A type TC meets the *Cpp17TrivialClock* requirements if
- [(4.1)](#4.1)
TC meets the [*Cpp17Clock*](#:Cpp17Clock "30.3Cpp17Clock requirements[time.clock.req]") requirements,
- [(4.2)](#4.2)
the types TC::rep, TC::duration, and TC::time_point meet the [*Cpp17EqualityComparable*](utility.arg.requirements#:Cpp17EqualityComparable "16.4.4.2Template argument requirements[utility.arg.requirements]") (Table [28](utility.arg.requirements#tab:cpp17.equalitycomparable "Table 28: Cpp17EqualityComparable requirements")) and[*Cpp17LessThanComparable*](utility.arg.requirements#:Cpp17LessThanComparable "16.4.4.2Template argument requirements[utility.arg.requirements]") (Table [29](utility.arg.requirements#tab:cpp17.lessthancomparable "Table 29: Cpp17LessThanComparable requirements"))
and [*Cpp17Swappable*](swappable.requirements#:Cpp17Swappable "16.4.4.3Swappable requirements[swappable.requirements]") ([[swappable.requirements]](swappable.requirements "16.4.4.3Swappable requirements"))
requirements and the requirements of
numeric types ([[numeric.requirements]](numeric.requirements "29.2Numeric type requirements")),
[*Note [3](#note-3)*:
This means, in particular,
that operations on these types will not throw exceptions[.](#4.2.sentence-1)
— *end note*]
- [(4.3)](#4.3)
the function TC::now() does not throw exceptions, and
- [(4.4)](#4.4)
the type TC::time_point::clock meets the *Cpp17TrivialClock* requirements, recursively[.](#4.sentence-1)

View File

@@ -0,0 +1,18 @@
[time.clock.steady]
# 30 Time library [[time]](./#time)
## 30.7 Clocks [[time.clock]](time.clock#steady)
### 30.7.7 Class steady_clock [time.clock.steady]
namespace std::chrono {class steady_clock {public:using rep = *unspecified*; using period = ratio<*unspecified*, *unspecified*>; using duration = chrono::duration<rep, period>; using time_point = chrono::time_point<*unspecified*, duration>; static constexpr bool is_steady = true; static time_point now() noexcept; };}
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L3480)
Objects of class steady_clock represent clocks for which values of time_point never decrease as physical time advances and for which values of time_point advance at
a steady rate relative to real time[.](#1.sentence-1)
That is, the clock may not be adjusted[.](#1.sentence-2)

View File

@@ -0,0 +1,166 @@
[time.clock.system]
# 30 Time library [[time]](./#time)
## 30.7 Clocks [[time.clock]](time.clock#system)
### 30.7.2 Class system_clock [time.clock.system]
#### [30.7.2.1](#overview) Overview [[time.clock.system.overview]](time.clock.system.overview)
namespace std::chrono {class system_clock {public:using rep = *see below*; using period = ratio<*unspecified*, *unspecified*>; using duration = chrono::duration<rep, period>; using time_point = chrono::time_point<system_clock>; static constexpr bool is_steady = *unspecified*; static time_point now() noexcept; // mapping to/from C type time_tstatic time_t to_time_t (const time_point& t) noexcept; static time_point from_time_t(time_t t) noexcept; };}
[1](#overview-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L2663)
Objects of type system_clock represent wall clock time from the system-wide
realtime clock[.](#overview-1.sentence-1)
Objects of type sys_time<Duration> measure time since
1970-01-01 00:00:00 UTC excluding leap seconds[.](#overview-1.sentence-2)
This measure is commonly referred to as [*Unix time*](#def:Unix_time "30.7.2.1Overview[time.clock.system.overview]")[.](#overview-1.sentence-3)
This measure facilitates an efficient mapping betweensys_time and calendar types ([[time.cal]](time.cal "30.8The civil calendar"))[.](#overview-1.sentence-4)
[*Example [1](#overview-example-1)*:
sys_seconds{sys_days{1970y/January/1}}.time_since_epoch() is 0s[.](#overview-1.sentence-5)
sys_seconds{sys_days{2000y/January/1}}.time_since_epoch() is 946'684'800s,
which is 10'957 * 86'400s[.](#overview-1.sentence-6)
— *end example*]
#### [30.7.2.2](#members) Members [[time.clock.system.members]](time.clock.system.members)
[🔗](#lib:rep,system_clock)
`using system_clock::rep = unspecified;
`
[1](#members-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L2686)
*Constraints*: system_clock::duration::min() < system_clock::duration::zero() is true[.](#members-1.sentence-1)
[*Note [1](#members-note-1)*:
This implies that rep is a signed type[.](#members-1.sentence-2)
— *end note*]
[🔗](#lib:to_time_t,system_clock)
`static time_t to_time_t(const time_point& t) noexcept;
`
[2](#members-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L2700)
*Returns*: A time_t object that represents the same point in time as t when both values are restricted to the coarser of the precisions of time_t andtime_point[.](#members-2.sentence-1)
It is implementation-defined
whether values are rounded or truncated to the required precision[.](#members-2.sentence-2)
[🔗](#lib:from_time_t,system_clock)
`static time_point from_time_t(time_t t) noexcept;
`
[3](#members-3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L2716)
*Returns*: A time_point object that represents the same point in time as t when both values are restricted to the coarser of the precisions of time_t andtime_point[.](#members-3.sentence-1)
It is implementation-defined
whether values are rounded or truncated to the required precision[.](#members-3.sentence-2)
#### [30.7.2.3](#nonmembers) Non-member functions [[time.clock.system.nonmembers]](time.clock.system.nonmembers)
[🔗](#lib:operator%3c%3c,sys_time)
`template<class charT, class traits, class Duration>
basic_ostream<charT, traits>&
operator<<(basic_ostream<charT, traits>& os, const sys_time<Duration>& tp);
`
[1](#nonmembers-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L2736)
*Constraints*: treat_as_floating_point_v<typename Duration::rep> is false, andDuration{1} < days{1} is true[.](#nonmembers-1.sentence-1)
[2](#nonmembers-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L2741)
*Effects*: Equivalent to:return os << format(os.getloc(), *STATICALLY-WIDEN*<charT>("{:L%F %T}"), tp);
[3](#nonmembers-3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L2748)
[*Example [1](#nonmembers-example-1)*: cout << sys_seconds{0s} << '\n'; // 1970-01-01 00:00:00 cout << sys_seconds{946'684'800s} << '\n'; // 2000-01-01 00:00:00 cout << sys_seconds{946'688'523s} << '\n'; // 2000-01-01 01:02:03 — *end example*]
[🔗](#lib:operator%3c%3c,sys_days)
`template<class charT, class traits>
basic_ostream<charT, traits>&
operator<<(basic_ostream<charT, traits>& os, const sys_days& dp);
`
[4](#nonmembers-4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L2766)
*Effects*: os << year_month_day{dp}[.](#nonmembers-4.sentence-1)
[5](#nonmembers-5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L2770)
*Returns*: os[.](#nonmembers-5.sentence-1)
[🔗](#lib:from_stream,sys_time)
`template<class charT, class traits, class Duration, class Alloc = allocator<charT>>
basic_istream<charT, traits>&
from_stream(basic_istream<charT, traits>& is, const charT* fmt,
sys_time<Duration>& tp, basic_string<charT, traits, Alloc>* abbrev = nullptr,
minutes* offset = nullptr);
`
[6](#nonmembers-6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L2785)
*Effects*: Attempts to parse the input stream is into the sys_time tp using
the format flags given in the NTCTS fmt as specified in [[time.parse]](time.parse "30.13Parsing")[.](#nonmembers-6.sentence-1)
If the parse fails to decode a valid date,is.setstate(ios_base::failbit) is called andtp is not modified[.](#nonmembers-6.sentence-2)
If %Z is used and successfully parsed,
that value will be assigned to *abbrev if abbrev is non-null[.](#nonmembers-6.sentence-3)
If %z (or a modified variant) is used and successfully parsed,
that value will be assigned to *offset if offset is non-null[.](#nonmembers-6.sentence-4)
Additionally, the parsed offset will be subtracted
from the successfully parsed timestamp
prior to assigning that difference to tp[.](#nonmembers-6.sentence-5)
[7](#nonmembers-7)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L2802)
*Returns*: is[.](#nonmembers-7.sentence-1)

View File

@@ -0,0 +1,54 @@
[time.clock.system.members]
# 30 Time library [[time]](./#time)
## 30.7 Clocks [[time.clock]](time.clock#system.members)
### 30.7.2 Class system_clock [[time.clock.system]](time.clock.system#members)
#### 30.7.2.2 Members [time.clock.system.members]
[🔗](#lib:rep,system_clock)
`using system_clock::rep = unspecified;
`
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L2686)
*Constraints*: system_clock::duration::min() < system_clock::duration::zero() is true[.](#1.sentence-1)
[*Note [1](#note-1)*:
This implies that rep is a signed type[.](#1.sentence-2)
— *end note*]
[🔗](#lib:to_time_t,system_clock)
`static time_t to_time_t(const time_point& t) noexcept;
`
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L2700)
*Returns*: A time_t object that represents the same point in time as t when both values are restricted to the coarser of the precisions of time_t andtime_point[.](#2.sentence-1)
It is implementation-defined
whether values are rounded or truncated to the required precision[.](#2.sentence-2)
[🔗](#lib:from_time_t,system_clock)
`static time_point from_time_t(time_t t) noexcept;
`
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L2716)
*Returns*: A time_point object that represents the same point in time as t when both values are restricted to the coarser of the precisions of time_t andtime_point[.](#3.sentence-1)
It is implementation-defined
whether values are rounded or truncated to the required precision[.](#3.sentence-2)

View File

@@ -0,0 +1,87 @@
[time.clock.system.nonmembers]
# 30 Time library [[time]](./#time)
## 30.7 Clocks [[time.clock]](time.clock#system.nonmembers)
### 30.7.2 Class system_clock [[time.clock.system]](time.clock.system#nonmembers)
#### 30.7.2.3 Non-member functions [time.clock.system.nonmembers]
[🔗](#lib:operator%3c%3c,sys_time)
`template<class charT, class traits, class Duration>
basic_ostream<charT, traits>&
operator<<(basic_ostream<charT, traits>& os, const sys_time<Duration>& tp);
`
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L2736)
*Constraints*: treat_as_floating_point_v<typename Duration::rep> is false, andDuration{1} < days{1} is true[.](#1.sentence-1)
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L2741)
*Effects*: Equivalent to:return os << format(os.getloc(), *STATICALLY-WIDEN*<charT>("{:L%F %T}"), tp);
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L2748)
[*Example [1](#example-1)*: cout << sys_seconds{0s} << '\n'; // 1970-01-01 00:00:00 cout << sys_seconds{946'684'800s} << '\n'; // 2000-01-01 00:00:00 cout << sys_seconds{946'688'523s} << '\n'; // 2000-01-01 01:02:03 — *end example*]
[🔗](#lib:operator%3c%3c,sys_days)
`template<class charT, class traits>
basic_ostream<charT, traits>&
operator<<(basic_ostream<charT, traits>& os, const sys_days& dp);
`
[4](#4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L2766)
*Effects*: os << year_month_day{dp}[.](#4.sentence-1)
[5](#5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L2770)
*Returns*: os[.](#5.sentence-1)
[🔗](#lib:from_stream,sys_time)
`template<class charT, class traits, class Duration, class Alloc = allocator<charT>>
basic_istream<charT, traits>&
from_stream(basic_istream<charT, traits>& is, const charT* fmt,
sys_time<Duration>& tp, basic_string<charT, traits, Alloc>* abbrev = nullptr,
minutes* offset = nullptr);
`
[6](#6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L2785)
*Effects*: Attempts to parse the input stream is into the sys_time tp using
the format flags given in the NTCTS fmt as specified in [[time.parse]](time.parse "30.13Parsing")[.](#6.sentence-1)
If the parse fails to decode a valid date,is.setstate(ios_base::failbit) is called andtp is not modified[.](#6.sentence-2)
If %Z is used and successfully parsed,
that value will be assigned to *abbrev if abbrev is non-null[.](#6.sentence-3)
If %z (or a modified variant) is used and successfully parsed,
that value will be assigned to *offset if offset is non-null[.](#6.sentence-4)
Additionally, the parsed offset will be subtracted
from the successfully parsed timestamp
prior to assigning that difference to tp[.](#6.sentence-5)
[7](#7)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L2802)
*Returns*: is[.](#7.sentence-1)

View File

@@ -0,0 +1,39 @@
[time.clock.system.overview]
# 30 Time library [[time]](./#time)
## 30.7 Clocks [[time.clock]](time.clock#system.overview)
### 30.7.2 Class system_clock [[time.clock.system]](time.clock.system#overview)
#### 30.7.2.1 Overview [time.clock.system.overview]
namespace std::chrono {class system_clock {public:using rep = *see below*; using period = ratio<*unspecified*, *unspecified*>; using duration = chrono::duration<rep, period>; using time_point = chrono::time_point<system_clock>; static constexpr bool is_steady = *unspecified*; static time_point now() noexcept; // mapping to/from C type time_tstatic time_t to_time_t (const time_point& t) noexcept; static time_point from_time_t(time_t t) noexcept; };}
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L2663)
Objects of type system_clock represent wall clock time from the system-wide
realtime clock[.](#1.sentence-1)
Objects of type sys_time<Duration> measure time since
1970-01-01 00:00:00 UTC excluding leap seconds[.](#1.sentence-2)
This measure is commonly referred to as [*Unix time*](#def:Unix_time "30.7.2.1Overview[time.clock.system.overview]")[.](#1.sentence-3)
This measure facilitates an efficient mapping betweensys_time and calendar types ([[time.cal]](time.cal "30.8The civil calendar"))[.](#1.sentence-4)
[*Example [1](#example-1)*:
sys_seconds{sys_days{1970y/January/1}}.time_since_epoch() is 0s[.](#1.sentence-5)
sys_seconds{sys_days{2000y/January/1}}.time_since_epoch() is 946'684'800s,
which is 10'957 * 86'400s[.](#1.sentence-6)
— *end example*]

149
cppdraft/time/clock/tai.md Normal file
View File

@@ -0,0 +1,149 @@
[time.clock.tai]
# 30 Time library [[time]](./#time)
## 30.7 Clocks [[time.clock]](time.clock#tai)
### 30.7.4 Class tai_clock [time.clock.tai]
#### [30.7.4.1](#overview) Overview [[time.clock.tai.overview]](time.clock.tai.overview)
namespace std::chrono {class tai_clock {public:using rep = *a signed arithmetic type*; using period = ratio<*unspecified*, *unspecified*>; using duration = chrono::duration<rep, period>; using time_point = chrono::time_point<tai_clock>; static constexpr bool is_steady = *unspecified*; static time_point now(); template<class Duration>static utc_time<common_type_t<Duration, seconds>> to_utc(const tai_time<Duration>&) noexcept; template<class Duration>static tai_time<common_type_t<Duration, seconds>> from_utc(const utc_time<Duration>&) noexcept; };}
[1](#overview-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L3059)
The clock tai_clock measures seconds since 1958-01-01 00:00:00
and is offset 10s ahead of UTC at this date[.](#overview-1.sentence-1)
That is, 1958-01-01 00:00:00 TAI is equivalent to 1957-12-31 23:59:50 UTC[.](#overview-1.sentence-2)
Leap seconds are not inserted into TAI[.](#overview-1.sentence-3)
Therefore every time a leap second is inserted into UTC,
UTC shifts another second with respect to TAI[.](#overview-1.sentence-4)
For example by 2000-01-01 there had been
22 positive and 0 negative leap seconds inserted
so 2000-01-01 00:00:00 UTC is equivalent to 2000-01-01 00:00:32 TAI
(22s plus the initial 10s offset)[.](#overview-1.sentence-5)
[2](#overview-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L3071)
tai_clock is not a [*Cpp17TrivialClock*](time.clock.req#:Cpp17TrivialClock "30.3Cpp17Clock requirements[time.clock.req]") unless the implementation can guarantee that tai_clock::now() does not propagate an exception[.](#overview-2.sentence-1)
[*Note [1](#overview-note-1)*:
noexcept(from_utc(utc_clock::now())) is false[.](#overview-2.sentence-2)
— *end note*]
#### [30.7.4.2](#members) Member functions [[time.clock.tai.members]](time.clock.tai.members)
[🔗](#lib:now,tai_clock)
`static time_point now();
`
[1](#members-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L3087)
*Returns*: from_utc(utc_clock::now()), or a more accurate value of tai_time[.](#members-1.sentence-1)
[🔗](#lib:to_utc,tai_clock)
`template<class Duration>
static utc_time<common_type_t<Duration, seconds>>
to_utc(const tai_time<Duration>& t) noexcept;
`
[2](#members-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L3100)
*Returns*: utc_time<common_type_t<Duration, seconds>>{t.time_since_epoch()} - 378691210s
[*Note [1](#members-note-1)*: 378691210s == sys_days{1970y/January/1} - sys_days{1958y/January/1} + 10s — *end note*]
[🔗](#lib:from_utc,tai_clock)
`template<class Duration>
static tai_time<common_type_t<Duration, seconds>>
from_utc(const utc_time<Duration>& t) noexcept;
`
[3](#members-3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L3120)
*Returns*: tai_time<common_type_t<Duration, seconds>>{t.time_since_epoch()} + 378691210s
[*Note [2](#members-note-2)*: 378691210s == sys_days{1970y/January/1} - sys_days{1958y/January/1} + 10s — *end note*]
#### [30.7.4.3](#nonmembers) Non-member functions [[time.clock.tai.nonmembers]](time.clock.tai.nonmembers)
[🔗](#lib:operator%3c%3c,tai_time)
`template<class charT, class traits, class Duration>
basic_ostream<charT, traits>&
operator<<(basic_ostream<charT, traits>& os, const tai_time<Duration>& t);
`
[1](#nonmembers-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L3142)
*Effects*: Equivalent to:return os << format(os.getloc(), *STATICALLY-WIDEN*<charT>("{:L%F %T}"), t);
[2](#nonmembers-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L3149)
[*Example [1](#nonmembers-example-1)*: auto st = sys_days{2000y/January/1};auto tt = clock_cast<tai_clock>(st);
cout << format("{0:%F %T %Z} == {1:%F %T %Z}\n", st, tt);
Produces this output:
```
2000-01-01 00:00:00 UTC == 2000-01-01 00:00:32 TAI
```
— *end example*]
[🔗](#lib:from_stream,tai_time)
`template<class charT, class traits, class Duration, class Alloc = allocator<charT>>
basic_istream<charT, traits>&
from_stream(basic_istream<charT, traits>& is, const charT* fmt,
tai_time<Duration>& tp, basic_string<charT, traits, Alloc>* abbrev = nullptr,
minutes* offset = nullptr);
`
[3](#nonmembers-3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L3175)
*Effects*: Attempts to parse the input stream is into the tai_time tp using
the format flags given in the NTCTS fmt as specified in [[time.parse]](time.parse "30.13Parsing")[.](#nonmembers-3.sentence-1)
If the parse fails to decode a valid date,is.setstate(ios_base::failbit) is called andtp is not modified[.](#nonmembers-3.sentence-2)
If %Z is used and successfully parsed,
that value will be assigned to *abbrev if abbrev is non-null[.](#nonmembers-3.sentence-3)
If %z (or a modified variant) is used and successfully parsed,
that value will be assigned to *offset if offset is non-null[.](#nonmembers-3.sentence-4)
Additionally, the parsed offset will be subtracted from
the successfully parsed timestamp prior to assigning that difference to tp[.](#nonmembers-3.sentence-5)
[4](#nonmembers-4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L3191)
*Returns*: is[.](#nonmembers-4.sentence-1)

View File

@@ -0,0 +1,50 @@
[time.clock.tai.members]
# 30 Time library [[time]](./#time)
## 30.7 Clocks [[time.clock]](time.clock#tai.members)
### 30.7.4 Class tai_clock [[time.clock.tai]](time.clock.tai#members)
#### 30.7.4.2 Member functions [time.clock.tai.members]
[🔗](#lib:now,tai_clock)
`static time_point now();
`
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L3087)
*Returns*: from_utc(utc_clock::now()), or a more accurate value of tai_time[.](#1.sentence-1)
[🔗](#lib:to_utc,tai_clock)
`template<class Duration>
static utc_time<common_type_t<Duration, seconds>>
to_utc(const tai_time<Duration>& t) noexcept;
`
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L3100)
*Returns*: utc_time<common_type_t<Duration, seconds>>{t.time_since_epoch()} - 378691210s
[*Note [1](#note-1)*: 378691210s == sys_days{1970y/January/1} - sys_days{1958y/January/1} + 10s — *end note*]
[🔗](#lib:from_utc,tai_clock)
`template<class Duration>
static tai_time<common_type_t<Duration, seconds>>
from_utc(const utc_time<Duration>& t) noexcept;
`
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L3120)
*Returns*: tai_time<common_type_t<Duration, seconds>>{t.time_since_epoch()} + 378691210s
[*Note [2](#note-2)*: 378691210s == sys_days{1970y/January/1} - sys_days{1958y/January/1} + 10s — *end note*]

View File

@@ -0,0 +1,71 @@
[time.clock.tai.nonmembers]
# 30 Time library [[time]](./#time)
## 30.7 Clocks [[time.clock]](time.clock#tai.nonmembers)
### 30.7.4 Class tai_clock [[time.clock.tai]](time.clock.tai#nonmembers)
#### 30.7.4.3 Non-member functions [time.clock.tai.nonmembers]
[🔗](#lib:operator%3c%3c,tai_time)
`template<class charT, class traits, class Duration>
basic_ostream<charT, traits>&
operator<<(basic_ostream<charT, traits>& os, const tai_time<Duration>& t);
`
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L3142)
*Effects*: Equivalent to:return os << format(os.getloc(), *STATICALLY-WIDEN*<charT>("{:L%F %T}"), t);
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L3149)
[*Example [1](#example-1)*: auto st = sys_days{2000y/January/1};auto tt = clock_cast<tai_clock>(st);
cout << format("{0:%F %T %Z} == {1:%F %T %Z}\n", st, tt);
Produces this output:
```
2000-01-01 00:00:00 UTC == 2000-01-01 00:00:32 TAI
```
— *end example*]
[🔗](#lib:from_stream,tai_time)
`template<class charT, class traits, class Duration, class Alloc = allocator<charT>>
basic_istream<charT, traits>&
from_stream(basic_istream<charT, traits>& is, const charT* fmt,
tai_time<Duration>& tp, basic_string<charT, traits, Alloc>* abbrev = nullptr,
minutes* offset = nullptr);
`
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L3175)
*Effects*: Attempts to parse the input stream is into the tai_time tp using
the format flags given in the NTCTS fmt as specified in [[time.parse]](time.parse "30.13Parsing")[.](#3.sentence-1)
If the parse fails to decode a valid date,is.setstate(ios_base::failbit) is called andtp is not modified[.](#3.sentence-2)
If %Z is used and successfully parsed,
that value will be assigned to *abbrev if abbrev is non-null[.](#3.sentence-3)
If %z (or a modified variant) is used and successfully parsed,
that value will be assigned to *offset if offset is non-null[.](#3.sentence-4)
Additionally, the parsed offset will be subtracted from
the successfully parsed timestamp prior to assigning that difference to tp[.](#3.sentence-5)
[4](#4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L3191)
*Returns*: is[.](#4.sentence-1)

View File

@@ -0,0 +1,42 @@
[time.clock.tai.overview]
# 30 Time library [[time]](./#time)
## 30.7 Clocks [[time.clock]](time.clock#tai.overview)
### 30.7.4 Class tai_clock [[time.clock.tai]](time.clock.tai#overview)
#### 30.7.4.1 Overview [time.clock.tai.overview]
namespace std::chrono {class tai_clock {public:using rep = *a signed arithmetic type*; using period = ratio<*unspecified*, *unspecified*>; using duration = chrono::duration<rep, period>; using time_point = chrono::time_point<tai_clock>; static constexpr bool is_steady = *unspecified*; static time_point now(); template<class Duration>static utc_time<common_type_t<Duration, seconds>> to_utc(const tai_time<Duration>&) noexcept; template<class Duration>static tai_time<common_type_t<Duration, seconds>> from_utc(const utc_time<Duration>&) noexcept; };}
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L3059)
The clock tai_clock measures seconds since 1958-01-01 00:00:00
and is offset 10s ahead of UTC at this date[.](#1.sentence-1)
That is, 1958-01-01 00:00:00 TAI is equivalent to 1957-12-31 23:59:50 UTC[.](#1.sentence-2)
Leap seconds are not inserted into TAI[.](#1.sentence-3)
Therefore every time a leap second is inserted into UTC,
UTC shifts another second with respect to TAI[.](#1.sentence-4)
For example by 2000-01-01 there had been
22 positive and 0 negative leap seconds inserted
so 2000-01-01 00:00:00 UTC is equivalent to 2000-01-01 00:00:32 TAI
(22s plus the initial 10s offset)[.](#1.sentence-5)
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L3071)
tai_clock is not a [*Cpp17TrivialClock*](time.clock.req#:Cpp17TrivialClock "30.3Cpp17Clock requirements[time.clock.req]") unless the implementation can guarantee that tai_clock::now() does not propagate an exception[.](#2.sentence-1)
[*Note [1](#note-1)*:
noexcept(from_utc(utc_clock::now())) is false[.](#2.sentence-2)
— *end note*]

220
cppdraft/time/clock/utc.md Normal file
View File

@@ -0,0 +1,220 @@
[time.clock.utc]
# 30 Time library [[time]](./#time)
## 30.7 Clocks [[time.clock]](time.clock#utc)
### 30.7.3 Class utc_clock [time.clock.utc]
#### [30.7.3.1](#overview) Overview [[time.clock.utc.overview]](time.clock.utc.overview)
namespace std::chrono {class utc_clock {public:using rep = *a signed arithmetic type*; using period = ratio<*unspecified*, *unspecified*>; using duration = chrono::duration<rep, period>; using time_point = chrono::time_point<utc_clock>; static constexpr bool is_steady = *unspecified*; static time_point now(); template<class Duration>static sys_time<common_type_t<Duration, seconds>> to_sys(const utc_time<Duration>& t); template<class Duration>static utc_time<common_type_t<Duration, seconds>> from_sys(const sys_time<Duration>& t); };}
[1](#overview-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L2834)
In contrast to sys_time,
which does not take leap seconds into account,utc_clock and its associated time_point, utc_time,
count time, including leap seconds, since 1970-01-01 00:00:00 UTC.
[*Note [1](#overview-note-1)*:
The UTC time standard began on 1972-01-01 00:00:10 TAI.
To measure time since this epoch instead, one can add/subtract the constantsys_days{1972y/1/1} - sys_days{1970y/1/1} (63'072'000s)
from the utc_time[.](#overview-1.sentence-1)
— *end note*]
[*Example [1](#overview-example-1)*:
clock_cast<utc_clock>(sys_seconds{sys_days{1970y/January/1}}).time_since_epoch() is 0s[.](#overview-1.sentence-2)
clock_cast<utc_clock>(sys_seconds{sys_days{2000y/January/1}}).time_since_epoch() is 946'684'822s,
which is 10'957 * 86'400s + 22s[.](#overview-1.sentence-4)
— *end example*]
[2](#overview-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L2852)
utc_clock is not a [*Cpp17TrivialClock*](time.clock.req#:Cpp17TrivialClock "30.3Cpp17Clock requirements[time.clock.req]") unless the implementation can guarantee that utc_clock::now() does not propagate an exception[.](#overview-2.sentence-1)
[*Note [2](#overview-note-2)*:
noexcept(from_sys(system_clock::now())) is false[.](#overview-2.sentence-2)
— *end note*]
#### [30.7.3.2](#members) Member functions [[time.clock.utc.members]](time.clock.utc.members)
[🔗](#lib:now,utc_clock)
`static time_point now();
`
[1](#members-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L2868)
*Returns*: from_sys(system_clock::now()), or a more accurate value of utc_time[.](#members-1.sentence-1)
[🔗](#lib:to_sys,utc_clock)
`template<class Duration>
static sys_time<common_type_t<Duration, seconds>>
to_sys(const utc_time<Duration>& u);
`
[2](#members-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L2881)
*Returns*: A sys_time t,
such that from_sys(t) == u if such a mapping exists[.](#members-2.sentence-1)
Otherwise u represents a time_point during a positive leap second insertion,
the conversion counts that leap second as not inserted,
and the last representable value of sys_time prior to the insertion of the leap second is returned[.](#members-2.sentence-2)
[🔗](#lib:from_sys,utc_clock)
`template<class Duration>
static utc_time<common_type_t<Duration, seconds>>
from_sys(const sys_time<Duration>& t);
`
[3](#members-3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L2900)
*Returns*: A utc_time u, such thatu.time_since_epoch() - t.time_since_epoch() is equal to the sum of leap seconds that were inserted
between t and 1970-01-01[.](#members-3.sentence-1)
If t is exactly the date of leap second insertion,
then the conversion counts that leap second as inserted[.](#members-3.sentence-2)
[*Example [1](#members-example-1)*: auto t = sys_days{July/1/2015} - 2ns;auto u = utc_clock::from_sys(t);
assert(u.time_since_epoch() - t.time_since_epoch() == 25s);
t += 1ns;
u = utc_clock::from_sys(t);
assert(u.time_since_epoch() - t.time_since_epoch() == 25s);
t += 1ns;
u = utc_clock::from_sys(t);
assert(u.time_since_epoch() - t.time_since_epoch() == 26s);
t += 1ns;
u = utc_clock::from_sys(t);
assert(u.time_since_epoch() - t.time_since_epoch() == 26s); — *end example*]
#### [30.7.3.3](#nonmembers) Non-member functions [[time.clock.utc.nonmembers]](time.clock.utc.nonmembers)
[🔗](#lib:operator%3c%3c,utc_time)
`template<class charT, class traits, class Duration>
basic_ostream<charT, traits>&
operator<<(basic_ostream<charT, traits>& os, const utc_time<Duration>& t);
`
[1](#nonmembers-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L2937)
*Effects*: Equivalent to:return os << format(os.getloc(), *STATICALLY-WIDEN*<charT>("{:L%F %T}"), t);
[2](#nonmembers-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L2944)
[*Example [1](#nonmembers-example-1)*: auto t = sys_days{July/1/2015} - 500ms;auto u = clock_cast<utc_clock>(t);for (auto i = 0; i < 8; ++i, u += 250ms) cout << u << " UTC\n";
Produces this output:
```
2015-06-30 23:59:59.500 UTC
2015-06-30 23:59:59.750 UTC
2015-06-30 23:59:60.000 UTC
2015-06-30 23:59:60.250 UTC
2015-06-30 23:59:60.500 UTC
2015-06-30 23:59:60.750 UTC
2015-07-01 00:00:00.000 UTC
2015-07-01 00:00:00.250 UTC
```
— *end example*]
[🔗](#lib:from_stream,utc_time)
`template<class charT, class traits, class Duration, class Alloc = allocator<charT>>
basic_istream<charT, traits>&
from_stream(basic_istream<charT, traits>& is, const charT* fmt,
utc_time<Duration>& tp, basic_string<charT, traits, Alloc>* abbrev = nullptr,
minutes* offset = nullptr);
`
[3](#nonmembers-3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L2977)
*Effects*: Attempts to parse the input stream is into the utc_time tp using
the format flags given in the NTCTS fmt as specified in [[time.parse]](time.parse "30.13Parsing")[.](#nonmembers-3.sentence-1)
If the parse fails to decode a valid date,is.setstate(ios_base::failbit) is called andtp is not modified[.](#nonmembers-3.sentence-2)
If %Z is used and successfully parsed,
that value will be assigned to *abbrev if abbrev is non-null[.](#nonmembers-3.sentence-3)
If %z (or a modified variant) is used and successfully parsed,
that value will be assigned to *offset if offset is non-null[.](#nonmembers-3.sentence-4)
Additionally, the parsed offset will be subtracted from
the successfully parsed timestamp
prior to assigning that difference to tp[.](#nonmembers-3.sentence-5)
[4](#nonmembers-4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L2994)
*Returns*: is[.](#nonmembers-4.sentence-1)
[🔗](#lib:leap_second_info)
`struct leap_second_info {
bool is_leap_second;
seconds elapsed;
};
`
[5](#nonmembers-5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L3008)
The type leap_second_info has data members and special members specified above[.](#nonmembers-5.sentence-1)
It has no base classes or members other than those specified[.](#nonmembers-5.sentence-2)
[🔗](#lib:get_leap_second_info)
`template<class Duration>
leap_second_info get_leap_second_info(const utc_time<Duration>& ut);
`
[6](#nonmembers-6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L3021)
*Returns*: A leap_second_info lsi,
where lsi.is_leap_second is true if ut is during a positive leap second insertion, and
otherwise false[.](#nonmembers-6.sentence-1)
lsi.elapsed is the sum of leap seconds between 1970-01-01 and ut[.](#nonmembers-6.sentence-2)
If lsi.is_leap_second is true,
the leap second referred to by ut is included in the sum[.](#nonmembers-6.sentence-3)

View File

@@ -0,0 +1,67 @@
[time.clock.utc.members]
# 30 Time library [[time]](./#time)
## 30.7 Clocks [[time.clock]](time.clock#utc.members)
### 30.7.3 Class utc_clock [[time.clock.utc]](time.clock.utc#members)
#### 30.7.3.2 Member functions [time.clock.utc.members]
[🔗](#lib:now,utc_clock)
`static time_point now();
`
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L2868)
*Returns*: from_sys(system_clock::now()), or a more accurate value of utc_time[.](#1.sentence-1)
[🔗](#lib:to_sys,utc_clock)
`template<class Duration>
static sys_time<common_type_t<Duration, seconds>>
to_sys(const utc_time<Duration>& u);
`
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L2881)
*Returns*: A sys_time t,
such that from_sys(t) == u if such a mapping exists[.](#2.sentence-1)
Otherwise u represents a time_point during a positive leap second insertion,
the conversion counts that leap second as not inserted,
and the last representable value of sys_time prior to the insertion of the leap second is returned[.](#2.sentence-2)
[🔗](#lib:from_sys,utc_clock)
`template<class Duration>
static utc_time<common_type_t<Duration, seconds>>
from_sys(const sys_time<Duration>& t);
`
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L2900)
*Returns*: A utc_time u, such thatu.time_since_epoch() - t.time_since_epoch() is equal to the sum of leap seconds that were inserted
between t and 1970-01-01[.](#3.sentence-1)
If t is exactly the date of leap second insertion,
then the conversion counts that leap second as inserted[.](#3.sentence-2)
[*Example [1](#example-1)*: auto t = sys_days{July/1/2015} - 2ns;auto u = utc_clock::from_sys(t);
assert(u.time_since_epoch() - t.time_since_epoch() == 25s);
t += 1ns;
u = utc_clock::from_sys(t);
assert(u.time_since_epoch() - t.time_since_epoch() == 25s);
t += 1ns;
u = utc_clock::from_sys(t);
assert(u.time_since_epoch() - t.time_since_epoch() == 26s);
t += 1ns;
u = utc_clock::from_sys(t);
assert(u.time_since_epoch() - t.time_since_epoch() == 26s); — *end example*]

View File

@@ -0,0 +1,113 @@
[time.clock.utc.nonmembers]
# 30 Time library [[time]](./#time)
## 30.7 Clocks [[time.clock]](time.clock#utc.nonmembers)
### 30.7.3 Class utc_clock [[time.clock.utc]](time.clock.utc#nonmembers)
#### 30.7.3.3 Non-member functions [time.clock.utc.nonmembers]
[🔗](#lib:operator%3c%3c,utc_time)
`template<class charT, class traits, class Duration>
basic_ostream<charT, traits>&
operator<<(basic_ostream<charT, traits>& os, const utc_time<Duration>& t);
`
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L2937)
*Effects*: Equivalent to:return os << format(os.getloc(), *STATICALLY-WIDEN*<charT>("{:L%F %T}"), t);
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L2944)
[*Example [1](#example-1)*: auto t = sys_days{July/1/2015} - 500ms;auto u = clock_cast<utc_clock>(t);for (auto i = 0; i < 8; ++i, u += 250ms) cout << u << " UTC\n";
Produces this output:
```
2015-06-30 23:59:59.500 UTC
2015-06-30 23:59:59.750 UTC
2015-06-30 23:59:60.000 UTC
2015-06-30 23:59:60.250 UTC
2015-06-30 23:59:60.500 UTC
2015-06-30 23:59:60.750 UTC
2015-07-01 00:00:00.000 UTC
2015-07-01 00:00:00.250 UTC
```
— *end example*]
[🔗](#lib:from_stream,utc_time)
`template<class charT, class traits, class Duration, class Alloc = allocator<charT>>
basic_istream<charT, traits>&
from_stream(basic_istream<charT, traits>& is, const charT* fmt,
utc_time<Duration>& tp, basic_string<charT, traits, Alloc>* abbrev = nullptr,
minutes* offset = nullptr);
`
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L2977)
*Effects*: Attempts to parse the input stream is into the utc_time tp using
the format flags given in the NTCTS fmt as specified in [[time.parse]](time.parse "30.13Parsing")[.](#3.sentence-1)
If the parse fails to decode a valid date,is.setstate(ios_base::failbit) is called andtp is not modified[.](#3.sentence-2)
If %Z is used and successfully parsed,
that value will be assigned to *abbrev if abbrev is non-null[.](#3.sentence-3)
If %z (or a modified variant) is used and successfully parsed,
that value will be assigned to *offset if offset is non-null[.](#3.sentence-4)
Additionally, the parsed offset will be subtracted from
the successfully parsed timestamp
prior to assigning that difference to tp[.](#3.sentence-5)
[4](#4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L2994)
*Returns*: is[.](#4.sentence-1)
[🔗](#lib:leap_second_info)
`struct leap_second_info {
bool is_leap_second;
seconds elapsed;
};
`
[5](#5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L3008)
The type leap_second_info has data members and special members specified above[.](#5.sentence-1)
It has no base classes or members other than those specified[.](#5.sentence-2)
[🔗](#lib:get_leap_second_info)
`template<class Duration>
leap_second_info get_leap_second_info(const utc_time<Duration>& ut);
`
[6](#6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L3021)
*Returns*: A leap_second_info lsi,
where lsi.is_leap_second is true if ut is during a positive leap second insertion, and
otherwise false[.](#6.sentence-1)
lsi.elapsed is the sum of leap seconds between 1970-01-01 and ut[.](#6.sentence-2)
If lsi.is_leap_second is true,
the leap second referred to by ut is included in the sum[.](#6.sentence-3)

View File

@@ -0,0 +1,54 @@
[time.clock.utc.overview]
# 30 Time library [[time]](./#time)
## 30.7 Clocks [[time.clock]](time.clock#utc.overview)
### 30.7.3 Class utc_clock [[time.clock.utc]](time.clock.utc#overview)
#### 30.7.3.1 Overview [time.clock.utc.overview]
namespace std::chrono {class utc_clock {public:using rep = *a signed arithmetic type*; using period = ratio<*unspecified*, *unspecified*>; using duration = chrono::duration<rep, period>; using time_point = chrono::time_point<utc_clock>; static constexpr bool is_steady = *unspecified*; static time_point now(); template<class Duration>static sys_time<common_type_t<Duration, seconds>> to_sys(const utc_time<Duration>& t); template<class Duration>static utc_time<common_type_t<Duration, seconds>> from_sys(const sys_time<Duration>& t); };}
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L2834)
In contrast to sys_time,
which does not take leap seconds into account,utc_clock and its associated time_point, utc_time,
count time, including leap seconds, since 1970-01-01 00:00:00 UTC.
[*Note [1](#note-1)*:
The UTC time standard began on 1972-01-01 00:00:10 TAI.
To measure time since this epoch instead, one can add/subtract the constantsys_days{1972y/1/1} - sys_days{1970y/1/1} (63'072'000s)
from the utc_time[.](#1.sentence-1)
— *end note*]
[*Example [1](#example-1)*:
clock_cast<utc_clock>(sys_seconds{sys_days{1970y/January/1}}).time_since_epoch() is 0s[.](#1.sentence-2)
clock_cast<utc_clock>(sys_seconds{sys_days{2000y/January/1}}).time_since_epoch() is 946'684'822s,
which is 10'957 * 86'400s + 22s[.](#1.sentence-4)
— *end example*]
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L2852)
utc_clock is not a [*Cpp17TrivialClock*](time.clock.req#:Cpp17TrivialClock "30.3Cpp17Clock requirements[time.clock.req]") unless the implementation can guarantee that utc_clock::now() does not propagate an exception[.](#2.sentence-1)
[*Note [2](#note-2)*:
noexcept(from_sys(system_clock::now())) is false[.](#2.sentence-2)
— *end note*]