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 // TODO FMT Investigate Windows issues.
19 // REQUIRES: locale.fr_FR.UTF-8
20 // REQUIRES: locale.ja_JP.UTF-8
24 // class system_Clock;
26 // template<class charT, class traits>
27 // basic_ostream<charT, traits>&
28 // operator<<(basic_ostream<charT, traits>& os, const sys_days& dp);
35 #include "make_string.h"
36 #include "platform_support.h" // locale name macros
37 #include "test_macros.h"
38 #include "assert_macros.h"
39 #include "concat_macros.h"
41 #define SV(S) MAKE_STRING_VIEW(CharT, S)
43 #define TEST_EQUAL(OUT, EXPECTED) \
44 TEST_REQUIRE(OUT == EXPECTED, \
45 TEST_WRITE_CONCATENATED( \
46 "\nExpression ", #OUT, "\nExpected output ", EXPECTED, "\nActual output ", OUT, '\n'));
48 template <class CharT
>
49 static std::basic_string
<CharT
> stream_c_locale(const std::chrono::sys_days
& dp
) {
50 std::basic_stringstream
<CharT
> sstr
;
55 template <class CharT
>
56 static std::basic_string
<CharT
> stream_fr_FR_locale(const std::chrono::sys_days
& dp
) {
57 std::basic_stringstream
<CharT
> sstr
;
58 const std::locale
locale(LOCALE_fr_FR_UTF_8
);
64 template <class CharT
>
65 static std::basic_string
<CharT
> stream_ja_JP_locale(const std::chrono::sys_days
& dp
) {
66 std::basic_stringstream
<CharT
> sstr
;
67 const std::locale
locale(LOCALE_ja_JP_UTF_8
);
73 template <class CharT
>
75 TEST_EQUAL(stream_c_locale
<CharT
>(std::chrono::sys_days
{
76 std::chrono::year_month_day
{std::chrono::year
{-32'768}, std::chrono::month
{1}, std::chrono::day
{1}}}),
77 SV("-32768-01-01 is not a valid date"));
78 TEST_EQUAL(stream_c_locale
<CharT
>(std::chrono::sys_days
{
79 std::chrono::year_month_day
{std::chrono::year
{1970}, std::chrono::month
{1}, std::chrono::day
{1}}}),
81 TEST_EQUAL(stream_c_locale
<CharT
>(std::chrono::sys_days
{
82 std::chrono::year_month_day
{std::chrono::year
{2000}, std::chrono::month
{2}, std::chrono::day
{29}}}),
86 TEST_EQUAL(stream_c_locale
<CharT
>(std::chrono::sys_days
{
87 std::chrono::year_month_day
{std::chrono::year
{32'767}, std::chrono::month
{12}, std::chrono::day
{31}}}),
89 #elif defined(_WIN32) // defined(_AIX)
90 TEST_EQUAL(stream_c_locale
<CharT
>(std::chrono::sys_days
{
91 std::chrono::year_month_day
{std::chrono::year
{32'767}, std::chrono::month
{12}, std::chrono::day
{31}}}),
93 #else // defined(_AIX)
94 TEST_EQUAL(stream_c_locale
<CharT
>(std::chrono::sys_days
{
95 std::chrono::year_month_day
{std::chrono::year
{32'767}, std::chrono::month
{12}, std::chrono::day
{31}}}),
97 #endif // defined(_AIX)
99 // multiples of days are considered days.
100 TEST_EQUAL(stream_c_locale
<CharT
>(std::chrono::sys_time
<std::chrono::weeks
>{std::chrono::weeks
{3}}),
102 TEST_EQUAL(stream_c_locale
<CharT
>(std::chrono::sys_time
<std::chrono::duration
<int, std::ratio
<30 * 86400>>>{
103 std::chrono::duration
<int, std::ratio
<30 * 86400>>{1}}),
106 TEST_EQUAL(stream_fr_FR_locale
<CharT
>(std::chrono::sys_days
{
107 std::chrono::year_month_day
{std::chrono::year
{-32'768}, std::chrono::month
{1}, std::chrono::day
{1}}}),
108 SV("-32768-01-01 is not a valid date"));
109 TEST_EQUAL(stream_fr_FR_locale
<CharT
>(std::chrono::sys_days
{
110 std::chrono::year_month_day
{std::chrono::year
{1970}, std::chrono::month
{1}, std::chrono::day
{1}}}),
112 TEST_EQUAL(stream_fr_FR_locale
<CharT
>(std::chrono::sys_days
{
113 std::chrono::year_month_day
{std::chrono::year
{2000}, std::chrono::month
{2}, std::chrono::day
{29}}}),
116 TEST_EQUAL(stream_fr_FR_locale
<CharT
>(std::chrono::sys_days
{
117 std::chrono::year_month_day
{std::chrono::year
{32'767}, std::chrono::month
{12}, std::chrono::day
{31}}}),
119 #elif defined(_WIN32) // defined(_AIX)
120 TEST_EQUAL(stream_fr_FR_locale
<CharT
>(std::chrono::sys_days
{
121 std::chrono::year_month_day
{std::chrono::year
{32'767}, std::chrono::month
{12}, std::chrono::day
{31}}}),
123 #else // defined(_AIX)
124 TEST_EQUAL(stream_fr_FR_locale
<CharT
>(std::chrono::sys_days
{
125 std::chrono::year_month_day
{std::chrono::year
{32'767}, std::chrono::month
{12}, std::chrono::day
{31}}}),
127 #endif // defined(_AIX)
129 // multiples of days are considered days.
130 TEST_EQUAL(stream_fr_FR_locale
<CharT
>(std::chrono::sys_time
<std::chrono::weeks
>{std::chrono::weeks
{3}}),
132 TEST_EQUAL(stream_fr_FR_locale
<CharT
>(std::chrono::sys_time
<std::chrono::duration
<int, std::ratio
<30 * 86400>>>{
133 std::chrono::duration
<int, std::ratio
<30 * 86400>>{1}}),
136 TEST_EQUAL(stream_ja_JP_locale
<CharT
>(std::chrono::sys_days
{
137 std::chrono::year_month_day
{std::chrono::year
{-32'768}, std::chrono::month
{1}, std::chrono::day
{1}}}),
138 SV("-32768-01-01 is not a valid date"));
139 TEST_EQUAL(stream_ja_JP_locale
<CharT
>(std::chrono::sys_days
{
140 std::chrono::year_month_day
{std::chrono::year
{1970}, std::chrono::month
{1}, std::chrono::day
{1}}}),
142 TEST_EQUAL(stream_ja_JP_locale
<CharT
>(std::chrono::sys_days
{
143 std::chrono::year_month_day
{std::chrono::year
{2000}, std::chrono::month
{2}, std::chrono::day
{29}}}),
146 TEST_EQUAL(stream_ja_JP_locale
<CharT
>(std::chrono::sys_days
{
147 std::chrono::year_month_day
{std::chrono::year
{32'767}, std::chrono::month
{12}, std::chrono::day
{31}}}),
149 #elif defined(_WIN32) // defined(_AIX)
150 TEST_EQUAL(stream_ja_JP_locale
<CharT
>(std::chrono::sys_days
{
151 std::chrono::year_month_day
{std::chrono::year
{32'767}, std::chrono::month
{12}, std::chrono::day
{31}}}),
153 #else // defined(_AIX)
154 TEST_EQUAL(stream_ja_JP_locale
<CharT
>(std::chrono::sys_days
{
155 std::chrono::year_month_day
{std::chrono::year
{32'767}, std::chrono::month
{12}, std::chrono::day
{31}}}),
157 #endif // defined(_AIX)
159 // multiples of days are considered days.
160 TEST_EQUAL(stream_ja_JP_locale
<CharT
>(std::chrono::sys_time
<std::chrono::weeks
>{std::chrono::weeks
{3}}),
162 TEST_EQUAL(stream_ja_JP_locale
<CharT
>(std::chrono::sys_time
<std::chrono::duration
<int, std::ratio
<30 * 86400>>>{
163 std::chrono::duration
<int, std::ratio
<30 * 86400>>{1}}),
167 int main(int, char**) {
170 #ifndef TEST_HAS_NO_WIDE_CHARACTERS