From Jason Turner

[time.cal.ymd]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmp1p1n5zk3/{from.md → to.md} +299 -0
tmp/tmp1p1n5zk3/{from.md → to.md} RENAMED
@@ -0,0 +1,299 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ### Class `year_month_day` <a id="time.cal.ymd">[[time.cal.ymd]]</a>
2
+
3
+ #### Overview <a id="time.cal.ymd.overview">[[time.cal.ymd.overview]]</a>
4
+
5
+ ``` cpp
6
+ namespace std::chrono {
7
+ class year_month_day {
8
+ chrono::year y_; // exposition only
9
+ chrono::month m_; // exposition only
10
+ chrono::day d_; // exposition only
11
+
12
+ public:
13
+ year_month_day() = default;
14
+ constexpr year_month_day(const chrono::year& y, const chrono::month& m,
15
+ const chrono::day& d) noexcept;
16
+ constexpr year_month_day(const year_month_day_last& ymdl) noexcept;
17
+ constexpr year_month_day(const sys_days& dp) noexcept;
18
+ constexpr explicit year_month_day(const local_days& dp) noexcept;
19
+
20
+ constexpr year_month_day& operator+=(const months& m) noexcept;
21
+ constexpr year_month_day& operator-=(const months& m) noexcept;
22
+ constexpr year_month_day& operator+=(const years& y) noexcept;
23
+ constexpr year_month_day& operator-=(const years& y) noexcept;
24
+
25
+ constexpr chrono::year year() const noexcept;
26
+ constexpr chrono::month month() const noexcept;
27
+ constexpr chrono::day day() const noexcept;
28
+
29
+ constexpr operator sys_days() const noexcept;
30
+ constexpr explicit operator local_days() const noexcept;
31
+ constexpr bool ok() const noexcept;
32
+ };
33
+ }
34
+ ```
35
+
36
+ `year_month_day` represents a specific year, month, and day.
37
+ `year_month_day` is a field-based time point with a resolution of
38
+ `days`.
39
+
40
+ [*Note 1*: `year_month_day` supports `years`- and `months`-oriented
41
+ arithmetic, but not `days`-oriented arithmetic. For the latter, there is
42
+ a conversion to `sys_days`, which efficiently supports `days`-oriented
43
+ arithmetic. — *end note*]
44
+
45
+ `year_month_day` meets the *Cpp17EqualityComparable* (
46
+ [[cpp17.equalitycomparable]]) and *Cpp17LessThanComparable* (
47
+ [[cpp17.lessthancomparable]]) requirements.
48
+
49
+ `year_month_day` is a trivially copyable and standard-layout class type.
50
+
51
+ #### Member functions <a id="time.cal.ymd.members">[[time.cal.ymd.members]]</a>
52
+
53
+ ``` cpp
54
+ constexpr year_month_day(const chrono::year& y, const chrono::month& m,
55
+ const chrono::day& d) noexcept;
56
+ ```
57
+
58
+ *Effects:* Initializes `y_` with `y`, `m_` with `m`, and `d_` with `d`.
59
+
60
+ ``` cpp
61
+ constexpr year_month_day(const year_month_day_last& ymdl) noexcept;
62
+ ```
63
+
64
+ *Effects:* Initializes `y_` with `ymdl.year()`, `m_` with
65
+ `ymdl.month()`, and `d_` with `ymdl.day()`.
66
+
67
+ [*Note 1*: This conversion from `year_month_day_last` to
68
+ `year_month_day` may be more efficient than converting a
69
+ `year_month_day_last` to a `sys_days`, and then converting that
70
+ `sys_days` to a `year_month_day`. — *end note*]
71
+
72
+ ``` cpp
73
+ constexpr year_month_day(const sys_days& dp) noexcept;
74
+ ```
75
+
76
+ *Effects:* Constructs an object of type `year_month_day` that
77
+ corresponds to the date represented by `dp`.
78
+
79
+ *Remarks:* For any value `ymd` of type `year_month_day` for which
80
+ `ymd.ok()` is `true`, `ymd == year_month_day{sys_days{ymd}}` is `true`.
81
+
82
+ ``` cpp
83
+ constexpr explicit year_month_day(const local_days& dp) noexcept;
84
+ ```
85
+
86
+ *Effects:* Equivalent to constructing with
87
+ `sys_days{dp.time_since_epoch()}`.
88
+
89
+ ``` cpp
90
+ constexpr year_month_day& operator+=(const months& m) noexcept;
91
+ ```
92
+
93
+ *Constraints:* If the argument supplied by the caller for the `months`
94
+ parameter is convertible to `years`, its implicit conversion sequence to
95
+ `years` is worse than its implicit conversion sequence to `months`
96
+ [[over.ics.rank]].
97
+
98
+ *Effects:* `*this = *this + m`.
99
+
100
+ *Returns:* `*this`.
101
+
102
+ ``` cpp
103
+ constexpr year_month_day& operator-=(const months& m) noexcept;
104
+ ```
105
+
106
+ *Constraints:* If the argument supplied by the caller for the `months`
107
+ parameter is convertible to `years`, its implicit conversion sequence to
108
+ `years` is worse than its implicit conversion sequence to `months`
109
+ [[over.ics.rank]].
110
+
111
+ *Effects:* `*this = *this - m`.
112
+
113
+ *Returns:* `*this`.
114
+
115
+ ``` cpp
116
+ constexpr year_month_day& year_month_day::operator+=(const years& y) noexcept;
117
+ ```
118
+
119
+ *Effects:* `*this = *this + y`.
120
+
121
+ *Returns:* `*this`.
122
+
123
+ ``` cpp
124
+ constexpr year_month_day& year_month_day::operator-=(const years& y) noexcept;
125
+ ```
126
+
127
+ *Effects:* `*this = *this - y`.
128
+
129
+ *Returns:* `*this`.
130
+
131
+ ``` cpp
132
+ constexpr chrono::year year() const noexcept;
133
+ ```
134
+
135
+ *Returns:* `y_`.
136
+
137
+ ``` cpp
138
+ constexpr chrono::month month() const noexcept;
139
+ ```
140
+
141
+ *Returns:* `m_`.
142
+
143
+ ``` cpp
144
+ constexpr chrono::day day() const noexcept;
145
+ ```
146
+
147
+ *Returns:* `d_`.
148
+
149
+ ``` cpp
150
+ constexpr operator sys_days() const noexcept;
151
+ ```
152
+
153
+ *Returns:* If `ok()`, returns a `sys_days` holding a count of days from
154
+ the `sys_days` epoch to `*this` (a negative value if `*this` represents
155
+ a date prior to the `sys_days` epoch). Otherwise, if
156
+ `y_.ok() && m_.ok()` is `true`, returns
157
+ `sys_days{y_/m_/1d} + (d_ - 1d)`. Otherwise the value returned is
158
+ unspecified.
159
+
160
+ *Remarks:* A `sys_days` in the range \[`days{-12687428}`,
161
+ `days{11248737}`\] which is converted to a `year_month_day` has the same
162
+ value when converted back to a `sys_days`.
163
+
164
+ [*Example 1*:
165
+
166
+ ``` cpp
167
+ static_assert(year_month_day{sys_days{2017y/January/0}} == 2016y/December/31);
168
+ static_assert(year_month_day{sys_days{2017y/January/31}} == 2017y/January/31);
169
+ static_assert(year_month_day{sys_days{2017y/January/32}} == 2017y/February/1);
170
+ ```
171
+
172
+ — *end example*]
173
+
174
+ ``` cpp
175
+ constexpr explicit operator local_days() const noexcept;
176
+ ```
177
+
178
+ *Returns:* `local_days{sys_days{*this}.time_since_epoch()}`.
179
+
180
+ ``` cpp
181
+ constexpr bool ok() const noexcept;
182
+ ```
183
+
184
+ *Returns:* If `y_.ok()` is `true`, and `m_.ok()` is `true`, and `d_` is
185
+ in the range \[`1d`, `(y_/m_/last).day()`\], then returns `true`;
186
+ otherwise returns `false`.
187
+
188
+ #### Non-member functions <a id="time.cal.ymd.nonmembers">[[time.cal.ymd.nonmembers]]</a>
189
+
190
+ ``` cpp
191
+ constexpr bool operator==(const year_month_day& x, const year_month_day& y) noexcept;
192
+ ```
193
+
194
+ *Returns:*
195
+ `x.year() == y.year() && x.month() == y.month() && x.day() == y.day()`.
196
+
197
+ ``` cpp
198
+ constexpr strong_ordering operator<=>(const year_month_day& x, const year_month_day& y) noexcept;
199
+ ```
200
+
201
+ *Effects:* Equivalent to:
202
+
203
+ ``` cpp
204
+ if (auto c = x.year() <=> y.year(); c != 0) return c;
205
+ if (auto c = x.month() <=> y.month(); c != 0) return c;
206
+ return x.day() <=> y.day();
207
+ ```
208
+
209
+ ``` cpp
210
+ constexpr year_month_day operator+(const year_month_day& ymd, const months& dm) noexcept;
211
+ ```
212
+
213
+ *Constraints:* If the argument supplied by the caller for the `months`
214
+ parameter is convertible to `years`, its implicit conversion sequence to
215
+ `years` is worse than its implicit conversion sequence to `months`
216
+ [[over.ics.rank]].
217
+
218
+ *Returns:* `(ymd.year() / ymd.month() + dm) / ymd.day()`.
219
+
220
+ [*Note 1*: If `ymd.day()` is in the range \[`1d`, `28d`\], `ok()` will
221
+ return `true` for the resultant `year_month_day`. — *end note*]
222
+
223
+ ``` cpp
224
+ constexpr year_month_day operator+(const months& dm, const year_month_day& ymd) noexcept;
225
+ ```
226
+
227
+ *Constraints:* If the argument supplied by the caller for the `months`
228
+ parameter is convertible to `years`, its implicit conversion sequence to
229
+ `years` is worse than its implicit conversion sequence to `months`
230
+ [[over.ics.rank]].
231
+
232
+ *Returns:* `ymd + dm`.
233
+
234
+ ``` cpp
235
+ constexpr year_month_day operator-(const year_month_day& ymd, const months& dm) noexcept;
236
+ ```
237
+
238
+ *Constraints:* If the argument supplied by the caller for the `months`
239
+ parameter is convertible to `years`, its implicit conversion sequence to
240
+ `years` is worse than its implicit conversion sequence to `months`
241
+ [[over.ics.rank]].
242
+
243
+ *Returns:* `ymd + (-dm)`.
244
+
245
+ ``` cpp
246
+ constexpr year_month_day operator+(const year_month_day& ymd, const years& dy) noexcept;
247
+ ```
248
+
249
+ *Returns:* `(ymd.year() + dy) / ymd.month() / ymd.day()`.
250
+
251
+ [*Note 2*: If `ymd.month()` is February and `ymd.day()` is not in the
252
+ range \[`1d`, `28d`\], `ok()` may return `false` for the resultant
253
+ `year_month_day`. — *end note*]
254
+
255
+ ``` cpp
256
+ constexpr year_month_day operator+(const years& dy, const year_month_day& ymd) noexcept;
257
+ ```
258
+
259
+ *Returns:* `ymd + dy`.
260
+
261
+ ``` cpp
262
+ constexpr year_month_day operator-(const year_month_day& ymd, const years& dy) noexcept;
263
+ ```
264
+
265
+ *Returns:* `ymd + (-dy)`.
266
+
267
+ ``` cpp
268
+ template<class charT, class traits>
269
+ basic_ostream<charT, traits>&
270
+ operator<<(basic_ostream<charT, traits>& os, const year_month_day& ymd);
271
+ ```
272
+
273
+ *Effects:* Equivalent to:
274
+
275
+ ``` cpp
276
+ return os << (ymd.ok() ?
277
+ format(STATICALLY-WIDEN<charT>("{:%F}"), ymd) :
278
+ format(STATICALLY-WIDEN<charT>("{:%F} is not a valid date"), ymd));
279
+ ```
280
+
281
+ ``` cpp
282
+ template<class charT, class traits, class Alloc = allocator<charT>>
283
+ basic_istream<charT, traits>&
284
+ from_stream(basic_istream<charT, traits>& is, const charT* fmt,
285
+ year_month_day& ymd, basic_string<charT, traits, Alloc>* abbrev = nullptr,
286
+ minutes* offset = nullptr);
287
+ ```
288
+
289
+ *Effects:* Attempts to parse the input stream `is` into the
290
+ `year_month_day` `ymd` using the format flags given in the NTCTS `fmt`
291
+ as specified in [[time.parse]]. If the parse fails to decode a valid
292
+ `year_month_day`, `is.setstate(ios_base::failbit)` is called and `ymd`
293
+ is not modified. If `%Z` is used and successfully parsed, that value
294
+ will be assigned to `*abbrev` if `abbrev` is non-null. If `%z` (or a
295
+ modified variant) is used and successfully parsed, that value will be
296
+ assigned to `*offset` if `offset` is non-null.
297
+
298
+ *Returns:* `is`.
299
+