Skip to content

Commit 5bcc9a6

Browse files
committed
feat: [chrono] add day/month/year/duration and some small funcs
1 parent 7c1a029 commit 5bcc9a6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

80 files changed

+7419
-0
lines changed

src/content/docs/cpp/library/chrono.mdx

Lines changed: 524 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
label: Date and time library
Lines changed: 184 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,184 @@
1+
---
2+
title: std::chrono::ambiguous_local_time
3+
cppdoc:
4+
keys: ["cpp.chrono.ambiguous_local_time"]
5+
revision:
6+
since: C++20
7+
---
8+
9+
import { CppHeader } from "@components/header";
10+
import { Decl, DeclDoc } from "@components/decl-doc";
11+
import { Desc, DescList } from "@components/desc-list";
12+
import { ParamDoc, ParamDocList } from "@components/param-doc";
13+
import Missing from "@components/Missing.astro";
14+
import { Revision, RevisionBlock } from "@components/revision";
15+
16+
Defined in header <CppHeader name="chrono" />.
17+
18+
<DeclDoc>
19+
<Decl slot="decl">
20+
<RevisionBlock since="C++20" noborder>
21+
```cpp
22+
class ambiguous_local_time;
23+
```
24+
</RevisionBlock>
25+
</Decl>
26+
27+
Defines a type of object to be thrown as exception to report that an attempt was made to convert an ambiguous <Missing>`std::chrono::local_time`</Missing> to a <Missing>`std::chrono::sys_time`</Missing> without specifying a <Missing>`std::chrono::choose`</Missing> (such as `choose::earliest` or `choose::latest`).
28+
29+
This exception is thrown by <Missing>`std::chrono::time_zone::to_sys`</Missing> and functions that call it (such as the constructors of <Missing>`std::chrono::zoned_time`</Missing> that take a <Missing>`std::chrono::local_time`</Missing>).
30+
</DeclDoc>
31+
32+
## Member functions
33+
34+
<DescList>
35+
<Desc kind="constructor">
36+
<Fragment slot="item">`(constructor)`</Fragment>
37+
constructs the exception object
38+
</Desc>
39+
<Desc kind="function">
40+
<Fragment slot="item">`operator=`</Fragment>
41+
replaces the exception object
42+
</Desc>
43+
<Desc kind="function">
44+
<Fragment slot="item">`what`</Fragment>
45+
returns the explanatory string
46+
</Desc>
47+
</DescList>
48+
49+
## std::chrono::ambiguous_local_time::ambiguous_local_time
50+
51+
<DeclDoc id={1}>
52+
<Decl slot="decl">
53+
<RevisionBlock since="C++20" noborder>
54+
```cpp
55+
template< class Duration >
56+
ambiguous_local_time( const std::chrono::local_time<Duration>& tp,
57+
const std::chrono::local_info& i );
58+
```
59+
</RevisionBlock>
60+
</Decl>
61+
62+
The explanatory string returned by `what()` is equivalent to that produced by `os.str()` after the following code:
63+
64+
```cpp
65+
std::ostringstream os;
66+
os << tp << " is ambiguous. It could be\n"
67+
<< tp << ' ' << i.first.abbrev << " == "
68+
<< tp - i.first.offset << " UTC or\n"
69+
<< tp << ' ' << i.second.abbrev << " == "
70+
<< tp - i.second.offset << " UTC";
71+
```
72+
73+
The behavior is undefined if `i.result != std::chrono::local_info::ambiguous`.
74+
</DeclDoc>
75+
76+
<DeclDoc id={2}>
77+
<Decl slot="decl">
78+
<RevisionBlock since="C++20" noborder>
79+
```cpp
80+
ambiguous_local_time( const ambiguous_local_time& other ) noexcept;
81+
```
82+
</RevisionBlock>
83+
</Decl>
84+
85+
Copy constructor. If `*this` and `other` both have dynamic type `std::chrono::ambiguous_local_time` then `std::strcmp(what(), other.what()) == 0`.
86+
</DeclDoc>
87+
88+
### Parameters
89+
90+
<ParamDocList>
91+
<ParamDoc name="tp">
92+
the time point for which conversion was attempted
93+
</ParamDoc>
94+
<ParamDoc name="i">
95+
a <Missing>`std::chrono::local_info`</Missing> describing the result of the conversion attempt
96+
</ParamDoc>
97+
<ParamDoc name="other">
98+
another `ambiguous_local_time` to copy
99+
</ParamDoc>
100+
</ParamDocList>
101+
102+
### Exceptions
103+
104+
May throw <Missing>`std::bad_alloc`</Missing>.
105+
106+
### Notes
107+
108+
Because copying a standard library class derived from <Missing>`std::exception`</Missing> is not permitted to throw exceptions, this message is typically stored internally as a separately-allocated reference-counted string.
109+
110+
## std::chrono::ambiguous_local_time::operator=
111+
112+
<DeclDoc>
113+
<Decl slot="decl">
114+
<RevisionBlock since="C++20" noborder>
115+
```cpp
116+
ambiguous_local_time& operator=( const ambiguous_local_time& other ) noexcept;
117+
```
118+
</RevisionBlock>
119+
</Decl>
120+
121+
Assigns the contents with those of `other`. If `*this` and `other` both have dynamic type `std::chrono::ambiguous_local_time` then `std::strcmp(what(), other.what()) == 0` after assignment.
122+
</DeclDoc>
123+
124+
### Parameters
125+
126+
<ParamDocList>
127+
<ParamDoc name="other">
128+
another exception object to assign with
129+
</ParamDoc>
130+
</ParamDocList>
131+
132+
### Return value
133+
134+
`*this`
135+
136+
## std::chrono::ambiguous_local_time::what
137+
138+
<DeclDoc>
139+
<Decl slot="decl">
140+
<RevisionBlock since="C++20" noborder>
141+
```cpp
142+
virtual const char* what() const noexcept;
143+
```
144+
</RevisionBlock>
145+
</Decl>
146+
147+
Returns the explanatory string.
148+
</DeclDoc>
149+
150+
### Parameters
151+
152+
(none)
153+
154+
### Return value
155+
156+
Pointer to a null-terminated string with explanatory information. The string is suitable for conversion and display as a <Missing>`std::wstring`</Missing>. The pointer is guaranteed to be valid at least until the exception object from which it is obtained is destroyed, or until a non-const member function (e.g. copy assignment operator) on the exception object is called.
157+
158+
### Notes
159+
160+
Implementations are allowed but not required to override `what()`.
161+
162+
## Inherited from std::runtime_error
163+
164+
Inherited from <Missing>`std::exception`</Missing>.
165+
166+
### Member functions
167+
168+
<DescList>
169+
<Desc kind="virtual function">
170+
<Fragment slot="item">`what`</Fragment>
171+
returns an explanatory string
172+
</Desc>
173+
</DescList>
174+
175+
## See also
176+
177+
<DescList>
178+
<Desc kind="class" autorevSince="C++20">
179+
<Fragment slot="item">
180+
<RevisionBlock noborder since="C++20" dir="v"><Missing>`nonexistent_local_time`</Missing></RevisionBlock>
181+
</Fragment>
182+
exception thrown to report that a local time is nonexistent
183+
</Desc>
184+
</DescList>
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
---
2+
title: std::chrono::choose
3+
cppdoc:
4+
keys: ["cpp.chrono.choose"]
5+
revision:
6+
since: C++20
7+
---
8+
9+
import { CppHeader } from "@components/header";
10+
import { Decl, DeclDoc } from "@components/decl-doc";
11+
import { Desc, DescList } from "@components/desc-list";
12+
import Missing from "@components/Missing.astro";
13+
import { Revision, RevisionBlock } from "@components/revision";
14+
15+
Defined in header <CppHeader name="chrono" />.
16+
17+
<DeclDoc>
18+
<Decl slot="decl">
19+
<RevisionBlock since="C++20" noborder>
20+
```cpp
21+
enum class choose {
22+
earliest,
23+
latest
24+
};
25+
```
26+
</RevisionBlock>
27+
</Decl>
28+
29+
The scoped enumeration `choose` can be passed to certain member functions of <Missing>`std::chrono::time_zone`</Missing> and <Missing>`std::chrono::zoned_time`</Missing> to control how ambiguous or nonexistent local times should be resolved. Passing `choose::earliest` causes the earlier time point to be returned, while passing `choose::latest` causes the later time point to be returned. (For nonexistent local times, these two time points are identical.)
30+
31+
If a `choose` is not passed and an ambiguous or nonexistent local time is encountered, a <Missing>`std::chrono::ambiguous_local_time`</Missing> or <Missing>`std::chrono::nonexistent_local_time`</Missing> exception (as applicable) will be thrown.
32+
</DeclDoc>
33+
34+
## See also
35+
36+
<DescList>
37+
<Desc kind="constructor" autorevSince="C++20">
38+
<Fragment slot="item">
39+
<RevisionBlock noborder since="C++20" dir="v"><Missing>`zoned_time::zoned_time`</Missing></RevisionBlock>
40+
</Fragment>
41+
constructs a `zoned_time`
42+
</Desc>
43+
<Desc kind="function" autorevSince="C++20">
44+
<Fragment slot="item">
45+
<RevisionBlock noborder since="C++20" dir="v"><Missing>`time_zone::to_sys`</Missing></RevisionBlock>
46+
</Fragment>
47+
converts a `local_time` in this time zone to a `sys_time`
48+
</Desc>
49+
</DescList>
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
---
2+
title: std::chrono::clock_cast
3+
cppdoc:
4+
keys: ["cpp.chrono.clock_cast"]
5+
revision:
6+
since: C++20
7+
---
8+
9+
import { CppHeader } from "@components/header";
10+
import { Decl, DeclDoc } from "@components/decl-doc";
11+
import { Desc, DescList } from "@components/desc-list";
12+
import { ParamDoc, ParamDocList } from "@components/param-doc";
13+
import Missing from "@components/Missing.astro";
14+
import { Revision, RevisionBlock } from "@components/revision";
15+
16+
Defined in header <CppHeader name="chrono" />.
17+
18+
<DeclDoc>
19+
<Decl slot="decl">
20+
<RevisionBlock since="C++20" noborder>
21+
```cpp
22+
template< class Dest, class Source, class Duration >
23+
auto clock_cast( const std::chrono::time_point<Source, Duration>& t );
24+
```
25+
</RevisionBlock>
26+
</Decl>
27+
28+
Converts the time point `t` of a clock `Source` to an equivalent time point of the clock `Dest`, using <Missing>`std::chrono::system_clock`</Missing> and/or <Missing>`std::chrono::utc_clock`</Missing> as intermediaries if necessary.
29+
30+
- If the expression `std::chrono::clock_time_conversion<Dest, Source>{}(t)` is well-formed, returns the result of that expression.
31+
- Otherwise, if at least one of the following two expressions are well-formed, then
32+
- If both expressions are well-formed, the conversion is ambiguous, and the program is ill-formed.
33+
- Otherwise, exactly one of the two expressions is well-formed; the result of that expression is returned.
34+
1. `std::chrono::clock_time_conversion<Dest, std::chrono::system_clock>{}(std::chrono::clock_time_conversion<std::chrono::system_clock, Source>{}(t))`
35+
2. `std::chrono::clock_time_conversion<Dest, std::chrono::utc_clock>{}(std::chrono::clock_time_conversion<std::chrono::utc_clock, Source>{}(t))`
36+
- Otherwise, if at least one of the following two expressions are well-formed, then
37+
- If both expressions are well-formed, the conversion is ambiguous, and the program is ill-formed.
38+
- Otherwise, exactly one of the two expressions is well-formed; the result of that expression is returned.
39+
1. `std::chrono::clock_time_conversion<Dest, std::chrono::utc_clock>{}(std::chrono::clock_time_conversion<std::chrono::utc_clock, std::chrono::system_clock>{}(std::chrono::clock_time_conversion<std::chrono::system_clock, Source>{}(t)))`
40+
2. `std::chrono::clock_time_conversion<Dest, std::chrono::system_clock>{}(std::chrono::clock_time_conversion<std::chrono::system_clock, std::chrono::utc_clock>{}(std::chrono::clock_time_conversion<std::chrono::utc_clock, Source>{}(t)))`
41+
- Otherwise, this function does not participate in overload resolution.
42+
</DeclDoc>
43+
44+
## Return value
45+
46+
The result of the conversion, determined as described above.
47+
48+
## Example
49+
50+
```cpp
51+
// Example code here
52+
```
53+
54+
## See also
55+
56+
<DescList>
57+
<Desc kind="class template" autorevSince="C++20">
58+
<Fragment slot="item">
59+
<RevisionBlock noborder since="C++20" dir="v"><Missing>`clock_time_conversion`</Missing></RevisionBlock>
60+
</Fragment>
61+
traits class defining how to convert time points of one clock to another
62+
</Desc>
63+
</DescList>

0 commit comments

Comments
 (0)