Debian Codegraph @

libcxx/test/std/time/time.syn/formatter.year_month_weekday.pass.cpp

raw
1 //===----------------------------------------------------------------------===//
2 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
3 // See https://llvm.org/LICENSE.txt for license information.
4 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
5 //
6 //===----------------------------------------------------------------------===//
7
8 // UNSUPPORTED: c++03, c++11, c++14, c++17
9 // UNSUPPORTED: no-localization
10 // UNSUPPORTED: GCC-ALWAYS_INLINE-FIXME
11
12 // TODO FMT This test should not require std::to_chars(floating-point)
13 // XFAIL: availability-fp_to_chars-missing
14
15 // REQUIRES: locale.fr_FR.UTF-8
16 // REQUIRES: locale.ja_JP.UTF-8
17
18 // <chrono>
19
20 // template<class charT> struct formatter<chrono::year_month_weekday, charT>;
21
22 #include <chrono>
23 #include <format>
24
25 #include <cassert>
26 #include <concepts>
27 #include <locale>
28 #include <iostream>
29 #include <type_traits>
30
31 #include "formatter_tests.h"
32 #include "make_string.h"
33 #include "platform_support.h" // locale name macros
34 #include "string_literal.h"
35 #include "test_macros.h"
36
37 template <class CharT>
38 static void test_no_chrono_specs() {
39 // Valid year, valid month, valid day, valid index
40 check(SV("1970/Jan/Mon[1]"),
41 SV("{}"),
42 std::chrono::year_month_weekday{
43 std::chrono::year{1970}, std::chrono::month{1}, std::chrono::weekday_indexed{std::chrono::weekday{1}, 1}});
44 check(SV("*1970/Jan/Mon[1]"),
45 SV("{:*>16}"),
46 std::chrono::year_month_weekday{
47 std::chrono::year{1970}, std::chrono::month{1}, std::chrono::weekday_indexed{std::chrono::weekday{1}, 1}});
48 check(SV("*1970/Jan/Mon[1]*"),
49 SV("{:*^17}"),
50 std::chrono::year_month_weekday{
51 std::chrono::year{1970}, std::chrono::month{1}, std::chrono::weekday_indexed{std::chrono::weekday{1}, 1}});
52
53 // Valid year, valid month, valid day, invalid index
54 check(SV("1970/Jan/Mon[7 is not a valid index]"),
55 SV("{}"),
56 std::chrono::year_month_weekday{
57 std::chrono::year{1970}, std::chrono::month{1}, std::chrono::weekday_indexed{std::chrono::weekday{1}, 7}});
58
59 // Valid year, valid month, invalid day, valid index
60 check(SV("1970/Jan/13 is not a valid weekday[1]"),
61 SV("{}"),
62 std::chrono::year_month_weekday{
63 std::chrono::year{1970}, std::chrono::month{1}, std::chrono::weekday_indexed{std::chrono::weekday{13}, 1}});
64
65 // Valid year, valid month, invalid day, invalid index
66 check(SV("1970/Jan/13 is not a valid weekday[7 is not a valid index]"),
67 SV("{}"),
68 std::chrono::year_month_weekday{
69 std::chrono::year{1970}, std::chrono::month{1}, std::chrono::weekday_indexed{std::chrono::weekday{13}, 7}});
70
71 // Valid year, invalid month, valid day, invalid index
72 check(SV("1970/0 is not a valid month/Mon[7 is not a valid index]"),
73 SV("{}"),
74 std::chrono::year_month_weekday{
75 std::chrono::year{1970}, std::chrono::month{0}, std::chrono::weekday_indexed{std::chrono::weekday{1}, 7}});
76
77 // Valid year, invalid month, invalid day, valid index
78 check(SV("1970/0 is not a valid month/13 is not a valid weekday[1]"),
79 SV("{}"),
80 std::chrono::year_month_weekday{
81 std::chrono::year{1970}, std::chrono::month{0}, std::chrono::weekday_indexed{std::chrono::weekday{13}, 1}});
82
83 // Valid year, invalid month, invalid day, invalid index
84 check(SV("1970/0 is not a valid month/13 is not a valid weekday[7 is not a valid index]"),
85 SV("{}"),
86 std::chrono::year_month_weekday{
87 std::chrono::year{1970}, std::chrono::month{0}, std::chrono::weekday_indexed{std::chrono::weekday{13}, 7}});
88
89 // Invalid year, valid month, valid day, valid index
90 check(
91 SV("-32768 is not a valid year/Jan/Mon[1]"),
92 SV("{}"),
93 std::chrono::year_month_weekday{
94 std::chrono::year{-32768}, std::chrono::month{1}, std::chrono::weekday_indexed{std::chrono::weekday{1}, 1}});
95
96 // Invalid year, valid month, valid day, invalid index
97 check(
98 SV("-32768 is not a valid year/Jan/Mon[7 is not a valid index]"),
99 SV("{}"),
100 std::chrono::year_month_weekday{
101 std::chrono::year{-32768}, std::chrono::month{1}, std::chrono::weekday_indexed{std::chrono::weekday{1}, 7}});
102
103 // Invalid year, valid month, invalid day, valid index
104 check(
105 SV("-32768 is not a valid year/Jan/13 is not a valid weekday[1]"),
106 SV("{}"),
107 std::chrono::year_month_weekday{
108 std::chrono::year{-32768}, std::chrono::month{1}, std::chrono::weekday_indexed{std::chrono::weekday{13}, 1}});
109
110 // Invalid year, valid month, invalid day, invalid index
111 check(
112 SV("-32768 is not a valid year/Jan/13 is not a valid weekday[7 is not a valid index]"),
113 SV("{}"),
114 std::chrono::year_month_weekday{
115 std::chrono::year{-32768}, std::chrono::month{1}, std::chrono::weekday_indexed{std::chrono::weekday{13}, 7}});
116
117 // Invalid year, invalid month, valid day, invalid index
118 check(
119 SV("-32768 is not a valid year/0 is not a valid month/Mon[7 is not a valid index]"),
120 SV("{}"),
121 std::chrono::year_month_weekday{
122 std::chrono::year{-32768}, std::chrono::month{0}, std::chrono::weekday_indexed{std::chrono::weekday{1}, 7}});
123
124 // Invalid year, invalid month, invalid day, valid index
125 check(
126 SV("-32768 is not a valid year/0 is not a valid month/13 is not a valid weekday[1]"),
127 SV("{}"),
128 std::chrono::year_month_weekday{
129 std::chrono::year{-32768}, std::chrono::month{0}, std::chrono::weekday_indexed{std::chrono::weekday{13}, 1}});
130
131 // Invalid year, invalid month, invalid day, invalid index
132 check(
133 SV("-32768 is not a valid year/0 is not a valid month/13 is not a valid weekday[7 is not a valid index]"),
134 SV("{}"),
135 std::chrono::year_month_weekday{
136 std::chrono::year{-32768}, std::chrono::month{0}, std::chrono::weekday_indexed{std::chrono::weekday{13}, 7}});
137 }
138
139 // TODO FMT Should x throw?
140 template <class CharT>
141 static void test_invalid_values() {
142 // Test that %a, %A, %b, %B, %h, %j, %u, %U, %V, %w, %W, %Ou, %OU, %OV, %Ow, and %OW throw an exception.
143 check_exception(
144 "Formatting a weekday name needs a valid weekday",
145 SV("{:%a}"),
146 std::chrono::year_month_weekday{
147 std::chrono::year{1970}, std::chrono::month{1}, std::chrono::weekday_indexed{std::chrono::weekday{13}, 1}});
148
149 check_exception(
150 "Formatting a weekday name needs a valid weekday",
151 SV("{:%A}"),
152 std::chrono::year_month_weekday{
153 std::chrono::year{1970}, std::chrono::month{1}, std::chrono::weekday_indexed{std::chrono::weekday{13}, 1}});
154
155 check_exception(
156 "Formatting a month name from an invalid month number",
157 SV("{:%b}"),
158 std::chrono::year_month_weekday{
159 std::chrono::year{1970}, std::chrono::month{0}, std::chrono::weekday_indexed{std::chrono::weekday{1}, 1}});
160
161 check_exception(
162 "Formatting a month name from an invalid month number",
163 SV("{:%B}"),
164 std::chrono::year_month_weekday{
165 std::chrono::year{1970}, std::chrono::month{0}, std::chrono::weekday_indexed{std::chrono::weekday{1}, 1}});
166
167 check_exception(
168 "Formatting a month name from an invalid month number",
169 SV("{:%h}"),
170 std::chrono::year_month_weekday{
171 std::chrono::year{1970}, std::chrono::month{0}, std::chrono::weekday_indexed{std::chrono::weekday{1}, 1}});
172
173 check_exception(
174 "Formatting a day of year needs a valid date",
175 SV("{:%j}"),
176 std::chrono::year_month_weekday{
177 std::chrono::year{1970}, std::chrono::month{1}, std::chrono::weekday_indexed{std::chrono::weekday{1}, 7}});
178 check_exception(
179 "Formatting a day of year needs a valid date",
180 SV("{:%j}"),
181 std::chrono::year_month_weekday{
182 std::chrono::year{1970}, std::chrono::month{1}, std::chrono::weekday_indexed{std::chrono::weekday{13}, 1}});
183 check_exception(
184 "Formatting a day of year needs a valid date",
185 SV("{:%j}"),
186 std::chrono::year_month_weekday{
187 std::chrono::year{1970}, std::chrono::month{0}, std::chrono::weekday_indexed{std::chrono::weekday{1}, 1}});
188 check_exception(
189 "Formatting a day of year needs a valid date",
190 SV("{:%j}"),
191 std::chrono::year_month_weekday{
192 std::chrono::year{-32768}, std::chrono::month{1}, std::chrono::weekday_indexed{std::chrono::weekday{1}, 1}});
193
194 check_exception(
195 "Formatting a weekday needs a valid weekday",
196 SV("{:%u}"),
197 std::chrono::year_month_weekday{
198 std::chrono::year{1970}, std::chrono::month{1}, std::chrono::weekday_indexed{std::chrono::weekday{13}, 1}});
199
200 check_exception(
201 "Formatting a week of year needs a valid date",
202 SV("{:%U}"),
203 std::chrono::year_month_weekday{
204 std::chrono::year{1970}, std::chrono::month{1}, std::chrono::weekday_indexed{std::chrono::weekday{1}, 7}});
205 check_exception(
206 "Formatting a week of year needs a valid date",
207 SV("{:%U}"),
208 std::chrono::year_month_weekday{
209 std::chrono::year{1970}, std::chrono::month{1}, std::chrono::weekday_indexed{std::chrono::weekday{13}, 1}});
210 check_exception(
211 "Formatting a week of year needs a valid date",
212 SV("{:%U}"),
213 std::chrono::year_month_weekday{
214 std::chrono::year{1970}, std::chrono::month{0}, std::chrono::weekday_indexed{std::chrono::weekday{1}, 1}});
215 check_exception(
216 "Formatting a week of year needs a valid date",
217 SV("{:%U}"),
218 std::chrono::year_month_weekday{
219 std::chrono::year{-32768}, std::chrono::month{1}, std::chrono::weekday_indexed{std::chrono::weekday{1}, 1}});
220
221 check_exception(
222 "Formatting a week of year needs a valid date",
223 SV("{:%V}"),
224 std::chrono::year_month_weekday{
225 std::chrono::year{1970}, std::chrono::month{1}, std::chrono::weekday_indexed{std::chrono::weekday{1}, 7}});
226 check_exception(
227 "Formatting a week of year needs a valid date",
228 SV("{:%V}"),
229 std::chrono::year_month_weekday{
230 std::chrono::year{1970}, std::chrono::month{1}, std::chrono::weekday_indexed{std::chrono::weekday{13}, 1}});
231 check_exception(
232 "Formatting a week of year needs a valid date",
233 SV("{:%V}"),
234 std::chrono::year_month_weekday{
235 std::chrono::year{1970}, std::chrono::month{0}, std::chrono::weekday_indexed{std::chrono::weekday{1}, 1}});
236 check_exception(
237 "Formatting a week of year needs a valid date",
238 SV("{:%V}"),
239 std::chrono::year_month_weekday{
240 std::chrono::year{-32768}, std::chrono::month{1}, std::chrono::weekday_indexed{std::chrono::weekday{1}, 1}});
241
242 check_exception(
243 "Formatting a weekday needs a valid weekday",
244 SV("{:%w}"),
245 std::chrono::year_month_weekday{
246 std::chrono::year{1970}, std::chrono::month{1}, std::chrono::weekday_indexed{std::chrono::weekday{13}, 1}});
247
248 check_exception(
249 "Formatting a week of year needs a valid date",
250 SV("{:%W}"),
251 std::chrono::year_month_weekday{
252 std::chrono::year{1970}, std::chrono::month{1}, std::chrono::weekday_indexed{std::chrono::weekday{1}, 7}});
253 check_exception(
254 "Formatting a week of year needs a valid date",
255 SV("{:%W}"),
256 std::chrono::year_month_weekday{
257 std::chrono::year{1970}, std::chrono::month{1}, std::chrono::weekday_indexed{std::chrono::weekday{13}, 1}});
258 check_exception(
259 "Formatting a week of year needs a valid date",
260 SV("{:%W}"),
261 std::chrono::year_month_weekday{
262 std::chrono::year{1970}, std::chrono::month{0}, std::chrono::weekday_indexed{std::chrono::weekday{1}, 1}});
263 check_exception(
264 "Formatting a week of year needs a valid date",
265 SV("{:%W}"),
266 std::chrono::year_month_weekday{
267 std::chrono::year{-32768}, std::chrono::month{1}, std::chrono::weekday_indexed{std::chrono::weekday{1}, 1}});
268 }
269
270 template <class CharT>
271 static void test_valid_md_values() {
272 constexpr std::basic_string_view<CharT> fmt =
273 SV("{:%%b='%b'%t%%B='%B'%t%%h='%h'%t%%m='%m'%t%%Om='%Om'%t%%d='%d'%t%%e='%e'%t%%Od='%Od'%t%%Oe='%Oe'%n}");
274 constexpr std::basic_string_view<CharT> lfmt =
275 SV("{:L%%b='%b'%t%%B='%B'%t%%h='%h'%t%%m='%m'%t%%Om='%Om'%t%%d='%d'%t%%e='%e'%t%%Od='%Od'%t%%Oe='%Oe'%n}");
276
277 const std::locale loc(LOCALE_ja_JP_UTF_8);
278 std::locale::global(std::locale(LOCALE_fr_FR_UTF_8));
279
280 // Non localized output using C-locale
281
282 check(SV("%b='Jan'\t%B='January'\t%h='Jan'\t%m='01'\t%Om='01'\t%d='01'\t%e=' 1'\t%Od='01'\t%Oe=' 1'\n"),
283 fmt,
284 std::chrono::year_month_weekday{
285 std::chrono::year{1970}, std::chrono::January, std::chrono::weekday_indexed{std::chrono::weekday{4}, 1}});
286 check(SV("%b='Dec'\t%B='December'\t%h='Dec'\t%m='12'\t%Om='12'\t%d='20'\t%e='20'\t%Od='20'\t%Oe='20'\n"),
287 fmt,
288 std::chrono::year_month_weekday{
289 std::chrono::year{1970}, std::chrono::December, std::chrono::weekday_indexed{std::chrono::weekday{7}, 3}});
290
291 // Use the global locale (fr_FR)
292 #if defined(__APPLE__)
293 check(SV("%b='jan'\t%B='janvier'\t%h='jan'\t%m='01'\t%Om='01'\t%d='01'\t%e=' 1'\t%Od='01'\t%Oe=' 1'\n"),
294 lfmt,
295 std::chrono::year_month_weekday{
296 std::chrono::year{1970}, std::chrono::January, std::chrono::weekday_indexed{std::chrono::weekday{4}, 1}});
297
298 check(SV("%b='déc'\t%B='décembre'\t%h='déc'\t%m='12'\t%Om='12'\t%d='20'\t%e='20'\t%Od='20'\t%Oe='20'\n"),
299 lfmt,
300 std::chrono::year_month_weekday{
301 std::chrono::year{1970}, std::chrono::December, std::chrono::weekday_indexed{std::chrono::weekday{7}, 3}});
302
303 #else // defined(__APPLE__)
304 check(SV("%b='janv.'\t%B='janvier'\t%h='janv.'\t%m='01'\t%Om='01'\t%d='01'\t%e=' 1'\t%Od='01'\t%Oe=' 1'\n"),
305 lfmt,
306 std::chrono::year_month_weekday{
307 std::chrono::year{1970}, std::chrono::January, std::chrono::weekday_indexed{std::chrono::weekday{4}, 1}});
308 check(SV("%b='déc.'\t%B='décembre'\t%h='déc.'\t%m='12'\t%Om='12'\t%d='20'\t%e='20'\t%Od='20'\t%Oe='20'\n"),
309 lfmt,
310 std::chrono::year_month_weekday{
311 std::chrono::year{1970}, std::chrono::December, std::chrono::weekday_indexed{std::chrono::weekday{7}, 3}});
312
313 #endif // defined(__APPLE__)
314
315 // Use supplied locale (ja_JP)
316 #if defined(_WIN32)
317 check(loc,
318 SV("%b='1'\t%B='1月'\t%h='1'\t%m='01'\t%Om='01'\t%d='01'\t%e=' 1'\t%Od='01'\t%Oe=' 1'\n"),
319 lfmt,
320 std::chrono::year_month_weekday{
321 std::chrono::year{1970}, std::chrono::January, std::chrono::weekday_indexed{std::chrono::weekday{4}, 1}});
322
323 check(loc,
324 SV("%b='12'\t%B='12月'\t%h='12'\t%m='12'\t%Om='12'\t%d='20'\t%e='20'\t%Od='20'\t%Oe='20'\n"),
325 lfmt,
326 std::chrono::year_month_weekday{
327 std::chrono::year{1970}, std::chrono::December, std::chrono::weekday_indexed{std::chrono::weekday{7}, 3}});
328
329 #elif defined(_AIX) // defined(_WIN32)
330 check(loc,
331 SV("%b='1月'\t%B='1月'\t%h='1月'\t%m='01'\t%Om='01'\t%d='01'\t%e=' 1'\t%Od='01'\t%Oe=' 1'\n"),
332 lfmt,
333 std::chrono::year_month_weekday{
334 std::chrono::year{1970}, std::chrono::January, std::chrono::weekday_indexed{std::chrono::weekday{4}, 1}});
335
336 check(loc,
337 SV("%b='12月'\t%B='12月'\t%h='12月'\t%m='12'\t%Om='12'\t%d='20'\t%e='20'\t%Od='20'\t%Oe='20'\n"),
338 lfmt,
339 std::chrono::year_month_weekday{
340 std::chrono::year{1970}, std::chrono::December, std::chrono::weekday_indexed{std::chrono::weekday{7}, 3}});
341
342 #elif defined(__APPLE__) // defined(_WIN32)
343 check(loc,
344 SV("%b=' 1'\t%B='1月'\t%h=' 1'\t%m='01'\t%Om='01'\t%d='01'\t%e=' 1'\t%Od='01'\t%Oe=' 1'\n"),
345 lfmt,
346 std::chrono::year_month_weekday{
347 std::chrono::year{1970}, std::chrono::January, std::chrono::weekday_indexed{std::chrono::weekday{4}, 1}});
348
349 check(loc,
350 SV("%b='12'\t%B='12月'\t%h='12'\t%m='12'\t%Om='12'\t%d='20'\t%e='20'\t%Od='20'\t%Oe='20'\n"),
351 lfmt,
352 std::chrono::year_month_weekday{
353 std::chrono::year{1970}, std::chrono::December, std::chrono::weekday_indexed{std::chrono::weekday{7}, 3}});
354
355 #elif defined(__FreeBSD__) // defined(_WIN32)
356 check(loc,
357 SV("%b=' 1月'\t%B='1月'\t%h=' 1月'\t%m='01'\t%Om='01'\t%d='01'\t%e=' 1'\t%Od='01'\t%Oe=' 1'\n"),
358 lfmt,
359 std::chrono::year_month_weekday{
360 std::chrono::year{1970}, std::chrono::January, std::chrono::weekday_indexed{std::chrono::weekday{4}, 1}});
361
362 check(loc,
363 SV("%b='12月'\t%B='12月'\t%h='12月'\t%m='12'\t%Om='12'\t%d='20'\t%e='20'\t%Od='20'\t%Oe='20'\n"),
364 lfmt,
365 std::chrono::year_month_weekday{
366 std::chrono::year{1970}, std::chrono::December, std::chrono::weekday_indexed{std::chrono::weekday{7}, 3}});
367 #else // defined(_WIN32)
368 check(loc,
369 SV("%b=' 1月'\t%B='1月'\t%h=' 1月'\t%m='01'\t%Om='一'\t%d='01'\t%e=' 1'\t%Od='一'\t%Oe='一'\n"),
370 lfmt,
371 std::chrono::year_month_weekday{
372 std::chrono::year{1970}, std::chrono::January, std::chrono::weekday_indexed{std::chrono::weekday{4}, 1}});
373
374 check(loc,
375 SV("%b='12月'\t%B='12月'\t%h='12月'\t%m='12'\t%Om='十二'\t%d='20'\t%e='20'\t%Od='二十'\t%Oe='二十'\n"),
376 lfmt,
377 std::chrono::year_month_weekday{
378 std::chrono::year{1970}, std::chrono::December, std::chrono::weekday_indexed{std::chrono::weekday{7}, 3}});
379
380 #endif // defined(_WIN32)
381
382 std::locale::global(std::locale::classic());
383 }
384
385 template <class CharT>
386 static void test_valid_ymd_values() {
387 constexpr std::basic_string_view<CharT> fmt = SV(
388 "{:"
389 "%%C='%C'%t"
390 "%%D='%D'%t"
391 "%%F='%F'%t"
392 "%%j='%j'%t"
393 "%%g='%g'%t"
394 "%%G='%G'%t"
395 "%%u='%u'%t"
396 "%%U='%U'%t"
397 "%%V='%V'%t"
398 "%%w='%w'%t"
399 "%%W='%W'%t"
400 "%%x='%x'%t"
401 "%%y='%y'%t"
402 "%%Y='%Y'%t"
403 "%%Ex='%Ex'%t"
404 "%%EC='%EC'%t"
405 "%%Ey='%Ey'%t"
406 "%%EY='%EY'%t"
407 "%%Ou='%Ou'%t"
408 "%%OU='%OU'%t"
409 "%%OV='%OV'%t"
410 "%%Ow='%Ow'%t"
411 "%%OW='%OW'%t"
412 "%%Oy='%Oy'%t"
413 "%n}");
414
415 constexpr std::basic_string_view<CharT> lfmt = SV(
416 "{:L"
417 "%%C='%C'%t"
418 "%%D='%D'%t"
419 "%%F='%F'%t"
420 "%%j='%j'%t"
421 "%%g='%g'%t"
422 "%%G='%G'%t"
423 "%%u='%u'%t"
424 "%%U='%U'%t"
425 "%%V='%V'%t"
426 "%%w='%w'%t"
427 "%%W='%W'%t"
428 "%%x='%x'%t"
429 "%%y='%y'%t"
430 "%%Y='%Y'%t"
431 "%%Ex='%Ex'%t"
432 "%%EC='%EC'%t"
433 "%%Ey='%Ey'%t"
434 "%%EY='%EY'%t"
435 "%%Ou='%Ou'%t"
436 "%%OU='%OU'%t"
437 "%%OV='%OV'%t"
438 "%%Ow='%Ow'%t"
439 "%%OW='%OW'%t"
440 "%%Oy='%Oy'%t"
441 "%n}");
442
443 const std::locale loc(LOCALE_ja_JP_UTF_8);
444 std::locale::global(std::locale(LOCALE_fr_FR_UTF_8));
445
446 // Non localized output using C-locale
447 check(
448 SV("%C='19'\t"
449 "%D='01/01/70'\t"
450 "%F='1970-01-01'\t"
451 "%j='001'\t"
452 "%g='70'\t"
453 "%G='1970'\t"
454 "%u='4'\t"
455 "%U='00'\t"
456 "%V='01'\t"
457 "%w='4'\t"
458 "%W='00'\t"
459 "%x='01/01/70'\t"
460 "%y='70'\t"
461 "%Y='1970'\t"
462 "%Ex='01/01/70'\t"
463 "%EC='19'\t"
464 "%Ey='70'\t"
465 "%EY='1970'\t"
466 "%Ou='4'\t"
467 "%OU='00'\t"
468 "%OV='01'\t"
469 "%Ow='4'\t"
470 "%OW='00'\t"
471 "%Oy='70'\t"
472 "\n"),
473 fmt,
474 std::chrono::year_month_weekday{
475 std::chrono::year{1970}, std::chrono::January, std::chrono::weekday_indexed{std::chrono::weekday{4}, 1}});
476
477 check(
478 SV("%C='20'\t"
479 "%D='05/29/04'\t"
480 "%F='2004-05-29'\t"
481 "%j='150'\t"
482 "%g='04'\t"
483 "%G='2004'\t"
484 "%u='6'\t"
485 "%U='21'\t"
486 "%V='22'\t"
487 "%w='6'\t"
488 "%W='21'\t"
489 "%x='05/29/04'\t"
490 "%y='04'\t"
491 "%Y='2004'\t"
492 "%Ex='05/29/04'\t"
493 "%EC='20'\t"
494 "%Ey='04'\t"
495 "%EY='2004'\t"
496 "%Ou='6'\t"
497 "%OU='21'\t"
498 "%OV='22'\t"
499 "%Ow='6'\t"
500 "%OW='21'\t"
501 "%Oy='04'\t"
502 "\n"),
503 fmt,
504 std::chrono::year_month_weekday{
505 std::chrono::year{2004}, std::chrono::May, std::chrono::weekday_indexed{std::chrono::weekday{6}, 5}});
506
507 // Use the global locale (fr_FR)
508 check(
509 SV("%C='19'\t"
510 "%D='01/01/70'\t"
511 "%F='1970-01-01'\t"
512 "%j='001'\t"
513 "%g='70'\t"
514 "%G='1970'\t"
515 "%u='4'\t"
516 "%U='00'\t"
517 "%V='01'\t"
518 "%w='4'\t"
519 "%W='00'\t"
520 #if defined(__APPLE__) || defined(__FreeBSD__)
521 "%x='01.01.1970'\t"
522 #else
523 "%x='01/01/1970'\t"
524 #endif
525 "%y='70'\t"
526 "%Y='1970'\t"
527 #if defined(__APPLE__) || defined(__FreeBSD__)
528 "%Ex='01.01.1970'\t"
529 #else
530 "%Ex='01/01/1970'\t"
531 #endif
532 "%EC='19'\t"
533 "%Ey='70'\t"
534 "%EY='1970'\t"
535 "%Ou='4'\t"
536 "%OU='00'\t"
537 "%OV='01'\t"
538 "%Ow='4'\t"
539 "%OW='00'\t"
540 "%Oy='70'\t"
541 "\n"),
542 lfmt,
543 std::chrono::year_month_weekday{
544 std::chrono::year{1970}, std::chrono::January, std::chrono::weekday_indexed{std::chrono::weekday{4}, 1}});
545
546 check(
547 SV("%C='20'\t"
548 "%D='05/29/04'\t"
549 "%F='2004-05-29'\t"
550 "%j='150'\t"
551 "%g='04'\t"
552 "%G='2004'\t"
553 "%u='6'\t"
554 "%U='21'\t"
555 "%V='22'\t"
556 "%w='6'\t"
557 "%W='21'\t"
558 #if defined(__APPLE__) || defined(__FreeBSD__)
559 "%x='29.05.2004'\t"
560 #else
561 "%x='29/05/2004'\t"
562 #endif
563 "%y='04'\t"
564 "%Y='2004'\t"
565 #if defined(__APPLE__) || defined(__FreeBSD__)
566 "%Ex='29.05.2004'\t"
567 #else
568 "%Ex='29/05/2004'\t"
569 #endif
570 "%EC='20'\t"
571 "%Ey='04'\t"
572 "%EY='2004'\t"
573 "%Ou='6'\t"
574 "%OU='21'\t"
575 "%OV='22'\t"
576 "%Ow='6'\t"
577 "%OW='21'\t"
578 "%Oy='04'\t"
579 "\n"),
580 lfmt,
581 std::chrono::year_month_weekday{
582 std::chrono::year{2004}, std::chrono::May, std::chrono::weekday_indexed{std::chrono::weekday{6}, 5}});
583
584 // Use supplied locale (ja_JP)
585 check(
586 loc,
587 SV("%C='19'\t"
588 "%D='01/01/70'\t"
589 "%F='1970-01-01'\t"
590 "%j='001'\t"
591 "%g='70'\t"
592 "%G='1970'\t"
593 "%u='4'\t"
594 "%U='00'\t"
595 "%V='01'\t"
596 "%w='4'\t"
597 "%W='00'\t"
598 #if defined(__APPLE__) || defined(_AIX) || defined(_WIN32) || defined(__FreeBSD__)
599 "%x='1970/01/01'\t"
600 #else // defined(__APPLE__) || defined(_AIX) || defined(_WIN32) || defined(__FreeBSD__)
601 "%x='1970年01月01日'\t"
602 #endif // defined(__APPLE__) || defined(_AIX) || defined(_WIN32) || defined(__FreeBSD__)
603 "%y='70'\t"
604 "%Y='1970'\t"
605 #if defined(__APPLE__) || defined(_AIX) || defined(_WIN32) || defined(__FreeBSD__)
606 "%Ex='1970/01/01'\t"
607 "%EC='19'\t"
608 "%Ey='70'\t"
609 "%EY='1970'\t"
610 "%Ou='4'\t"
611 "%OU='00'\t"
612 "%OV='01'\t"
613 "%Ow='4'\t"
614 "%OW='00'\t"
615 "%Oy='70'\t"
616 #else // defined(__APPLE__) || defined(_AIX) || defined(_WIN32) || defined(__FreeBSD__)
617 "%Ex='昭和45年01月01日'\t"
618 "%EC='昭和'\t"
619 "%Ey='45'\t"
620 "%EY='昭和45年'\t"
621 "%Ou='四'\t"
622 "%OU='〇'\t"
623 "%OV='一'\t"
624 "%Ow='四'\t"
625 "%OW='〇'\t"
626 "%Oy='七十'\t"
627 #endif // defined(__APPLE__) || defined(_AIX) || defined(_WIN32) || defined(__FreeBSD__)
628 "\n"),
629 lfmt,
630 std::chrono::year_month_weekday{
631 std::chrono::year{1970}, std::chrono::January, std::chrono::weekday_indexed{std::chrono::weekday{4}, 1}});
632
633 check(
634 loc,
635 SV("%C='20'\t"
636 "%D='05/29/04'\t"
637 "%F='2004-05-29'\t"
638 "%j='150'\t"
639 "%g='04'\t"
640 "%G='2004'\t"
641 "%u='6'\t"
642 "%U='21'\t"
643 "%V='22'\t"
644 "%w='6'\t"
645 "%W='21'\t"
646 #if defined(__APPLE__) || defined(_AIX) || defined(_WIN32) || defined(__FreeBSD__)
647 "%x='2004/05/29'\t"
648 #else // defined(__APPLE__) || defined(_AIX) || defined(_WIN32) || defined(__FreeBSD__)
649 "%x='2004年05月29日'\t"
650 #endif // defined(__APPLE__) || defined(_AIX) || defined(_WIN32) || defined(__FreeBSD__)
651 "%y='04'\t"
652 "%Y='2004'\t"
653 #if defined(__APPLE__) || defined(_AIX) || defined(_WIN32) || defined(__FreeBSD__)
654 "%Ex='2004/05/29'\t"
655 "%EC='20'\t"
656 "%Ey='04'\t"
657 "%EY='2004'\t"
658 "%Ou='6'\t"
659 "%OU='21'\t"
660 "%OV='22'\t"
661 "%Ow='6'\t"
662 "%OW='21'\t"
663 "%Oy='04'\t"
664 #else // defined(__APPLE__) || defined(_AIX) || defined(_WIN32) || defined(__FreeBSD__)
665 "%Ex='平成16年05月29日'\t"
666 "%EC='平成'\t"
667 "%Ey='16'\t"
668 "%EY='平成16年'\t"
669 "%Ou='六'\t"
670 "%OU='二十一'\t"
671 "%OV='二十二'\t"
672 "%Ow='六'\t"
673 "%OW='二十一'\t"
674 "%Oy='四'\t"
675 #endif // defined(__APPLE__) || defined(_AIX) || defined(_WIN32) || defined(__FreeBSD__)
676 "\n"),
677 lfmt,
678 std::chrono::year_month_weekday{
679 std::chrono::year{2004}, std::chrono::May, std::chrono::weekday_indexed{std::chrono::weekday{6}, 5}});
680
681 std::locale::global(std::locale::classic());
682 }
683
684 template <class CharT>
685 static void test_valid_values() {
686 // Fields only using month and day.
687 test_valid_md_values<CharT>();
688 // Fields only using year, month, and day.
689 test_valid_ymd_values<CharT>();
690 }
691
692 template <class CharT>
693 static void test() {
694 test_no_chrono_specs<CharT>();
695 test_invalid_values<CharT>();
696 test_valid_values<CharT>();
697 check_invalid_types<CharT>(
698 {SV("a"), SV("A"), SV("b"), SV("B"), SV("C"), SV("d"), SV("D"), SV("e"), SV("EC"),
699 SV("Ex"), SV("Ey"), SV("EY"), SV("F"), SV("g"), SV("G"), SV("h"), SV("j"), SV("m"),
700 SV("Od"), SV("Oe"), SV("Om"), SV("Ou"), SV("OU"), SV("OV"), SV("Ow"), SV("OW"), SV("Oy"),
701 SV("u"), SV("U"), SV("V"), SV("w"), SV("W"), SV("x"), SV("y"), SV("Y")},
702 std::chrono::year_month_weekday{
703 std::chrono::year{1970}, std::chrono::January, std::chrono::weekday_indexed{std::chrono::weekday{1}, 1}});
704
705 check_exception(
706 "The format specifier expects a '%' or a '}'",
707 SV("{:A"),
708 std::chrono::year_month_weekday{
709 std::chrono::year{1970}, std::chrono::January, std::chrono::weekday_indexed{std::chrono::weekday{1}, 1}});
710 check_exception(
711 "The chrono specifiers contain a '{'",
712 SV("{:%%{"),
713 std::chrono::year_month_weekday{
714 std::chrono::year{1970}, std::chrono::January, std::chrono::weekday_indexed{std::chrono::weekday{1}, 1}});
715 check_exception(
716 "End of input while parsing a conversion specifier",
717 SV("{:%"),
718 std::chrono::year_month_weekday{
719 std::chrono::year{1970}, std::chrono::January, std::chrono::weekday_indexed{std::chrono::weekday{1}, 1}});
720 check_exception(
721 "End of input while parsing the modifier E",
722 SV("{:%E"),
723 std::chrono::year_month_weekday{
724 std::chrono::year{1970}, std::chrono::January, std::chrono::weekday_indexed{std::chrono::weekday{1}, 1}});
725 check_exception(
726 "End of input while parsing the modifier O",
727 SV("{:%O"),
728 std::chrono::year_month_weekday{
729 std::chrono::year{1970}, std::chrono::January, std::chrono::weekday_indexed{std::chrono::weekday{1}, 1}});
730
731 // Precision not allowed
732 check_exception(
733 "The format specifier expects a '%' or a '}'",
734 SV("{:.3}"),
735 std::chrono::year_month_weekday{
736 std::chrono::year{1970}, std::chrono::January, std::chrono::weekday_indexed{std::chrono::weekday{1}, 1}});
737 }
738
739 int main(int, char**) {
740 test<char>();
741
742 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
743 test<wchar_t>();
744 #endif
745
746 return 0;
747 }