1 //===----------------------------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 // UNSUPPORTED: c++03, c++11, c++14, c++17
10 // UNSUPPORTED: no-localization
11 // UNSUPPORTED: GCC-ALWAYS_INLINE-FIXME
13 // TODO FMT This test should not require std::to_chars(floating-point)
14 // XFAIL: availability-fp_to_chars-missing
16 // REQUIRES: locale.fr_FR.UTF-8
17 // REQUIRES: locale.ja_JP.UTF-8
21 // template<class charT> struct formatter<chrono::day, charT>;
30 #include <type_traits>
32 #include "formatter_tests.h"
33 #include "make_string.h"
34 #include "platform_support.h" // locale name macros
35 #include "test_macros.h"
37 template <class CharT
>
38 static void test_no_chrono_specs() {
39 using namespace std::literals::chrono_literals
;
41 std::locale::global(std::locale(LOCALE_fr_FR_UTF_8
));
43 // Non localized output
46 // using nanoseconds = duration<signed integer type of at least 64 bits, nano>;
47 // using microseconds = duration<signed integer type of at least 55 bits, micro>;
48 // using milliseconds = duration<signed integer type of at least 45 bits, milli>;
49 // using seconds = duration<signed integer type of at least 35 bits>;
50 // using minutes = duration<signed integer type of at least 29 bits, ratio< 60>>;
51 // using hours = duration<signed integer type of at least 23 bits, ratio<3600>>;
53 SV("1425-08-04 22:06:56"), SV("{}"), std::chrono::local_seconds(-17'179'869'184s
)); // Minimum value for 35 bits.
54 check(SV("1901-12-13 20:45:52"), SV("{}"), std::chrono::local_seconds(-2'147'483'648s
));
56 check(SV("1969-12-31 00:00:00"), SV("{}"), std::chrono::local_seconds(-24h
));
57 check(SV("1969-12-31 06:00:00"), SV("{}"), std::chrono::local_seconds(-18h
));
58 check(SV("1969-12-31 12:00:00"), SV("{}"), std::chrono::local_seconds(-12h
));
59 check(SV("1969-12-31 18:00:00"), SV("{}"), std::chrono::local_seconds(-6h
));
60 check(SV("1969-12-31 23:59:59"), SV("{}"), std::chrono::local_seconds(-1s
));
62 check(SV("1970-01-01 00:00:00"), SV("{}"), std::chrono::local_seconds(0s
));
63 check(SV("2000-01-01 00:00:00"), SV("{}"), std::chrono::local_seconds(946'684'800s
));
64 check(SV("2000-01-01 01:02:03"), SV("{}"), std::chrono::local_seconds(946'688'523s
));
66 check(SV("2038-01-19 03:14:07"), SV("{}"), std::chrono::local_seconds(2'147'483'647s
));
67 check(SV("2514-05-30 01:53:03"), SV("{}"), std::chrono::local_seconds(17'179'869'183s
)); // Maximum value for 35 bits.
69 check(SV("2000-01-01 01:02:03.123"), SV("{}"), std::chrono::local_time
<std::chrono::milliseconds
>(946'688'523'123ms
));
71 std::locale::global(std::locale::classic());
74 template <class CharT
>
75 static void test_valid_values_year() {
76 using namespace std::literals::chrono_literals
;
78 constexpr std::basic_string_view
<CharT
> fmt
=
79 SV("{:%%C='%C'%t%%EC='%EC'%t%%y='%y'%t%%Oy='%Oy'%t%%Ey='%Ey'%t%%Y='%Y'%t%%EY='%EY'%n}");
80 constexpr std::basic_string_view
<CharT
> lfmt
=
81 SV("{:L%%C='%C'%t%%EC='%EC'%t%%y='%y'%t%%Oy='%Oy'%t%%Ey='%Ey'%t%%Y='%Y'%t%%EY='%EY'%n}");
83 const std::locale
loc(LOCALE_ja_JP_UTF_8
);
84 std::locale::global(std::locale(LOCALE_fr_FR_UTF_8
));
86 // Non localized output using C-locale
87 check(SV("%C='19'\t%EC='19'\t%y='70'\t%Oy='70'\t%Ey='70'\t%Y='1970'\t%EY='1970'\n"),
89 std::chrono::local_seconds(0s
)); // 00:00:00 UTC Thursday, 1 January 1970
91 check(SV("%C='20'\t%EC='20'\t%y='09'\t%Oy='09'\t%Ey='09'\t%Y='2009'\t%EY='2009'\n"),
93 std::chrono::local_seconds(1'234'567'890s
)); // 23:31:30 UTC on Friday, 13 February 2009
95 // Use the global locale (fr_FR)
96 check(SV("%C='19'\t%EC='19'\t%y='70'\t%Oy='70'\t%Ey='70'\t%Y='1970'\t%EY='1970'\n"),
98 std::chrono::local_seconds(0s
)); // 00:00:00 UTC Thursday, 1 January 1970
100 check(SV("%C='20'\t%EC='20'\t%y='09'\t%Oy='09'\t%Ey='09'\t%Y='2009'\t%EY='2009'\n"),
102 std::chrono::local_seconds(1'234'567'890s
)); // 23:31:30 UTC on Friday, 13 February 2009
104 // Use supplied locale (ja_JP). This locale has a different alternate.
105 #if defined(_WIN32) || defined(__APPLE__) || defined(_AIX) || defined(__FreeBSD__)
107 SV("%C='19'\t%EC='19'\t%y='70'\t%Oy='70'\t%Ey='70'\t%Y='1970'\t%EY='1970'\n"),
109 std::chrono::local_seconds(0s
)); // 00:00:00 UTC Thursday, 1 January 1970
112 SV("%C='20'\t%EC='20'\t%y='09'\t%Oy='09'\t%Ey='09'\t%Y='2009'\t%EY='2009'\n"),
114 std::chrono::local_seconds(1'234'567'890s
)); // 23:31:30 UTC on Friday, 13 February 2009
115 #else // defined(_WIN32) || defined(__APPLE__) || defined(_AIX)||defined(__FreeBSD__)
117 SV("%C='19'\t%EC='昭和'\t%y='70'\t%Oy='七十'\t%Ey='45'\t%Y='1970'\t%EY='昭和45年'\n"),
119 std::chrono::local_seconds(0s
)); // 00:00:00 UTC Thursday, 1 January 1970
122 SV("%C='20'\t%EC='平成'\t%y='09'\t%Oy='九'\t%Ey='21'\t%Y='2009'\t%EY='平成21年'\n"),
124 std::chrono::local_seconds(1'234'567'890s
)); // 23:31:30 UTC on Friday, 13 February 2009
125 #endif // defined(_WIN32) || defined(__APPLE__) || defined(_AIX)||defined(__FreeBSD__)
127 std::locale::global(std::locale::classic());
130 template <class CharT
>
131 static void test_valid_values_month() {
132 using namespace std::literals::chrono_literals
;
134 constexpr std::basic_string_view
<CharT
> fmt
= SV("{:%%b='%b'%t%%h='%h'%t%%B='%B'%t%%m='%m'%t%%Om='%Om'%n}");
135 constexpr std::basic_string_view
<CharT
> lfmt
= SV("{:L%%b='%b'%t%%h='%h'%t%%B='%B'%t%%m='%m'%t%%Om='%Om'%n}");
137 const std::locale
loc(LOCALE_ja_JP_UTF_8
);
138 std::locale::global(std::locale(LOCALE_fr_FR_UTF_8
));
140 // Non localized output using C-locale
141 check(SV("%b='Jan'\t%h='Jan'\t%B='January'\t%m='01'\t%Om='01'\n"),
143 std::chrono::local_seconds(0s
)); // 00:00:00 UTC Thursday, 1 January 1970
145 check(SV("%b='May'\t%h='May'\t%B='May'\t%m='05'\t%Om='05'\n"),
147 std::chrono::local_seconds(2'000'000'000s
)); // 03:33:20 UTC on Wednesday, 18 May 2033
149 // Use the global locale (fr_FR)
150 #if defined(__APPLE__)
151 check(SV("%b='jan'\t%h='jan'\t%B='janvier'\t%m='01'\t%Om='01'\n"),
153 std::chrono::local_seconds(0s
)); // 00:00:00 UTC Thursday, 1 January 1970
155 check(SV("%b='janv.'\t%h='janv.'\t%B='janvier'\t%m='01'\t%Om='01'\n"),
157 std::chrono::local_seconds(0s
)); // 00:00:00 UTC Thursday, 1 January 1970
160 check(SV("%b='mai'\t%h='mai'\t%B='mai'\t%m='05'\t%Om='05'\n"),
162 std::chrono::local_seconds(2'000'000'000s
)); // 03:33:20 UTC on Wednesday, 18 May 2033
164 // Use supplied locale (ja_JP). This locale has a different alternate.
167 SV("%b='1'\t%h='1'\t%B='1月'\t%m='01'\t%Om='01'\n"),
169 std::chrono::local_seconds(0s
)); // 00:00:00 UTC Thursday, 1 January 1970
172 SV("%b='5'\t%h='5'\t%B='5月'\t%m='05'\t%Om='05'\n"),
174 std::chrono::local_seconds(2'000'000'000s
)); // 03:33:20 UTC on Wednesday, 18 May 2033
175 #elif defined(_AIX) // _WIN32
177 SV("%b='1月'\t%h='1月'\t%B='1月'\t%m='01'\t%Om='01'\n"),
179 std::chrono::local_seconds(0s
)); // 00:00:00 UTC Thursday, 1 January 1970
182 SV("%b='5月'\t%h='5月'\t%B='5月'\t%m='05'\t%Om='05'\n"),
184 std::chrono::local_seconds(2'000'000'000s
)); // 03:33:20 UTC on Wednesday, 18 May 2033
185 #elif defined(__APPLE__) // _WIN32
187 SV("%b=' 1'\t%h=' 1'\t%B='1月'\t%m='01'\t%Om='01'\n"),
189 std::chrono::local_seconds(0s
)); // 00:00:00 UTC Thursday, 1 January 1970
192 SV("%b=' 5'\t%h=' 5'\t%B='5月'\t%m='05'\t%Om='05'\n"),
194 std::chrono::local_seconds(2'000'000'000s
)); // 03:33:20 UTC on Wednesday, 18 May 2033
195 #elif defined(__FreeBSD__) // _WIN32
197 SV("%b=' 1月'\t%h=' 1月'\t%B='1月'\t%m='01'\t%Om='01'\n"),
199 std::chrono::local_seconds(0s
)); // 00:00:00 UTC Thursday, 1 January 1970
202 SV("%b=' 5月'\t%h=' 5月'\t%B='5月'\t%m='05'\t%Om='05'\n"),
204 std::chrono::local_seconds(2'000'000'000s
)); // 03:33:20 UTC on Wednesday, 18 May 2033
207 SV("%b=' 1月'\t%h=' 1月'\t%B='1月'\t%m='01'\t%Om='一'\n"),
209 std::chrono::local_seconds(0s
)); // 00:00:00 UTC Thursday, 1 January 1970
212 SV("%b=' 5月'\t%h=' 5月'\t%B='5月'\t%m='05'\t%Om='五'\n"),
214 std::chrono::local_seconds(2'000'000'000s
)); // 03:33:20 UTC on Wednesday, 18 May 2033
217 std::locale::global(std::locale::classic());
220 template <class CharT
>
221 static void test_valid_values_day() {
222 using namespace std::literals::chrono_literals
;
224 constexpr std::basic_string_view
<CharT
> fmt
= SV("{:%%d='%d'%t%%Od='%Od'%t%%e='%e'%t%%Oe='%Oe'%n}");
225 constexpr std::basic_string_view
<CharT
> lfmt
= SV("{:L%%d='%d'%t%%Od='%Od'%t%%e='%e'%t%%Oe='%Oe'%n}");
227 const std::locale
loc(LOCALE_ja_JP_UTF_8
);
228 std::locale::global(std::locale(LOCALE_fr_FR_UTF_8
));
230 // Non localized output using C-locale
231 check(SV("%d='01'\t%Od='01'\t%e=' 1'\t%Oe=' 1'\n"),
233 std::chrono::local_seconds(0s
)); // 00:00:00 UTC Thursday, 1 January 1970
235 check(SV("%d='13'\t%Od='13'\t%e='13'\t%Oe='13'\n"),
237 std::chrono::local_seconds(1'234'567'890s
)); // 23:31:30 UTC on Friday, 13 February 2009
239 // Use the global locale (fr_FR)
240 check(SV("%d='01'\t%Od='01'\t%e=' 1'\t%Oe=' 1'\n"),
242 std::chrono::local_seconds(0s
)); // 00:00:00 UTC Thursday, 1 January 1970
244 check(SV("%d='13'\t%Od='13'\t%e='13'\t%Oe='13'\n"),
246 std::chrono::local_seconds(1'234'567'890s
)); // 23:31:30 UTC on Friday, 13 February 2009
248 // Use supplied locale (ja_JP). This locale has a different alternate.
249 #if defined(_WIN32) || defined(__APPLE__) || defined(_AIX) || defined(__FreeBSD__)
251 SV("%d='01'\t%Od='01'\t%e=' 1'\t%Oe=' 1'\n"),
253 std::chrono::local_seconds(0s
)); // 00:00:00 UTC Thursday, 1 January 1970
256 SV("%d='13'\t%Od='13'\t%e='13'\t%Oe='13'\n"),
258 std::chrono::local_seconds(1'234'567'890s
)); // 23:31:30 UTC on Friday, 13 February 2009
259 #else // defined(_WIN32) || defined(__APPLE__) || defined(_AIX) || defined(__FreeBSD__)
261 SV("%d='01'\t%Od='一'\t%e=' 1'\t%Oe='一'\n"),
263 std::chrono::local_seconds(0s
)); // 00:00:00 UTC Thursday, 1 January 1970
266 SV("%d='13'\t%Od='十三'\t%e='13'\t%Oe='十三'\n"),
268 std::chrono::local_seconds(1'234'567'890s
)); // 23:31:30 UTC on Friday, 13 February 2009
270 #endif // defined(_WIN32) || defined(__APPLE__) || defined(_AIX) || defined(__FreeBSD__)
272 std::locale::global(std::locale::classic());
275 template <class CharT
>
276 static void test_valid_values_weekday() {
277 using namespace std::literals::chrono_literals
;
279 constexpr std::basic_string_view
<CharT
> fmt
=
280 SV("{:%%a='%a'%t%%A='%A'%t%%u='%u'%t%%Ou='%Ou'%t%%w='%w'%t%%Ow='%Ow'%n}");
281 constexpr std::basic_string_view
<CharT
> lfmt
=
282 SV("{:L%%a='%a'%t%%A='%A'%t%%u='%u'%t%%Ou='%Ou'%t%%w='%w'%t%%Ow='%Ow'%n}");
284 const std::locale
loc(LOCALE_ja_JP_UTF_8
);
285 std::locale::global(std::locale(LOCALE_fr_FR_UTF_8
));
287 // Non localized output using C-locale
288 check(SV("%a='Thu'\t%A='Thursday'\t%u='4'\t%Ou='4'\t%w='4'\t%Ow='4'\n"),
290 std::chrono::local_seconds(0s
)); // 00:00:00 UTC Thursday, 1 January 1970
292 check(SV("%a='Sun'\t%A='Sunday'\t%u='7'\t%Ou='7'\t%w='0'\t%Ow='0'\n"),
294 std::chrono::local_seconds(4'294'967'295s
)); // 06:28:15 UTC on Sunday, 7 February 2106
296 // Use the global locale (fr_FR)
297 #if defined(__APPLE__)
298 check(SV("%a='Jeu'\t%A='Jeudi'\t%u='4'\t%Ou='4'\t%w='4'\t%Ow='4'\n"),
300 std::chrono::local_seconds(0s
)); // 00:00:00 UTC Thursday, 1 January 1970
302 check(SV("%a='Dim'\t%A='Dimanche'\t%u='7'\t%Ou='7'\t%w='0'\t%Ow='0'\n"),
304 std::chrono::local_seconds(4'294'967'295s
)); // 06:28:15 UTC on Sunday, 7 February 2106
306 check(SV("%a='jeu.'\t%A='jeudi'\t%u='4'\t%Ou='4'\t%w='4'\t%Ow='4'\n"),
308 std::chrono::local_seconds(0s
)); // 00:00:00 UTC Thursday, 1 January 1970
310 check(SV("%a='dim.'\t%A='dimanche'\t%u='7'\t%Ou='7'\t%w='0'\t%Ow='0'\n"),
312 std::chrono::local_seconds(4'294'967'295s
)); // 06:28:15 UTC on Sunday, 7 February 2106
315 // Use supplied locale (ja_JP).
316 // This locale has a different alternate, but not on all platforms
317 #if defined(_WIN32) || defined(__APPLE__) || defined(_AIX) || defined(__FreeBSD__)
319 SV("%a='木'\t%A='木曜日'\t%u='4'\t%Ou='4'\t%w='4'\t%Ow='4'\n"),
321 std::chrono::local_seconds(0s
)); // 00:00:00 UTC Thursday, 1 January 1970
324 SV("%a='日'\t%A='日曜日'\t%u='7'\t%Ou='7'\t%w='0'\t%Ow='0'\n"),
326 std::chrono::local_seconds(4'294'967'295s
)); // 06:28:15 UTC on Sunday, 7 February 2106
327 #else // defined(_WIN32) || defined(__APPLE__) || defined(_AIX) || defined(__FreeBSD__)
329 SV("%a='木'\t%A='木曜日'\t%u='4'\t%Ou='四'\t%w='4'\t%Ow='四'\n"),
331 std::chrono::local_seconds(0s
)); // 00:00:00 UTC Thursday, 1 January 1970
334 SV("%a='日'\t%A='日曜日'\t%u='7'\t%Ou='七'\t%w='0'\t%Ow='〇'\n"),
336 std::chrono::local_seconds(4'294'967'295s
)); // 06:28:15 UTC on Sunday, 7 February 2106
337 #endif // defined(_WIN32) || defined(__APPLE__) || defined(_AIX) || defined(__FreeBSD__)
339 std::locale::global(std::locale::classic());
342 template <class CharT
>
343 static void test_valid_values_day_of_year() {
344 using namespace std::literals::chrono_literals
;
346 constexpr std::basic_string_view
<CharT
> fmt
= SV("{:%%j='%j'%n}");
347 constexpr std::basic_string_view
<CharT
> lfmt
= SV("{:L%%j='%j'%n}");
349 const std::locale
loc(LOCALE_ja_JP_UTF_8
);
350 std::locale::global(std::locale(LOCALE_fr_FR_UTF_8
));
352 // Non localized output using C-locale
353 check(SV("%j='001'\n"), fmt
, std::chrono::local_seconds(0s
)); // 00:00:00 UTC Thursday, 1 January 1970
354 check(SV("%j='138'\n"), fmt
, std::chrono::local_seconds(2'000'000'000s
)); // 03:33:20 UTC on Wednesday, 18 May 2033
356 // Use the global locale (fr_FR)
357 check(SV("%j='001'\n"), lfmt
, std::chrono::local_seconds(0s
)); // 00:00:00 UTC Thursday, 1 January 1970
358 check(SV("%j='138'\n"), lfmt
, std::chrono::local_seconds(2'000'000'000s
)); // 03:33:20 UTC on Wednesday, 18 May 2033
360 // Use supplied locale (ja_JP). This locale has a different alternate.
361 check(loc
, SV("%j='001'\n"), lfmt
, std::chrono::local_seconds(0s
)); // 00:00:00 UTC Thursday, 1 January 1970
366 std::chrono::local_seconds(2'000'000'000s
)); // 03:33:20 UTC on Wednesday, 18 May 2033
368 std::locale::global(std::locale::classic());
371 template <class CharT
>
372 static void test_valid_values_week() {
373 using namespace std::literals::chrono_literals
;
375 constexpr std::basic_string_view
<CharT
> fmt
= SV("{:%%U='%U'%t%%OU='%OU'%t%%W='%W'%t%%OW='%OW'%n}");
376 constexpr std::basic_string_view
<CharT
> lfmt
= SV("{:L%%U='%U'%t%%OU='%OU'%t%%W='%W'%t%%OW='%OW'%n}");
378 const std::locale
loc(LOCALE_ja_JP_UTF_8
);
379 std::locale::global(std::locale(LOCALE_fr_FR_UTF_8
));
381 // Non localized output using C-locale
382 check(SV("%U='00'\t%OU='00'\t%W='00'\t%OW='00'\n"),
384 std::chrono::local_seconds(0s
)); // 00:00:00 UTC Thursday, 1 January 1970
386 check(SV("%U='20'\t%OU='20'\t%W='20'\t%OW='20'\n"),
388 std::chrono::local_seconds(2'000'000'000s
)); // 03:33:20 UTC on Wednesday, 18 May 2033
390 // Use the global locale (fr_FR)
391 check(SV("%U='00'\t%OU='00'\t%W='00'\t%OW='00'\n"),
393 std::chrono::local_seconds(0s
)); // 00:00:00 UTC Thursday, 1 January 1970
395 check(SV("%U='20'\t%OU='20'\t%W='20'\t%OW='20'\n"),
397 std::chrono::local_seconds(2'000'000'000s
)); // 03:33:20 UTC on Wednesday, 18 May 2033
399 // Use supplied locale (ja_JP). This locale has a different alternate.
400 #if defined(_WIN32) || defined(__APPLE__) || defined(_AIX) || defined(__FreeBSD__)
402 SV("%U='00'\t%OU='00'\t%W='00'\t%OW='00'\n"),
404 std::chrono::local_seconds(0s
)); // 00:00:00 UTC Thursday, 1 January 1970
407 SV("%U='20'\t%OU='20'\t%W='20'\t%OW='20'\n"),
409 std::chrono::local_seconds(2'000'000'000s
)); // 03:33:20 UTC on Wednesday, 18 May 2033
410 #else // defined(_WIN32) || defined(__APPLE__) || defined(_AIX) || defined(__FreeBSD__)
412 SV("%U='00'\t%OU='〇'\t%W='00'\t%OW='〇'\n"),
414 std::chrono::local_seconds(0s
)); // 00:00:00 UTC Thursday, 1 January 1970
417 SV("%U='20'\t%OU='二十'\t%W='20'\t%OW='二十'\n"),
419 std::chrono::local_seconds(2'000'000'000s
)); // 03:33:20 UTC on Wednesday, 18 May 2033
420 #endif // defined(_WIN32) || defined(__APPLE__) || defined(_AIX) || defined(__FreeBSD__)
421 std::locale::global(std::locale::classic());
424 template <class CharT
>
425 static void test_valid_values_iso_8601_week() {
426 using namespace std::literals::chrono_literals
;
428 constexpr std::basic_string_view
<CharT
> fmt
= SV("{:%%g='%g'%t%%G='%G'%t%%V='%V'%t%%OV='%OV'%n}");
429 constexpr std::basic_string_view
<CharT
> lfmt
= SV("{:L%%g='%g'%t%%G='%G'%t%%V='%V'%t%%OV='%OV'%n}");
431 const std::locale
loc(LOCALE_ja_JP_UTF_8
);
432 std::locale::global(std::locale(LOCALE_fr_FR_UTF_8
));
434 // Non localized output using C-locale
435 check(SV("%g='70'\t%G='1970'\t%V='01'\t%OV='01'\n"),
437 std::chrono::local_seconds(0s
)); // 00:00:00 UTC Thursday, 1 January 1970
439 check(SV("%g='09'\t%G='2009'\t%V='07'\t%OV='07'\n"),
441 std::chrono::local_seconds(1'234'567'890s
)); // 23:31:30 UTC on Friday, 13 February 2009
443 // Use the global locale (fr_FR)
444 check(SV("%g='70'\t%G='1970'\t%V='01'\t%OV='01'\n"),
446 std::chrono::local_seconds(0s
)); // 00:00:00 UTC Thursday, 1 January 1970
448 check(SV("%g='09'\t%G='2009'\t%V='07'\t%OV='07'\n"),
450 std::chrono::local_seconds(1'234'567'890s
)); // 23:31:30 UTC on Friday, 13 February 2009
452 // Use supplied locale (ja_JP). This locale has a different alternate.
453 #if defined(_WIN32) || defined(__APPLE__) || defined(_AIX) || defined(__FreeBSD__)
455 SV("%g='70'\t%G='1970'\t%V='01'\t%OV='01'\n"),
457 std::chrono::local_seconds(0s
)); // 00:00:00 UTC Thursday, 1 January 1970
460 SV("%g='09'\t%G='2009'\t%V='07'\t%OV='07'\n"),
462 std::chrono::local_seconds(1'234'567'890s
)); // 23:31:30 UTC on Friday, 13 February 2009
463 #else // defined(_WIN32) || defined(__APPLE__) || defined(_AIX) || defined(__FreeBSD__)
465 SV("%g='70'\t%G='1970'\t%V='01'\t%OV='一'\n"),
467 std::chrono::local_seconds(0s
)); // 00:00:00 UTC Thursday, 1 January 1970
470 SV("%g='09'\t%G='2009'\t%V='07'\t%OV='七'\n"),
472 std::chrono::local_seconds(1'234'567'890s
)); // 23:31:30 UTC on Friday, 13 February 2009
473 #endif // defined(_WIN32) || defined(__APPLE__) || defined(_AIX) || defined(__FreeBSD__)
475 std::locale::global(std::locale::classic());
478 template <class CharT
>
479 static void test_valid_values_date() {
480 using namespace std::literals::chrono_literals
;
482 constexpr std::basic_string_view
<CharT
> fmt
= SV("{:%%D='%D'%t%%F='%F'%t%%x='%x'%t%%Ex='%Ex'%n}");
483 constexpr std::basic_string_view
<CharT
> lfmt
= SV("{:L%%D='%D'%t%%F='%F'%t%%x='%x'%t%%Ex='%Ex'%n}");
485 const std::locale
loc(LOCALE_ja_JP_UTF_8
);
486 std::locale::global(std::locale(LOCALE_fr_FR_UTF_8
));
488 // Non localized output using C-locale
489 check(SV("%D='01/01/70'\t%F='1970-01-01'\t%x='01/01/70'\t%Ex='01/01/70'\n"),
491 std::chrono::local_seconds(0s
)); // 00:00:00 UTC Thursday, 1 January 1970
493 check(SV("%D='02/13/09'\t%F='2009-02-13'\t%x='02/13/09'\t%Ex='02/13/09'\n"),
495 std::chrono::local_seconds(1'234'567'890s
)); // 23:31:30 UTC on Friday, 13 February 2009
497 // Use the global locale (fr_FR)
498 #if defined(__APPLE__) || defined(__FreeBSD__)
499 check(SV("%D='01/01/70'\t%F='1970-01-01'\t%x='01.01.1970'\t%Ex='01.01.1970'\n"),
501 std::chrono::local_seconds(0s
)); // 00:00:00 UTC Thursday, 1 January 1970
503 check(SV("%D='02/13/09'\t%F='2009-02-13'\t%x='13.02.2009'\t%Ex='13.02.2009'\n"),
505 std::chrono::local_seconds(1'234'567'890s
)); // 23:31:30 UTC on Friday, 13 February 2009
507 check(SV("%D='01/01/70'\t%F='1970-01-01'\t%x='01/01/1970'\t%Ex='01/01/1970'\n"),
509 std::chrono::local_seconds(0s
)); // 00:00:00 UTC Thursday, 1 January 1970
511 check(SV("%D='02/13/09'\t%F='2009-02-13'\t%x='13/02/2009'\t%Ex='13/02/2009'\n"),
513 std::chrono::local_seconds(1'234'567'890s
)); // 23:31:30 UTC on Friday, 13 February 2009
516 // Use supplied locale (ja_JP). This locale has a different alternate.
517 #if defined(_WIN32) || defined(__APPLE__) || defined(_AIX) || defined(__FreeBSD__)
519 SV("%D='01/01/70'\t%F='1970-01-01'\t%x='1970/01/01'\t%Ex='1970/01/01'\n"),
521 std::chrono::local_seconds(0s
)); // 00:00:00 UTC Thursday, 1 January 1970
524 SV("%D='02/13/09'\t%F='2009-02-13'\t%x='2009/02/13'\t%Ex='2009/02/13'\n"),
526 std::chrono::local_seconds(1'234'567'890s
)); // 23:31:30 UTC on Friday, 13 February 2009
527 #else // defined(_WIN32) || defined(__APPLE__) || defined(_AIX) || defined(__FreeBSD__)
529 SV("%D='01/01/70'\t%F='1970-01-01'\t%x='1970年01月01日'\t%Ex='昭和45年01月01日'\n"),
531 std::chrono::local_seconds(0s
)); // 00:00:00 UTC Thursday, 1 January 1970
534 SV("%D='02/13/09'\t%F='2009-02-13'\t%x='2009年02月13日'\t%Ex='平成21年02月13日'\n"),
536 std::chrono::local_seconds(1'234'567'890s
)); // 23:31:30 UTC on Friday, 13 February 2009
537 #endif // defined(_WIN32) || defined(__APPLE__) || defined(_AIX) || defined(__FreeBSD__)
539 std::locale::global(std::locale::classic());
542 template <class CharT
>
543 static void test_valid_values_time() {
544 using namespace std::literals::chrono_literals
;
546 constexpr std::basic_string_view
<CharT
> fmt
= SV(
563 constexpr std::basic_string_view
<CharT
> lfmt
= SV(
581 const std::locale
loc(LOCALE_ja_JP_UTF_8
);
582 std::locale::global(std::locale(LOCALE_fr_FR_UTF_8
));
584 // Non localized output using C-locale
601 std::chrono::local_seconds(0s
)); // 00:00:00 UTC Thursday, 1 January 1970
613 "%T='23:31:30.123'\t"
619 std::chrono::local_time
<std::chrono::milliseconds
>(
620 1'234'567'890'123ms
)); // 23:31:30 UTC on Friday, 13 February 2009
621 // Use the global locale (fr_FR)
641 #elif defined(__APPLE__) || defined(__FreeBSD__)
650 std::chrono::local_seconds(0s
)); // 00:00:00 UTC Thursday, 1 January 1970
666 "%T='23:31:30,123'\t"
671 #elif defined(__APPLE__) || defined(__FreeBSD__)
680 std::chrono::local_time
<std::chrono::milliseconds
>(
681 1'234'567'890'123ms
)); // 23:31:30 UTC on Friday, 13 February 2009
683 // Use supplied locale (ja_JP). This locale has a different alternate.a
684 #if defined(__APPLE__) || defined(_AIX) || defined(_WIN32) || defined(__FreeBSD__)
694 # if defined(__APPLE__)
701 # if defined(__APPLE__) || defined(__FreeBSD__)
702 # if defined(__APPLE__)
709 # elif defined(_WIN32)
720 std::chrono::hh_mm_ss(0s
));
731 # if defined(__APPLE__)
737 "%T='23:31:30.123'\t"
738 # if defined(__APPLE__) || defined(__FreeBSD__)
739 # if defined(__APPLE__)
746 # elif defined(_WIN32)
757 std::chrono::hh_mm_ss(23h
+ 31min
+ 30s
+ 123ms
));
758 #else // defined(__APPLE__) || defined(_AIX) || defined(_WIN32) || defined(__FreeBSD__)
776 std::chrono::local_seconds(0s
)); // 00:00:00 UTC Thursday, 1 January 1970
789 "%T='23:31:30.123'\t"
795 std::chrono::local_time
<std::chrono::milliseconds
>(
796 1'234'567'890'123ms
)); // 23:31:30 UTC on Friday, 13 February 2009
797 #endif // defined(__APPLE__) || defined(_AIX) || defined(_WIN32) || defined(__FreeBSD__)
799 std::locale::global(std::locale::classic());
802 template <class CharT
>
803 static void test_valid_values_date_time() {
804 using namespace std::literals::chrono_literals
;
806 constexpr std::basic_string_view
<CharT
> fmt
= SV("{:%%c='%c'%t%%Ec='%Ec'%n}");
807 constexpr std::basic_string_view
<CharT
> lfmt
= SV("{:L%%c='%c'%t%%Ec='%Ec'%n}");
809 const std::locale
loc(LOCALE_ja_JP_UTF_8
);
810 std::locale::global(std::locale(LOCALE_fr_FR_UTF_8
));
812 // Non localized output using C-locale
813 check(SV("%c='Thu Jan 1 00:00:00 1970'\t%Ec='Thu Jan 1 00:00:00 1970'\n"),
815 std::chrono::local_seconds(0s
)); // 00:00:00 UTC Thursday, 1 January 1970
817 check(SV("%c='Fri Feb 13 23:31:30 2009'\t%Ec='Fri Feb 13 23:31:30 2009'\n"),
819 std::chrono::local_seconds(1'234'567'890s
)); // 23:31:30 UTC on Friday, 13 February 2009
821 // Use the global locale (fr_FR)
823 // https://sourceware.org/bugzilla/show_bug.cgi?id=24054
824 #if defined(__powerpc__) && defined(__linux__)
825 SV("%c='jeu. 01 janv. 1970 00:00:00 UTC'\t%Ec='jeu. 01 janv. 1970 00:00:00 UTC'\n"),
826 #elif defined(__GLIBC__) && __GLIBC__ <= 2 && __GLIBC_MINOR__ < 29
827 SV("%c='jeu. 01 janv. 1970 00:00:00 GMT'\t%Ec='jeu. 01 janv. 1970 00:00:00 GMT'\n"),
829 SV("%c=' 1 janvier 1970 à 00:00:00 UTC'\t%Ec=' 1 janvier 1970 à 00:00:00 UTC'\n"),
830 #elif defined(__APPLE__)
831 SV("%c='Jeu 1 jan 00:00:00 1970'\t%Ec='Jeu 1 jan 00:00:00 1970'\n"),
832 #elif defined(_WIN32)
833 SV("%c='01/01/1970 00:00:00'\t%Ec='01/01/1970 00:00:00'\n"),
834 #elif defined(__FreeBSD__)
835 SV("%c='jeu. 1 janv. 00:00:00 1970'\t%Ec='jeu. 1 janv. 00:00:00 1970'\n"),
837 SV("%c='jeu. 01 janv. 1970 00:00:00'\t%Ec='jeu. 01 janv. 1970 00:00:00'\n"),
840 std::chrono::local_seconds(0s
)); // 00:00:00 UTC Thursday, 1 January 1970
843 // https://sourceware.org/bugzilla/show_bug.cgi?id=24054
844 #if defined(__powerpc__) && defined(__linux__)
845 SV("%c='ven. 13 févr. 2009 23:31:30 UTC'\t%Ec='ven. 13 févr. 2009 23:31:30 UTC'\n"),
846 #elif defined(__GLIBC__) && __GLIBC__ <= 2 && __GLIBC_MINOR__ < 29
847 SV("%c='ven. 13 févr. 2009 23:31:30 GMT'\t%Ec='ven. 13 févr. 2009 23:31:30 GMT'\n"),
849 SV("%c='13 février 2009 à 23:31:30 UTC'\t%Ec='13 février 2009 à 23:31:30 UTC'\n"),
850 #elif defined(__APPLE__)
851 SV("%c='Ven 13 fév 23:31:30 2009'\t%Ec='Ven 13 fév 23:31:30 2009'\n"),
852 #elif defined(_WIN32)
853 SV("%c='13/02/2009 23:31:30'\t%Ec='13/02/2009 23:31:30'\n"),
854 #elif defined(__FreeBSD__)
855 SV("%c='ven. 13 févr. 23:31:30 2009'\t%Ec='ven. 13 févr. 23:31:30 2009'\n"),
857 SV("%c='ven. 13 févr. 2009 23:31:30'\t%Ec='ven. 13 févr. 2009 23:31:30'\n"),
860 std::chrono::local_seconds(1'234'567'890s
)); // 23:31:30 UTC on Friday, 13 February 2009
862 // Use supplied locale (ja_JP). This locale has a different alternate.a
863 #if defined(__APPLE__) || defined(__FreeBSD__)
865 SV("%c='木 1/ 1 00:00:00 1970'\t%Ec='木 1/ 1 00:00:00 1970'\n"),
867 std::chrono::local_seconds(0s
)); // 00:00:00 UTC Thursday, 1 January 1970
869 SV("%c='金 2/13 23:31:30 2009'\t%Ec='金 2/13 23:31:30 2009'\n"),
871 std::chrono::local_seconds(1'234'567'890s
)); // 23:31:30 UTC on Friday, 13 February 2009
872 #elif defined(_AIX) // defined(__APPLE__)|| defined(__FreeBSD__)
874 SV("%c='1970年01月 1日 00:00:00 UTC'\t%Ec='1970年01月 1日 00:00:00 UTC'\n"),
876 std::chrono::local_seconds(0s
)); // 00:00:00 UTC Thursday, 1 January 1970
878 SV("%c='2009年02月13日 23:31:30 UTC'\t%Ec='2009年02月13日 23:31:30 UTC'\n"),
880 std::chrono::local_seconds(1'234'567'890s
)); // 23:31:30 UTC on Friday, 13 February 2009
881 #elif defined(_WIN32) // defined(__APPLE__)|| defined(__FreeBSD__)
883 SV("%c='1970/01/01 0:00:00'\t%Ec='1970/01/01 0:00:00'\n"),
885 std::chrono::sys_seconds(0s
)); // 00:00:00 UTC Thursday, 1 January 1970
887 SV("%c='2009/02/13 23:31:30'\t%Ec='2009/02/13 23:31:30'\n"),
889 std::chrono::sys_seconds(1'234'567'890s
)); // 23:31:30 UTC on Friday, 13 February 2009
890 #else // defined(__APPLE__)|| defined(__FreeBSD__)
892 SV("%c='1970年01月01日 00時00分00秒'\t%Ec='昭和45年01月01日 00時00分00秒'\n"),
894 std::chrono::local_seconds(0s
)); // 00:00:00 UTC Thursday, 1 January 1970
897 SV("%c='2009年02月13日 23時31分30秒'\t%Ec='平成21年02月13日 23時31分30秒'\n"),
899 std::chrono::local_seconds(1'234'567'890s
)); // 23:31:30 UTC on Friday, 13 February 2009
900 #endif // defined(__APPLE__)|| defined(__FreeBSD__)
902 std::locale::global(std::locale::classic());
905 template <class CharT
>
906 static void test_valid_values() {
907 test_valid_values_year
<CharT
>();
908 test_valid_values_month
<CharT
>();
909 test_valid_values_day
<CharT
>();
910 test_valid_values_weekday
<CharT
>();
911 test_valid_values_day_of_year
<CharT
>();
912 test_valid_values_week
<CharT
>();
913 test_valid_values_iso_8601_week
<CharT
>();
914 test_valid_values_date
<CharT
>();
915 test_valid_values_time
<CharT
>();
916 test_valid_values_date_time
<CharT
>();
919 template <class CharT
>
921 using namespace std::literals::chrono_literals
;
923 test_no_chrono_specs
<CharT
>();
924 test_valid_values
<CharT
>();
925 check_invalid_types
<CharT
>(
927 SV("a"), SV("A"), SV("b"), SV("B"), SV("c"), SV("C"), SV("d"), SV("D"), SV("e"), SV("F"), SV("g"),
928 SV("G"), SV("h"), SV("H"), SV("I"), SV("j"), SV("m"), SV("M"), SV("p"), SV("r"), SV("R"), SV("S"),
929 SV("T"), SV("u"), SV("U"), SV("V"), SV("w"), SV("W"), SV("x"), SV("X"), SV("y"), SV("Y"), SV("Ec"),
930 SV("EC"), SV("Ex"), SV("EX"), SV("Ey"), SV("EY"), SV("Od"), SV("Oe"), SV("OH"), SV("OI"), SV("Om"), SV("OM"),
931 SV("OS"), SV("Ou"), SV("OU"), SV("OV"), SV("Ow"), SV("OW"), SV("Oy"),
933 std::chrono::local_seconds(0s
));
935 check_exception("The format specifier expects a '%' or a '}'", SV("{:A"), std::chrono::local_seconds(0s
));
936 check_exception("The chrono specifiers contain a '{'", SV("{:%%{"), std::chrono::local_seconds(0s
));
937 check_exception("End of input while parsing a conversion specifier", SV("{:%"), std::chrono::local_seconds(0s
));
938 check_exception("End of input while parsing the modifier E", SV("{:%E"), std::chrono::local_seconds(0s
));
939 check_exception("End of input while parsing the modifier O", SV("{:%O"), std::chrono::local_seconds(0s
));
941 // Precision not allowed
942 check_exception("The format specifier expects a '%' or a '}'", SV("{:.3}"), std::chrono::local_seconds(0s
));
945 int main(int, char**) {
948 #ifndef TEST_HAS_NO_WIDE_CHARACTERS