Debian Codegraph @

libcxx/test/std/time/time.syn/formatter.year_month_day_last.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_day_last, 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
40 check(SV("1970/Jan/last"),
41 SV("{}"),
42 std::chrono::year_month_day_last{std::chrono::year{1970}, std::chrono::month_day_last{std::chrono::month{1}}});
43 check(SV("*1970/Jan/last*"),
44 SV("{:*^15}"),
45 std::chrono::year_month_day_last{std::chrono::year{1970}, std::chrono::month_day_last{std::chrono::month{1}}});
46 check(SV("*1970/Jan/last"),
47 SV("{:*>14}"),
48 std::chrono::year_month_day_last{std::chrono::year{1970}, std::chrono::month_day_last{std::chrono::month{1}}});
49
50 // Valid year, invalid month
51 check(SV("1970/0 is not a valid month/last"),
52 SV("{}"),
53 std::chrono::year_month_day_last{std::chrono::year{1970}, std::chrono::month_day_last{std::chrono::month{0}}});
54 check(SV("*1970/0 is not a valid month/last*"),
55 SV("{:*^34}"),
56 std::chrono::year_month_day_last{std::chrono::year{1970}, std::chrono::month_day_last{std::chrono::month{0}}});
57 check(SV("*1970/0 is not a valid month/last"),
58 SV("{:*>33}"),
59 std::chrono::year_month_day_last{std::chrono::year{1970}, std::chrono::month_day_last{std::chrono::month{0}}});
60
61 // Invalid year, valid month
62 check(
63 SV("-32768 is not a valid year/Jan/last"),
64 SV("{}"),
65 std::chrono::year_month_day_last{std::chrono::year{-32768}, std::chrono::month_day_last{std::chrono::month{1}}});
66 check(
67 SV("*-32768 is not a valid year/Jan/last*"),
68 SV("{:*^37}"),
69 std::chrono::year_month_day_last{std::chrono::year{-32768}, std::chrono::month_day_last{std::chrono::month{1}}});
70 check(
71 SV("*-32768 is not a valid year/Jan/last"),
72 SV("{:*>36}"),
73 std::chrono::year_month_day_last{std::chrono::year{-32768}, std::chrono::month_day_last{std::chrono::month{1}}});
74
75 // Invalid year, invalid month
76 check(
77 SV("-32768 is not a valid year/0 is not a valid month/last"),
78 SV("{}"),
79 std::chrono::year_month_day_last{std::chrono::year{-32768}, std::chrono::month_day_last{std::chrono::month{0}}});
80 check(
81 SV("*-32768 is not a valid year/0 is not a valid month/last*"),
82 SV("{:*^56}"),
83 std::chrono::year_month_day_last{std::chrono::year{-32768}, std::chrono::month_day_last{std::chrono::month{0}}});
84 check(
85 SV("*-32768 is not a valid year/0 is not a valid month/last"),
86 SV("{:*>55}"),
87 std::chrono::year_month_day_last{std::chrono::year{-32768}, std::chrono::month_day_last{std::chrono::month{0}}});
88 }
89
90 // TODO FMT Should x throw?
91 template <class CharT>
92 static void test_invalid_values() {
93 // Test that %a, %A, %b, %B, %h, %j, %u, %U, %V, %w, %W, %Ou, %OU, %OV, %Ow, and %OW throw an exception.
94 check_exception(
95 "Formatting a weekday name needs a valid weekday",
96 SV("{:%A}"),
97 std::chrono::year_month_day_last{std::chrono::year{1970}, std::chrono::month_day_last{std::chrono::month{0}}});
98 check_exception(
99 "Formatting a weekday name needs a valid weekday",
100 SV("{:%A}"),
101 std::chrono::year_month_day_last{std::chrono::year{-32768}, std::chrono::month_day_last{std::chrono::month{1}}});
102
103 check_exception(
104 "Formatting a weekday name needs a valid weekday",
105 SV("{:%a}"),
106 std::chrono::year_month_day_last{std::chrono::year{1970}, std::chrono::month_day_last{std::chrono::month{0}}});
107 check_exception(
108 "Formatting a weekday name needs a valid weekday",
109 SV("{:%a}"),
110 std::chrono::year_month_day_last{std::chrono::year{-32768}, std::chrono::month_day_last{std::chrono::month{1}}});
111
112 check_exception(
113 "Formatting a month name from an invalid month number",
114 SV("{:%B}"),
115 std::chrono::year_month_day_last{std::chrono::year{1970}, std::chrono::month_day_last{std::chrono::month{0}}});
116 check_exception(
117 "Formatting a month name from an invalid month number",
118 SV("{:%B}"),
119 std::chrono::year_month_day_last{std::chrono::year{1970}, std::chrono::month_day_last{std::chrono::month{13}}});
120 check_exception(
121 "Formatting a month name from an invalid month number",
122 SV("{:%B}"),
123 std::chrono::year_month_day_last{std::chrono::year{1970}, std::chrono::month_day_last{std::chrono::month{255}}});
124
125 check_exception(
126 "Formatting a month name from an invalid month number",
127 SV("{:%b}"),
128 std::chrono::year_month_day_last{std::chrono::year{1970}, std::chrono::month_day_last{std::chrono::month{200}}});
129 check_exception(
130 "Formatting a month name from an invalid month number",
131 SV("{:%b}"),
132 std::chrono::year_month_day_last{std::chrono::year{1970}, std::chrono::month_day_last{std::chrono::month{13}}});
133 check_exception(
134 "Formatting a month name from an invalid month number",
135 SV("{:%b}"),
136 std::chrono::year_month_day_last{std::chrono::year{1970}, std::chrono::month_day_last{std::chrono::month{255}}});
137
138 check_exception(
139 "Formatting a month name from an invalid month number",
140 SV("{:%h}"),
141 std::chrono::year_month_day_last{std::chrono::year{1970}, std::chrono::month_day_last{std::chrono::month{0}}});
142 check_exception(
143 "Formatting a month name from an invalid month number",
144 SV("{:%h}"),
145 std::chrono::year_month_day_last{std::chrono::year{1970}, std::chrono::month_day_last{std::chrono::month{13}}});
146 check_exception(
147 "Formatting a month name from an invalid month number",
148 SV("{:%h}"),
149 std::chrono::year_month_day_last{std::chrono::year{1970}, std::chrono::month_day_last{std::chrono::month{255}}});
150
151 check_exception(
152 "Formatting a day of year needs a valid date",
153 SV("{:%j}"),
154 std::chrono::year_month_day_last{std::chrono::year{1970}, std::chrono::month_day_last{std::chrono::month{0}}});
155 check_exception(
156 "Formatting a day of year needs a valid date",
157 SV("{:%j}"),
158 std::chrono::year_month_day_last{std::chrono::year{-32768}, std::chrono::month_day_last{std::chrono::month{1}}});
159
160 check_exception(
161 "Formatting a weekday needs a valid weekday",
162 SV("{:%u}"),
163 std::chrono::year_month_day_last{std::chrono::year{1970}, std::chrono::month_day_last{std::chrono::month{0}}});
164 check_exception(
165 "Formatting a weekday needs a valid weekday",
166 SV("{:%u}"),
167 std::chrono::year_month_day_last{std::chrono::year{-32768}, std::chrono::month_day_last{std::chrono::month{1}}});
168
169 check_exception(
170 "Formatting a week of year needs a valid date",
171 SV("{:%U}"),
172 std::chrono::year_month_day_last{std::chrono::year{1970}, std::chrono::month_day_last{std::chrono::month{0}}});
173 check_exception(
174 "Formatting a week of year needs a valid date",
175 SV("{:%U}"),
176 std::chrono::year_month_day_last{std::chrono::year{-32768}, std::chrono::month_day_last{std::chrono::month{1}}});
177
178 check_exception(
179 "Formatting a week of year needs a valid date",
180 SV("{:%V}"),
181 std::chrono::year_month_day_last{std::chrono::year{1970}, std::chrono::month_day_last{std::chrono::month{0}}});
182 check_exception(
183 "Formatting a week of year needs a valid date",
184 SV("{:%V}"),
185 std::chrono::year_month_day_last{std::chrono::year{-32768}, std::chrono::month_day_last{std::chrono::month{1}}});
186
187 check_exception(
188 "Formatting a weekday needs a valid weekday",
189 SV("{:%w}"),
190 std::chrono::year_month_day_last{std::chrono::year{1970}, std::chrono::month_day_last{std::chrono::month{0}}});
191 check_exception(
192 "Formatting a weekday needs a valid weekday",
193 SV("{:%w}"),
194 std::chrono::year_month_day_last{std::chrono::year{-32768}, std::chrono::month_day_last{std::chrono::month{1}}});
195
196 check_exception(
197 "Formatting a week of year needs a valid date",
198 SV("{:%W}"),
199 std::chrono::year_month_day_last{std::chrono::year{1970}, std::chrono::month_day_last{std::chrono::month{0}}});
200 check_exception(
201 "Formatting a week of year needs a valid date",
202 SV("{:%W}"),
203 std::chrono::year_month_day_last{std::chrono::year{-32768}, std::chrono::month_day_last{std::chrono::month{1}}});
204
205 check_exception(
206 "Formatting a weekday needs a valid weekday",
207 SV("{:%Ou}"),
208 std::chrono::year_month_day_last{std::chrono::year{1970}, std::chrono::month_day_last{std::chrono::month{0}}});
209 check_exception(
210 "Formatting a weekday needs a valid weekday",
211 SV("{:%Ou}"),
212 std::chrono::year_month_day_last{std::chrono::year{-32768}, std::chrono::month_day_last{std::chrono::month{1}}});
213
214 check_exception(
215 "Formatting a week of year needs a valid date",
216 SV("{:%OU}"),
217 std::chrono::year_month_day_last{std::chrono::year{1970}, std::chrono::month_day_last{std::chrono::month{0}}});
218 check_exception(
219 "Formatting a week of year needs a valid date",
220 SV("{:%OU}"),
221 std::chrono::year_month_day_last{std::chrono::year{-32768}, std::chrono::month_day_last{std::chrono::month{1}}});
222
223 check_exception(
224 "Formatting a week of year needs a valid date",
225 SV("{:%OV}"),
226 std::chrono::year_month_day_last{std::chrono::year{1970}, std::chrono::month_day_last{std::chrono::month{0}}});
227 check_exception(
228 "Formatting a week of year needs a valid date",
229 SV("{:%OV}"),
230 std::chrono::year_month_day_last{std::chrono::year{-32768}, std::chrono::month_day_last{std::chrono::month{1}}});
231
232 check_exception(
233 "Formatting a weekday needs a valid weekday",
234 SV("{:%Ow}"),
235 std::chrono::year_month_day_last{std::chrono::year{1970}, std::chrono::month_day_last{std::chrono::month{0}}});
236 check_exception(
237 "Formatting a weekday needs a valid weekday",
238 SV("{:%Ow}"),
239 std::chrono::year_month_day_last{std::chrono::year{-32768}, std::chrono::month_day_last{std::chrono::month{1}}});
240
241 check_exception(
242 "Formatting a week of year needs a valid date",
243 SV("{:%OW}"),
244 std::chrono::year_month_day_last{std::chrono::year{1970}, std::chrono::month_day_last{std::chrono::month{0}}});
245 check_exception(
246 "Formatting a week of year needs a valid date",
247 SV("{:%OW}"),
248 std::chrono::year_month_day_last{std::chrono::year{-32768}, std::chrono::month_day_last{std::chrono::month{1}}});
249 }
250
251 template <class CharT>
252 static void test_valid_md_values() {
253 constexpr std::basic_string_view<CharT> fmt =
254 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}");
255 constexpr std::basic_string_view<CharT> lfmt =
256 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}");
257
258 const std::locale loc(LOCALE_ja_JP_UTF_8);
259 std::locale::global(std::locale(LOCALE_fr_FR_UTF_8));
260
261 // Non localized output using C-locale
262 check(SV("%b='Jan'\t%B='January'\t%h='Jan'\t%m='01'\t%Om='01'\t%d='31'\t%e='31'\t%Od='31'\t%Oe='31'\n"),
263 fmt,
264 std::chrono::year_month_day_last{std::chrono::year{1970}, std::chrono::month_day_last{std::chrono::January}});
265 check(SV("%b='Feb'\t%B='February'\t%h='Feb'\t%m='02'\t%Om='02'\t%d='28'\t%e='28'\t%Od='28'\t%Oe='28'\n"),
266 fmt,
267 std::chrono::year_month_day_last{std::chrono::year{1970}, std::chrono::month_day_last{std::chrono::February}});
268 check(SV("%b='Mar'\t%B='March'\t%h='Mar'\t%m='03'\t%Om='03'\t%d='31'\t%e='31'\t%Od='31'\t%Oe='31'\n"),
269 fmt,
270 std::chrono::year_month_day_last{std::chrono::year{1970}, std::chrono::month_day_last{std::chrono::March}});
271 check(SV("%b='Apr'\t%B='April'\t%h='Apr'\t%m='04'\t%Om='04'\t%d='30'\t%e='30'\t%Od='30'\t%Oe='30'\n"),
272 fmt,
273 std::chrono::year_month_day_last{std::chrono::year{1970}, std::chrono::month_day_last{std::chrono::April}});
274 check(SV("%b='May'\t%B='May'\t%h='May'\t%m='05'\t%Om='05'\t%d='31'\t%e='31'\t%Od='31'\t%Oe='31'\n"),
275 fmt,
276 std::chrono::year_month_day_last{std::chrono::year{1970}, std::chrono::month_day_last{std::chrono::May}});
277 check(SV("%b='Jun'\t%B='June'\t%h='Jun'\t%m='06'\t%Om='06'\t%d='30'\t%e='30'\t%Od='30'\t%Oe='30'\n"),
278 fmt,
279 std::chrono::year_month_day_last{std::chrono::year{1970}, std::chrono::month_day_last{std::chrono::June}});
280 check(SV("%b='Jul'\t%B='July'\t%h='Jul'\t%m='07'\t%Om='07'\t%d='31'\t%e='31'\t%Od='31'\t%Oe='31'\n"),
281 fmt,
282 std::chrono::year_month_day_last{std::chrono::year{1970}, std::chrono::month_day_last{std::chrono::July}});
283 check(SV("%b='Aug'\t%B='August'\t%h='Aug'\t%m='08'\t%Om='08'\t%d='31'\t%e='31'\t%Od='31'\t%Oe='31'\n"),
284 fmt,
285 std::chrono::year_month_day_last{std::chrono::year{1970}, std::chrono::month_day_last{std::chrono::August}});
286 check(SV("%b='Sep'\t%B='September'\t%h='Sep'\t%m='09'\t%Om='09'\t%d='30'\t%e='30'\t%Od='30'\t%Oe='30'\n"),
287 fmt,
288 std::chrono::year_month_day_last{std::chrono::year{1970}, std::chrono::month_day_last{std::chrono::September}});
289 check(SV("%b='Oct'\t%B='October'\t%h='Oct'\t%m='10'\t%Om='10'\t%d='31'\t%e='31'\t%Od='31'\t%Oe='31'\n"),
290 fmt,
291 std::chrono::year_month_day_last{std::chrono::year{1970}, std::chrono::month_day_last{std::chrono::October}});
292 check(SV("%b='Nov'\t%B='November'\t%h='Nov'\t%m='11'\t%Om='11'\t%d='30'\t%e='30'\t%Od='30'\t%Oe='30'\n"),
293 fmt,
294 std::chrono::year_month_day_last{std::chrono::year{1970}, std::chrono::month_day_last{std::chrono::November}});
295 check(SV("%b='Dec'\t%B='December'\t%h='Dec'\t%m='12'\t%Om='12'\t%d='31'\t%e='31'\t%Od='31'\t%Oe='31'\n"),
296 fmt,
297 std::chrono::year_month_day_last{std::chrono::year{1970}, std::chrono::month_day_last{std::chrono::December}});
298
299 // Use the global locale (fr_FR)
300 #if defined(__APPLE__)
301 check(SV("%b='jan'\t%B='janvier'\t%h='jan'\t%m='01'\t%Om='01'\t%d='31'\t%e='31'\t%Od='31'\t%Oe='31'\n"),
302 lfmt,
303 std::chrono::year_month_day_last{std::chrono::year{1970}, std::chrono::month_day_last{std::chrono::January}});
304 check(SV("%b='fév'\t%B='février'\t%h='fév'\t%m='02'\t%Om='02'\t%d='28'\t%e='28'\t%Od='28'\t%Oe='28'\n"),
305 lfmt,
306 std::chrono::year_month_day_last{std::chrono::year{1970}, std::chrono::month_day_last{std::chrono::February}});
307 check(SV("%b='mar'\t%B='mars'\t%h='mar'\t%m='03'\t%Om='03'\t%d='31'\t%e='31'\t%Od='31'\t%Oe='31'\n"),
308 lfmt,
309 std::chrono::year_month_day_last{std::chrono::year{1970}, std::chrono::month_day_last{std::chrono::March}});
310 check(SV("%b='avr'\t%B='avril'\t%h='avr'\t%m='04'\t%Om='04'\t%d='30'\t%e='30'\t%Od='30'\t%Oe='30'\n"),
311 lfmt,
312 std::chrono::year_month_day_last{std::chrono::year{1970}, std::chrono::month_day_last{std::chrono::April}});
313 check(SV("%b='mai'\t%B='mai'\t%h='mai'\t%m='05'\t%Om='05'\t%d='31'\t%e='31'\t%Od='31'\t%Oe='31'\n"),
314 lfmt,
315 std::chrono::year_month_day_last{std::chrono::year{1970}, std::chrono::month_day_last{std::chrono::May}});
316 check(SV("%b='jui'\t%B='juin'\t%h='jui'\t%m='06'\t%Om='06'\t%d='30'\t%e='30'\t%Od='30'\t%Oe='30'\n"),
317 lfmt,
318 std::chrono::year_month_day_last{std::chrono::year{1970}, std::chrono::month_day_last{std::chrono::June}});
319 check(SV("%b='jul'\t%B='juillet'\t%h='jul'\t%m='07'\t%Om='07'\t%d='31'\t%e='31'\t%Od='31'\t%Oe='31'\n"),
320 lfmt,
321 std::chrono::year_month_day_last{std::chrono::year{1970}, std::chrono::month_day_last{std::chrono::July}});
322 check(SV("%b='aoû'\t%B='août'\t%h='aoû'\t%m='08'\t%Om='08'\t%d='31'\t%e='31'\t%Od='31'\t%Oe='31'\n"),
323 lfmt,
324 std::chrono::year_month_day_last{std::chrono::year{1970}, std::chrono::month_day_last{std::chrono::August}});
325 check(SV("%b='sep'\t%B='septembre'\t%h='sep'\t%m='09'\t%Om='09'\t%d='30'\t%e='30'\t%Od='30'\t%Oe='30'\n"),
326 lfmt,
327 std::chrono::year_month_day_last{std::chrono::year{1970}, std::chrono::month_day_last{std::chrono::September}});
328 check(SV("%b='oct'\t%B='octobre'\t%h='oct'\t%m='10'\t%Om='10'\t%d='31'\t%e='31'\t%Od='31'\t%Oe='31'\n"),
329 lfmt,
330 std::chrono::year_month_day_last{std::chrono::year{1970}, std::chrono::month_day_last{std::chrono::October}});
331 check(SV("%b='nov'\t%B='novembre'\t%h='nov'\t%m='11'\t%Om='11'\t%d='30'\t%e='30'\t%Od='30'\t%Oe='30'\n"),
332 lfmt,
333 std::chrono::year_month_day_last{std::chrono::year{1970}, std::chrono::month_day_last{std::chrono::November}});
334 check(SV("%b='déc'\t%B='décembre'\t%h='déc'\t%m='12'\t%Om='12'\t%d='31'\t%e='31'\t%Od='31'\t%Oe='31'\n"),
335 lfmt,
336 std::chrono::year_month_day_last{std::chrono::year{1970}, std::chrono::month_day_last{std::chrono::December}});
337 #else // defined(__APPLE__)
338 check(SV("%b='janv.'\t%B='janvier'\t%h='janv.'\t%m='01'\t%Om='01'\t%d='31'\t%e='31'\t%Od='31'\t%Oe='31'\n"),
339 lfmt,
340 std::chrono::year_month_day_last{std::chrono::year{1970}, std::chrono::month_day_last{std::chrono::January}});
341 check(SV("%b='févr.'\t%B='février'\t%h='févr.'\t%m='02'\t%Om='02'\t%d='28'\t%e='28'\t%Od='28'\t%Oe='28'\n"),
342 lfmt,
343 std::chrono::year_month_day_last{std::chrono::year{1970}, std::chrono::month_day_last{std::chrono::February}});
344 check(SV("%b='mars'\t%B='mars'\t%h='mars'\t%m='03'\t%Om='03'\t%d='31'\t%e='31'\t%Od='31'\t%Oe='31'\n"),
345 lfmt,
346 std::chrono::year_month_day_last{std::chrono::year{1970}, std::chrono::month_day_last{std::chrono::March}});
347 check(
348 # if defined(_WIN32) || defined(_AIX) || defined(__FreeBSD__)
349 SV("%b='avr.'\t%B='avril'\t%h='avr.'\t%m='04'\t%Om='04'\t%d='30'\t%e='30'\t%Od='30'\t%Oe='30'\n"),
350 # else // defined(_WIN32) || defined(_AIX) || defined(__FreeBSD__)
351 SV("%b='avril'\t%B='avril'\t%h='avril'\t%m='04'\t%Om='04'\t%d='30'\t%e='30'\t%Od='30'\t%Oe='30'\n"),
352 # endif // defined(_WIN32) || defined(_AIX) || defined(__FreeBSD__)
353 lfmt,
354 std::chrono::year_month_day_last{std::chrono::year{1970}, std::chrono::month_day_last{std::chrono::April}});
355 check(SV("%b='mai'\t%B='mai'\t%h='mai'\t%m='05'\t%Om='05'\t%d='31'\t%e='31'\t%Od='31'\t%Oe='31'\n"),
356 lfmt,
357 std::chrono::year_month_day_last{std::chrono::year{1970}, std::chrono::month_day_last{std::chrono::May}});
358 check(SV("%b='juin'\t%B='juin'\t%h='juin'\t%m='06'\t%Om='06'\t%d='30'\t%e='30'\t%Od='30'\t%Oe='30'\n"),
359 lfmt,
360 std::chrono::year_month_day_last{std::chrono::year{1970}, std::chrono::month_day_last{std::chrono::June}});
361 check(SV("%b='juil.'\t%B='juillet'\t%h='juil.'\t%m='07'\t%Om='07'\t%d='31'\t%e='31'\t%Od='31'\t%Oe='31'\n"),
362 lfmt,
363 std::chrono::year_month_day_last{std::chrono::year{1970}, std::chrono::month_day_last{std::chrono::July}});
364 check(SV("%b='août'\t%B='août'\t%h='août'\t%m='08'\t%Om='08'\t%d='31'\t%e='31'\t%Od='31'\t%Oe='31'\n"),
365 lfmt,
366 std::chrono::year_month_day_last{std::chrono::year{1970}, std::chrono::month_day_last{std::chrono::August}});
367 check(SV("%b='sept.'\t%B='septembre'\t%h='sept.'\t%m='09'\t%Om='09'\t%d='30'\t%e='30'\t%Od='30'\t%Oe='30'\n"),
368 lfmt,
369 std::chrono::year_month_day_last{std::chrono::year{1970}, std::chrono::month_day_last{std::chrono::September}});
370 check(SV("%b='oct.'\t%B='octobre'\t%h='oct.'\t%m='10'\t%Om='10'\t%d='31'\t%e='31'\t%Od='31'\t%Oe='31'\n"),
371 lfmt,
372 std::chrono::year_month_day_last{std::chrono::year{1970}, std::chrono::month_day_last{std::chrono::October}});
373 check(SV("%b='nov.'\t%B='novembre'\t%h='nov.'\t%m='11'\t%Om='11'\t%d='30'\t%e='30'\t%Od='30'\t%Oe='30'\n"),
374 lfmt,
375 std::chrono::year_month_day_last{std::chrono::year{1970}, std::chrono::month_day_last{std::chrono::November}});
376 check(SV("%b='déc.'\t%B='décembre'\t%h='déc.'\t%m='12'\t%Om='12'\t%d='31'\t%e='31'\t%Od='31'\t%Oe='31'\n"),
377 lfmt,
378 std::chrono::year_month_day_last{std::chrono::year{1970}, std::chrono::month_day_last{std::chrono::December}});
379 #endif // defined(__APPLE__)
380
381 // Use supplied locale (ja_JP)
382 #if defined(_WIN32)
383 check(loc,
384 SV("%b='1'\t%B='1月'\t%h='1'\t%m='01'\t%Om='01'\t%d='31'\t%e='31'\t%Od='31'\t%Oe='31'\n"),
385 lfmt,
386 std::chrono::year_month_day_last{std::chrono::year{1970}, std::chrono::month_day_last{std::chrono::January}});
387 check(loc,
388 SV("%b='2'\t%B='2月'\t%h='2'\t%m='02'\t%Om='02'\t%d='28'\t%e='28'\t%Od='28'\t%Oe='28'\n"),
389 lfmt,
390 std::chrono::year_month_day_last{std::chrono::year{1970}, std::chrono::month_day_last{std::chrono::February}});
391 check(loc,
392 SV("%b='3'\t%B='3月'\t%h='3'\t%m='03'\t%Om='03'\t%d='31'\t%e='31'\t%Od='31'\t%Oe='31'\n"),
393 lfmt,
394 std::chrono::year_month_day_last{std::chrono::year{1970}, std::chrono::month_day_last{std::chrono::March}});
395 check(loc,
396 SV("%b='4'\t%B='4月'\t%h='4'\t%m='04'\t%Om='04'\t%d='30'\t%e='30'\t%Od='30'\t%Oe='30'\n"),
397 lfmt,
398 std::chrono::year_month_day_last{std::chrono::year{1970}, std::chrono::month_day_last{std::chrono::April}});
399 check(loc,
400 SV("%b='5'\t%B='5月'\t%h='5'\t%m='05'\t%Om='05'\t%d='31'\t%e='31'\t%Od='31'\t%Oe='31'\n"),
401 lfmt,
402 std::chrono::year_month_day_last{std::chrono::year{1970}, std::chrono::month_day_last{std::chrono::May}});
403 check(loc,
404 SV("%b='6'\t%B='6月'\t%h='6'\t%m='06'\t%Om='06'\t%d='30'\t%e='30'\t%Od='30'\t%Oe='30'\n"),
405 lfmt,
406 std::chrono::year_month_day_last{std::chrono::year{1970}, std::chrono::month_day_last{std::chrono::June}});
407 check(loc,
408 SV("%b='7'\t%B='7月'\t%h='7'\t%m='07'\t%Om='07'\t%d='31'\t%e='31'\t%Od='31'\t%Oe='31'\n"),
409 lfmt,
410 std::chrono::year_month_day_last{std::chrono::year{1970}, std::chrono::month_day_last{std::chrono::July}});
411 check(loc,
412 SV("%b='8'\t%B='8月'\t%h='8'\t%m='08'\t%Om='08'\t%d='31'\t%e='31'\t%Od='31'\t%Oe='31'\n"),
413 lfmt,
414 std::chrono::year_month_day_last{std::chrono::year{1970}, std::chrono::month_day_last{std::chrono::August}});
415 check(loc,
416 SV("%b='9'\t%B='9月'\t%h='9'\t%m='09'\t%Om='09'\t%d='30'\t%e='30'\t%Od='30'\t%Oe='30'\n"),
417 lfmt,
418 std::chrono::year_month_day_last{std::chrono::year{1970}, std::chrono::month_day_last{std::chrono::September}});
419 check(loc,
420 SV("%b='10'\t%B='10月'\t%h='10'\t%m='10'\t%Om='10'\t%d='31'\t%e='31'\t%Od='31'\t%Oe='31'\n"),
421 lfmt,
422 std::chrono::year_month_day_last{std::chrono::year{1970}, std::chrono::month_day_last{std::chrono::October}});
423 check(loc,
424 SV("%b='11'\t%B='11月'\t%h='11'\t%m='11'\t%Om='11'\t%d='30'\t%e='30'\t%Od='30'\t%Oe='30'\n"),
425 lfmt,
426 std::chrono::year_month_day_last{std::chrono::year{1970}, std::chrono::month_day_last{std::chrono::November}});
427 check(loc,
428 SV("%b='12'\t%B='12月'\t%h='12'\t%m='12'\t%Om='12'\t%d='31'\t%e='31'\t%Od='31'\t%Oe='31'\n"),
429 lfmt,
430 std::chrono::year_month_day_last{std::chrono::year{1970}, std::chrono::month_day_last{std::chrono::December}});
431 #elif defined(_AIX) // defined(_WIN32)
432 check(loc,
433 SV("%b='1月'\t%B='1月'\t%h='1月'\t%m='01'\t%Om='01'\t%d='31'\t%e='31'\t%Od='31'\t%Oe='31'\n"),
434 lfmt,
435 std::chrono::year_month_day_last{std::chrono::year{1970}, std::chrono::month_day_last{std::chrono::January}});
436 check(loc,
437 SV("%b='2月'\t%B='2月'\t%h='2月'\t%m='02'\t%Om='02'\t%d='28'\t%e='28'\t%Od='28'\t%Oe='28'\n"),
438 lfmt,
439 std::chrono::year_month_day_last{std::chrono::year{1970}, std::chrono::month_day_last{std::chrono::February}});
440 check(loc,
441 SV("%b='3月'\t%B='3月'\t%h='3月'\t%m='03'\t%Om='03'\t%d='31'\t%e='31'\t%Od='31'\t%Oe='31'\n"),
442 lfmt,
443 std::chrono::year_month_day_last{std::chrono::year{1970}, std::chrono::month_day_last{std::chrono::March}});
444 check(loc,
445 SV("%b='4月'\t%B='4月'\t%h='4月'\t%m='04'\t%Om='04'\t%d='30'\t%e='30'\t%Od='30'\t%Oe='30'\n"),
446 lfmt,
447 std::chrono::year_month_day_last{std::chrono::year{1970}, std::chrono::month_day_last{std::chrono::April}});
448 check(loc,
449 SV("%b='5月'\t%B='5月'\t%h='5月'\t%m='05'\t%Om='05'\t%d='31'\t%e='31'\t%Od='31'\t%Oe='31'\n"),
450 lfmt,
451 std::chrono::year_month_day_last{std::chrono::year{1970}, std::chrono::month_day_last{std::chrono::May}});
452 check(loc,
453 SV("%b='6月'\t%B='6月'\t%h='6月'\t%m='06'\t%Om='06'\t%d='30'\t%e='30'\t%Od='30'\t%Oe='30'\n"),
454 lfmt,
455 std::chrono::year_month_day_last{std::chrono::year{1970}, std::chrono::month_day_last{std::chrono::June}});
456 check(loc,
457 SV("%b='7月'\t%B='7月'\t%h='7月'\t%m='07'\t%Om='07'\t%d='31'\t%e='31'\t%Od='31'\t%Oe='31'\n"),
458 lfmt,
459 std::chrono::year_month_day_last{std::chrono::year{1970}, std::chrono::month_day_last{std::chrono::July}});
460 check(loc,
461 SV("%b='8月'\t%B='8月'\t%h='8月'\t%m='08'\t%Om='08'\t%d='31'\t%e='31'\t%Od='31'\t%Oe='31'\n"),
462 lfmt,
463 std::chrono::year_month_day_last{std::chrono::year{1970}, std::chrono::month_day_last{std::chrono::August}});
464 check(loc,
465 SV("%b='9月'\t%B='9月'\t%h='9月'\t%m='09'\t%Om='09'\t%d='30'\t%e='30'\t%Od='30'\t%Oe='30'\n"),
466 lfmt,
467 std::chrono::year_month_day_last{std::chrono::year{1970}, std::chrono::month_day_last{std::chrono::September}});
468 check(loc,
469 SV("%b='10月'\t%B='10月'\t%h='10月'\t%m='10'\t%Om='10'\t%d='31'\t%e='31'\t%Od='31'\t%Oe='31'\n"),
470 lfmt,
471 std::chrono::year_month_day_last{std::chrono::year{1970}, std::chrono::month_day_last{std::chrono::October}});
472 check(loc,
473 SV("%b='11月'\t%B='11月'\t%h='11月'\t%m='11'\t%Om='11'\t%d='30'\t%e='30'\t%Od='30'\t%Oe='30'\n"),
474 lfmt,
475 std::chrono::year_month_day_last{std::chrono::year{1970}, std::chrono::month_day_last{std::chrono::November}});
476 check(loc,
477 SV("%b='12月'\t%B='12月'\t%h='12月'\t%m='12'\t%Om='12'\t%d='31'\t%e='31'\t%Od='31'\t%Oe='31'\n"),
478 lfmt,
479 std::chrono::year_month_day_last{std::chrono::year{1970}, std::chrono::month_day_last{std::chrono::December}});
480 #elif defined(__FreeBSD__) // defined(_WIN32)
481 check(loc,
482 SV("%b=' 1月'\t%B='1月'\t%h=' 1月'\t%m='01'\t%Om='01'\t%d='31'\t%e='31'\t%Od='31'\t%Oe='31'\n"),
483 lfmt,
484 std::chrono::year_month_day_last{std::chrono::year{1970}, std::chrono::month_day_last{std::chrono::January}});
485 check(loc,
486 SV("%b=' 2月'\t%B='2月'\t%h=' 2月'\t%m='02'\t%Om='02'\t%d='28'\t%e='28'\t%Od='28'\t%Oe='28'\n"),
487 lfmt,
488 std::chrono::year_month_day_last{std::chrono::year{1970}, std::chrono::month_day_last{std::chrono::February}});
489 check(loc,
490 SV("%b=' 3月'\t%B='3月'\t%h=' 3月'\t%m='03'\t%Om='03'\t%d='31'\t%e='31'\t%Od='31'\t%Oe='31'\n"),
491 lfmt,
492 std::chrono::year_month_day_last{std::chrono::year{1970}, std::chrono::month_day_last{std::chrono::March}});
493 check(loc,
494 SV("%b=' 4月'\t%B='4月'\t%h=' 4月'\t%m='04'\t%Om='04'\t%d='30'\t%e='30'\t%Od='30'\t%Oe='30'\n"),
495 lfmt,
496 std::chrono::year_month_day_last{std::chrono::year{1970}, std::chrono::month_day_last{std::chrono::April}});
497 check(loc,
498 SV("%b=' 5月'\t%B='5月'\t%h=' 5月'\t%m='05'\t%Om='05'\t%d='31'\t%e='31'\t%Od='31'\t%Oe='31'\n"),
499 lfmt,
500 std::chrono::year_month_day_last{std::chrono::year{1970}, std::chrono::month_day_last{std::chrono::May}});
501 check(loc,
502 SV("%b=' 6月'\t%B='6月'\t%h=' 6月'\t%m='06'\t%Om='06'\t%d='30'\t%e='30'\t%Od='30'\t%Oe='30'\n"),
503 lfmt,
504 std::chrono::year_month_day_last{std::chrono::year{1970}, std::chrono::month_day_last{std::chrono::June}});
505 check(loc,
506 SV("%b=' 7月'\t%B='7月'\t%h=' 7月'\t%m='07'\t%Om='07'\t%d='31'\t%e='31'\t%Od='31'\t%Oe='31'\n"),
507 lfmt,
508 std::chrono::year_month_day_last{std::chrono::year{1970}, std::chrono::month_day_last{std::chrono::July}});
509 check(loc,
510 SV("%b=' 8月'\t%B='8月'\t%h=' 8月'\t%m='08'\t%Om='08'\t%d='31'\t%e='31'\t%Od='31'\t%Oe='31'\n"),
511 lfmt,
512 std::chrono::year_month_day_last{std::chrono::year{1970}, std::chrono::month_day_last{std::chrono::August}});
513 check(loc,
514 SV("%b=' 9月'\t%B='9月'\t%h=' 9月'\t%m='09'\t%Om='09'\t%d='30'\t%e='30'\t%Od='30'\t%Oe='30'\n"),
515 lfmt,
516 std::chrono::year_month_day_last{std::chrono::year{1970}, std::chrono::month_day_last{std::chrono::September}});
517 check(loc,
518 SV("%b='10月'\t%B='10月'\t%h='10月'\t%m='10'\t%Om='10'\t%d='31'\t%e='31'\t%Od='31'\t%Oe='31'\n"),
519 lfmt,
520 std::chrono::year_month_day_last{std::chrono::year{1970}, std::chrono::month_day_last{std::chrono::October}});
521 check(loc,
522 SV("%b='11月'\t%B='11月'\t%h='11月'\t%m='11'\t%Om='11'\t%d='30'\t%e='30'\t%Od='30'\t%Oe='30'\n"),
523 lfmt,
524 std::chrono::year_month_day_last{std::chrono::year{1970}, std::chrono::month_day_last{std::chrono::November}});
525 check(loc,
526 SV("%b='12月'\t%B='12月'\t%h='12月'\t%m='12'\t%Om='12'\t%d='31'\t%e='31'\t%Od='31'\t%Oe='31'\n"),
527 lfmt,
528 std::chrono::year_month_day_last{std::chrono::year{1970}, std::chrono::month_day_last{std::chrono::December}});
529 #elif defined(__APPLE__) // defined(_WIN32)
530 check(loc,
531 SV("%b=' 1'\t%B='1月'\t%h=' 1'\t%m='01'\t%Om='01'\t%d='31'\t%e='31'\t%Od='31'\t%Oe='31'\n"),
532 lfmt,
533 std::chrono::year_month_day_last{std::chrono::year{1970}, std::chrono::month_day_last{std::chrono::January}});
534 check(loc,
535 SV("%b=' 2'\t%B='2月'\t%h=' 2'\t%m='02'\t%Om='02'\t%d='28'\t%e='28'\t%Od='28'\t%Oe='28'\n"),
536 lfmt,
537 std::chrono::year_month_day_last{std::chrono::year{1970}, std::chrono::month_day_last{std::chrono::February}});
538 check(loc,
539 SV("%b=' 3'\t%B='3月'\t%h=' 3'\t%m='03'\t%Om='03'\t%d='31'\t%e='31'\t%Od='31'\t%Oe='31'\n"),
540 lfmt,
541 std::chrono::year_month_day_last{std::chrono::year{1970}, std::chrono::month_day_last{std::chrono::March}});
542 check(loc,
543 SV("%b=' 4'\t%B='4月'\t%h=' 4'\t%m='04'\t%Om='04'\t%d='30'\t%e='30'\t%Od='30'\t%Oe='30'\n"),
544 lfmt,
545 std::chrono::year_month_day_last{std::chrono::year{1970}, std::chrono::month_day_last{std::chrono::April}});
546 check(loc,
547 SV("%b=' 5'\t%B='5月'\t%h=' 5'\t%m='05'\t%Om='05'\t%d='31'\t%e='31'\t%Od='31'\t%Oe='31'\n"),
548 lfmt,
549 std::chrono::year_month_day_last{std::chrono::year{1970}, std::chrono::month_day_last{std::chrono::May}});
550 check(loc,
551 SV("%b=' 6'\t%B='6月'\t%h=' 6'\t%m='06'\t%Om='06'\t%d='30'\t%e='30'\t%Od='30'\t%Oe='30'\n"),
552 lfmt,
553 std::chrono::year_month_day_last{std::chrono::year{1970}, std::chrono::month_day_last{std::chrono::June}});
554 check(loc,
555 SV("%b=' 7'\t%B='7月'\t%h=' 7'\t%m='07'\t%Om='07'\t%d='31'\t%e='31'\t%Od='31'\t%Oe='31'\n"),
556 lfmt,
557 std::chrono::year_month_day_last{std::chrono::year{1970}, std::chrono::month_day_last{std::chrono::July}});
558 check(loc,
559 SV("%b=' 8'\t%B='8月'\t%h=' 8'\t%m='08'\t%Om='08'\t%d='31'\t%e='31'\t%Od='31'\t%Oe='31'\n"),
560 lfmt,
561 std::chrono::year_month_day_last{std::chrono::year{1970}, std::chrono::month_day_last{std::chrono::August}});
562 check(loc,
563 SV("%b=' 9'\t%B='9月'\t%h=' 9'\t%m='09'\t%Om='09'\t%d='30'\t%e='30'\t%Od='30'\t%Oe='30'\n"),
564 lfmt,
565 std::chrono::year_month_day_last{std::chrono::year{1970}, std::chrono::month_day_last{std::chrono::September}});
566 check(loc,
567 SV("%b='10'\t%B='10月'\t%h='10'\t%m='10'\t%Om='10'\t%d='31'\t%e='31'\t%Od='31'\t%Oe='31'\n"),
568 lfmt,
569 std::chrono::year_month_day_last{std::chrono::year{1970}, std::chrono::month_day_last{std::chrono::October}});
570 check(loc,
571 SV("%b='11'\t%B='11月'\t%h='11'\t%m='11'\t%Om='11'\t%d='30'\t%e='30'\t%Od='30'\t%Oe='30'\n"),
572 lfmt,
573 std::chrono::year_month_day_last{std::chrono::year{1970}, std::chrono::month_day_last{std::chrono::November}});
574 check(loc,
575 SV("%b='12'\t%B='12月'\t%h='12'\t%m='12'\t%Om='12'\t%d='31'\t%e='31'\t%Od='31'\t%Oe='31'\n"),
576 lfmt,
577 std::chrono::year_month_day_last{std::chrono::year{1970}, std::chrono::month_day_last{std::chrono::December}});
578 #else // defined(_WIN32)
579 check(loc,
580 SV("%b=' 1月'\t%B='1月'\t%h=' 1月'\t%m='01'\t%Om='一'\t%d='31'\t%e='31'\t%Od='三十一'\t%Oe='三十一'\n"),
581 lfmt,
582 std::chrono::year_month_day_last{std::chrono::year{1970}, std::chrono::month_day_last{std::chrono::January}});
583 check(loc,
584 SV("%b=' 2月'\t%B='2月'\t%h=' 2月'\t%m='02'\t%Om='二'\t%d='28'\t%e='28'\t%Od='二十八'\t%Oe='二十八'\n"),
585 lfmt,
586 std::chrono::year_month_day_last{std::chrono::year{1970}, std::chrono::month_day_last{std::chrono::February}});
587 check(loc,
588 SV("%b=' 3月'\t%B='3月'\t%h=' 3月'\t%m='03'\t%Om='三'\t%d='31'\t%e='31'\t%Od='三十一'\t%Oe='三十一'\n"),
589 lfmt,
590 std::chrono::year_month_day_last{std::chrono::year{1970}, std::chrono::month_day_last{std::chrono::March}});
591 check(loc,
592 SV("%b=' 4月'\t%B='4月'\t%h=' 4月'\t%m='04'\t%Om='四'\t%d='30'\t%e='30'\t%Od='三十'\t%Oe='三十'\n"),
593 lfmt,
594 std::chrono::year_month_day_last{std::chrono::year{1970}, std::chrono::month_day_last{std::chrono::April}});
595 check(loc,
596 SV("%b=' 5月'\t%B='5月'\t%h=' 5月'\t%m='05'\t%Om='五'\t%d='31'\t%e='31'\t%Od='三十一'\t%Oe='三十一'\n"),
597 lfmt,
598 std::chrono::year_month_day_last{std::chrono::year{1970}, std::chrono::month_day_last{std::chrono::May}});
599 check(loc,
600 SV("%b=' 6月'\t%B='6月'\t%h=' 6月'\t%m='06'\t%Om='六'\t%d='30'\t%e='30'\t%Od='三十'\t%Oe='三十'\n"),
601 lfmt,
602 std::chrono::year_month_day_last{std::chrono::year{1970}, std::chrono::month_day_last{std::chrono::June}});
603 check(loc,
604 SV("%b=' 7月'\t%B='7月'\t%h=' 7月'\t%m='07'\t%Om='七'\t%d='31'\t%e='31'\t%Od='三十一'\t%Oe='三十一'\n"),
605 lfmt,
606 std::chrono::year_month_day_last{std::chrono::year{1970}, std::chrono::month_day_last{std::chrono::July}});
607 check(loc,
608 SV("%b=' 8月'\t%B='8月'\t%h=' 8月'\t%m='08'\t%Om='八'\t%d='31'\t%e='31'\t%Od='三十一'\t%Oe='三十一'\n"),
609 lfmt,
610 std::chrono::year_month_day_last{std::chrono::year{1970}, std::chrono::month_day_last{std::chrono::August}});
611 check(loc,
612 SV("%b=' 9月'\t%B='9月'\t%h=' 9月'\t%m='09'\t%Om='九'\t%d='30'\t%e='30'\t%Od='三十'\t%Oe='三十'\n"),
613 lfmt,
614 std::chrono::year_month_day_last{std::chrono::year{1970}, std::chrono::month_day_last{std::chrono::September}});
615 check(loc,
616 SV("%b='10月'\t%B='10月'\t%h='10月'\t%m='10'\t%Om='十'\t%d='31'\t%e='31'\t%Od='三十一'\t%Oe='三十一'\n"),
617 lfmt,
618 std::chrono::year_month_day_last{std::chrono::year{1970}, std::chrono::month_day_last{std::chrono::October}});
619 check(loc,
620 SV("%b='11月'\t%B='11月'\t%h='11月'\t%m='11'\t%Om='十一'\t%d='30'\t%e='30'\t%Od='三十'\t%Oe='三十'\n"),
621 lfmt,
622 std::chrono::year_month_day_last{std::chrono::year{1970}, std::chrono::month_day_last{std::chrono::November}});
623 check(loc,
624 SV("%b='12月'\t%B='12月'\t%h='12月'\t%m='12'\t%Om='十二'\t%d='31'\t%e='31'\t%Od='三十一'\t%Oe='三十一'\n"),
625 lfmt,
626 std::chrono::year_month_day_last{std::chrono::year{1970}, std::chrono::month_day_last{std::chrono::December}});
627 #endif // defined(_WIN32)
628
629 std::locale::global(std::locale::classic());
630 }
631
632 template <class CharT>
633 static void test_valid_ymd_values() {
634 constexpr std::basic_string_view<CharT> fmt = SV(
635 "{:"
636 "%%C='%C'%t"
637 "%%D='%D'%t"
638 "%%F='%F'%t"
639 "%%j='%j'%t"
640 "%%g='%g'%t"
641 "%%G='%G'%t"
642 "%%u='%u'%t"
643 "%%U='%U'%t"
644 "%%V='%V'%t"
645 "%%w='%w'%t"
646 "%%W='%W'%t"
647 "%%x='%x'%t"
648 "%%y='%y'%t"
649 "%%Y='%Y'%t"
650 "%%Ex='%Ex'%t"
651 "%%EC='%EC'%t"
652 "%%Ey='%Ey'%t"
653 "%%EY='%EY'%t"
654 "%%Ou='%Ou'%t"
655 "%%OU='%OU'%t"
656 "%%OV='%OV'%t"
657 "%%Ow='%Ow'%t"
658 "%%OW='%OW'%t"
659 "%%Oy='%Oy'%t"
660 "%n}");
661
662 constexpr std::basic_string_view<CharT> lfmt = SV(
663 "{:L"
664 "%%C='%C'%t"
665 "%%D='%D'%t"
666 "%%F='%F'%t"
667 "%%j='%j'%t"
668 "%%g='%g'%t"
669 "%%G='%G'%t"
670 "%%u='%u'%t"
671 "%%U='%U'%t"
672 "%%V='%V'%t"
673 "%%w='%w'%t"
674 "%%W='%W'%t"
675 "%%x='%x'%t"
676 "%%y='%y'%t"
677 "%%Y='%Y'%t"
678 "%%Ex='%Ex'%t"
679 "%%EC='%EC'%t"
680 "%%Ey='%Ey'%t"
681 "%%EY='%EY'%t"
682 "%%Ou='%Ou'%t"
683 "%%OU='%OU'%t"
684 "%%OV='%OV'%t"
685 "%%Ow='%Ow'%t"
686 "%%OW='%OW'%t"
687 "%%Oy='%Oy'%t"
688 "%n}");
689
690 const std::locale loc(LOCALE_ja_JP_UTF_8);
691 std::locale::global(std::locale(LOCALE_fr_FR_UTF_8));
692
693 // Non localized output using C-locale
694 check(
695 SV("%C='19'\t"
696 "%D='01/31/70'\t"
697 "%F='1970-01-31'\t"
698 "%j='031'\t"
699 "%g='70'\t"
700 "%G='1970'\t"
701 "%u='6'\t"
702 "%U='04'\t"
703 "%V='05'\t"
704 "%w='6'\t"
705 "%W='04'\t"
706 "%x='01/31/70'\t"
707 "%y='70'\t"
708 "%Y='1970'\t"
709 "%Ex='01/31/70'\t"
710 "%EC='19'\t"
711 "%Ey='70'\t"
712 "%EY='1970'\t"
713 "%Ou='6'\t"
714 "%OU='04'\t"
715 "%OV='05'\t"
716 "%Ow='6'\t"
717 "%OW='04'\t"
718 "%Oy='70'\t"
719 "\n"),
720 fmt,
721 std::chrono::year_month_day_last{std::chrono::year{1970}, std::chrono::month_day_last{std::chrono::January}});
722
723 check(
724 SV("%C='20'\t"
725 "%D='05/31/04'\t"
726 "%F='2004-05-31'\t"
727 "%j='152'\t"
728 "%g='04'\t"
729 "%G='2004'\t"
730 "%u='1'\t"
731 "%U='22'\t"
732 "%V='23'\t"
733 "%w='1'\t"
734 "%W='22'\t"
735 "%x='05/31/04'\t"
736 "%y='04'\t"
737 "%Y='2004'\t"
738 "%Ex='05/31/04'\t"
739 "%EC='20'\t"
740 "%Ey='04'\t"
741 "%EY='2004'\t"
742 "%Ou='1'\t"
743 "%OU='22'\t"
744 "%OV='23'\t"
745 "%Ow='1'\t"
746 "%OW='22'\t"
747 "%Oy='04'\t"
748 "\n"),
749 fmt,
750 std::chrono::year_month_day_last{std::chrono::year{2004}, std::chrono::month_day_last{std::chrono::May}});
751
752 // Use the global locale (fr_FR)
753 check(
754 SV("%C='19'\t"
755 "%D='01/31/70'\t"
756 "%F='1970-01-31'\t"
757 "%j='031'\t"
758 "%g='70'\t"
759 "%G='1970'\t"
760 "%u='6'\t"
761 "%U='04'\t"
762 "%V='05'\t"
763 "%w='6'\t"
764 "%W='04'\t"
765 #if defined(__APPLE__) || defined(__FreeBSD__)
766 "%x='31.01.1970'\t"
767 #else
768 "%x='31/01/1970'\t"
769 #endif
770 "%y='70'\t"
771 "%Y='1970'\t"
772 #if defined(__APPLE__) || defined(__FreeBSD__)
773 "%Ex='31.01.1970'\t"
774 #else
775 "%Ex='31/01/1970'\t"
776 #endif
777 "%EC='19'\t"
778 "%Ey='70'\t"
779 "%EY='1970'\t"
780 "%Ou='6'\t"
781 "%OU='04'\t"
782 "%OV='05'\t"
783 "%Ow='6'\t"
784 "%OW='04'\t"
785 "%Oy='70'\t"
786 "\n"),
787 lfmt,
788 std::chrono::year_month_day_last{std::chrono::year{1970}, std::chrono::month_day_last{std::chrono::January}});
789
790 check(
791 SV("%C='20'\t"
792 "%D='05/31/04'\t"
793 "%F='2004-05-31'\t"
794 "%j='152'\t"
795 "%g='04'\t"
796 "%G='2004'\t"
797 "%u='1'\t"
798 "%U='22'\t"
799 "%V='23'\t"
800 "%w='1'\t"
801 "%W='22'\t"
802 #if defined(__APPLE__) || defined(__FreeBSD__)
803 "%x='31.05.2004'\t"
804 #else
805 "%x='31/05/2004'\t"
806 #endif
807 "%y='04'\t"
808 "%Y='2004'\t"
809 #if defined(__APPLE__) || defined(__FreeBSD__)
810 "%Ex='31.05.2004'\t"
811 #else
812 "%Ex='31/05/2004'\t"
813 #endif
814 "%EC='20'\t"
815 "%Ey='04'\t"
816 "%EY='2004'\t"
817 "%Ou='1'\t"
818 "%OU='22'\t"
819 "%OV='23'\t"
820 "%Ow='1'\t"
821 "%OW='22'\t"
822 "%Oy='04'\t"
823 "\n"),
824 lfmt,
825 std::chrono::year_month_day_last{std::chrono::year{2004}, std::chrono::month_day_last{std::chrono::May}});
826
827 // Use supplied locale (ja_JP)
828 check(
829 loc,
830 SV("%C='19'\t"
831 "%D='01/31/70'\t"
832 "%F='1970-01-31'\t"
833 "%j='031'\t"
834 "%g='70'\t"
835 "%G='1970'\t"
836 "%u='6'\t"
837 "%U='04'\t"
838 "%V='05'\t"
839 "%w='6'\t"
840 "%W='04'\t"
841 #if defined(__APPLE__) || defined(_AIX) || defined(_WIN32) || defined(__FreeBSD__)
842 "%x='1970/01/31'\t"
843 #else // defined(__APPLE__) || defined(_AIX) || defined(_WIN32) || defined(__FreeBSD__)
844 "%x='1970年01月31日'\t"
845 #endif // defined(__APPLE__) || defined(_AIX) || defined(_WIN32) || defined(__FreeBSD__)
846 "%y='70'\t"
847 "%Y='1970'\t"
848 #if defined(__APPLE__) || defined(_AIX) || defined(_WIN32) || defined(__FreeBSD__)
849 "%Ex='1970/01/31'\t"
850 "%EC='19'\t"
851 "%Ey='70'\t"
852 "%EY='1970'\t"
853 "%Ou='6'\t"
854 "%OU='04'\t"
855 "%OV='05'\t"
856 "%Ow='6'\t"
857 "%OW='04'\t"
858 "%Oy='70'\t"
859 #else // defined(__APPLE__) || defined(_AIX) || defined(_WIN32) || defined(__FreeBSD__)
860 "%Ex='昭和45年01月31日'\t"
861 "%EC='昭和'\t"
862 "%Ey='45'\t"
863 "%EY='昭和45年'\t"
864 "%Ou='六'\t"
865 "%OU='四'\t"
866 "%OV='五'\t"
867 "%Ow='六'\t"
868 "%OW='四'\t"
869 "%Oy='七十'\t"
870 #endif // defined(__APPLE__) || defined(_AIX) || defined(_WIN32) || defined(__FreeBSD__)
871 "\n"),
872 lfmt,
873 std::chrono::year_month_day_last{std::chrono::year{1970}, std::chrono::month_day_last{std::chrono::January}});
874
875 check(
876 loc,
877 SV("%C='20'\t"
878 "%D='05/31/04'\t"
879 "%F='2004-05-31'\t"
880 "%j='152'\t"
881 "%g='04'\t"
882 "%G='2004'\t"
883 "%u='1'\t"
884 "%U='22'\t"
885 "%V='23'\t"
886 "%w='1'\t"
887 "%W='22'\t"
888 #if defined(__APPLE__) || defined(_AIX) || defined(_WIN32) || defined(__FreeBSD__)
889 "%x='2004/05/31'\t"
890 #else // defined(__APPLE__) || defined(_AIX) || defined(_WIN32) || defined(__FreeBSD__)
891 "%x='2004年05月31日'\t"
892 #endif // defined(__APPLE__) || defined(_AIX) || defined(_WIN32) || defined(__FreeBSD__)
893 "%y='04'\t"
894 "%Y='2004'\t"
895 #if defined(__APPLE__) || defined(_AIX) || defined(_WIN32) || defined(__FreeBSD__)
896 "%Ex='2004/05/31'\t"
897 "%EC='20'\t"
898 "%Ey='04'\t"
899 "%EY='2004'\t"
900 "%Ou='1'\t"
901 "%OU='22'\t"
902 "%OV='23'\t"
903 "%Ow='1'\t"
904 "%OW='22'\t"
905 "%Oy='04'\t"
906 #else // defined(__APPLE__) || defined(_AIX) || defined(_WIN32) || defined(__FreeBSD__)
907 "%Ex='平成16年05月31日'\t"
908 "%EC='平成'\t"
909 "%Ey='16'\t"
910 "%EY='平成16年'\t"
911 "%Ou='一'\t"
912 "%OU='二十二'\t"
913 "%OV='二十三'\t"
914 "%Ow='一'\t"
915 "%OW='二十二'\t"
916 "%Oy='四'\t"
917 #endif // defined(__APPLE__) || defined(_AIX) || defined(_WIN32) || defined(__FreeBSD__)
918 "\n"),
919 lfmt,
920 std::chrono::year_month_day_last{std::chrono::year{2004}, std::chrono::month_day_last{std::chrono::May}});
921
922 std::locale::global(std::locale::classic());
923 }
924
925 template <class CharT>
926 static void test_valid_values() {
927 // Fields only using month and day.
928 test_valid_md_values<CharT>();
929 // Fields only using year, month, and day.
930 test_valid_ymd_values<CharT>();
931 }
932
933 template <class CharT>
934 static void test() {
935 test_no_chrono_specs<CharT>();
936 test_invalid_values<CharT>();
937 test_valid_values<CharT>();
938 check_invalid_types<CharT>(
939 {SV("a"), SV("A"), SV("b"), SV("B"), SV("C"), SV("d"), SV("D"), SV("e"), SV("EC"),
940 SV("Ex"), SV("Ey"), SV("EY"), SV("F"), SV("g"), SV("G"), SV("h"), SV("j"), SV("m"),
941 SV("Od"), SV("Oe"), SV("Om"), SV("Ou"), SV("OU"), SV("OV"), SV("Ow"), SV("OW"), SV("Oy"),
942 SV("u"), SV("U"), SV("V"), SV("w"), SV("W"), SV("x"), SV("y"), SV("Y")},
943 std::chrono::year_month_day_last{std::chrono::year{1970}, std::chrono::month_day_last{std::chrono::January}});
944
945 check_exception(
946 "The format specifier expects a '%' or a '}'",
947 SV("{:A"),
948 std::chrono::year_month_day_last{std::chrono::year{1970}, std::chrono::month_day_last{std::chrono::January}});
949 check_exception(
950 "The chrono specifiers contain a '{'",
951 SV("{:%%{"),
952 std::chrono::year_month_day_last{std::chrono::year{1970}, std::chrono::month_day_last{std::chrono::January}});
953 check_exception(
954 "End of input while parsing a conversion specifier",
955 SV("{:%"),
956 std::chrono::year_month_day_last{std::chrono::year{1970}, std::chrono::month_day_last{std::chrono::January}});
957 check_exception(
958 "End of input while parsing the modifier E",
959 SV("{:%E"),
960 std::chrono::year_month_day_last{std::chrono::year{1970}, std::chrono::month_day_last{std::chrono::January}});
961 check_exception(
962 "End of input while parsing the modifier O",
963 SV("{:%O"),
964 std::chrono::year_month_day_last{std::chrono::year{1970}, std::chrono::month_day_last{std::chrono::January}});
965
966 // Precision not allowed
967 check_exception(
968 "The format specifier expects a '%' or a '}'",
969 SV("{:.3}"),
970 std::chrono::year_month_day_last{std::chrono::year{1970}, std::chrono::month_day_last{std::chrono::January}});
971 }
972
973 int main(int, char**) {
974 test<char>();
975
976 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
977 test<wchar_t>();
978 #endif
979
980 return 0;
981 }