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

source code of libcxx/test/std/time/time.syn/formatter.year_month_day_last.pass.cpp