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 // XFAIL: availability-fp_to_chars-missing
15 // REQUIRES: locale.fr_FR.UTF-8
16 // REQUIRES: locale.ja_JP.UTF-8
22 // template<class charT, class traits, class Duration>
23 // basic_ostream<charT, traits>&
24 // operator<<(basic_ostream<charT, traits>& os, const hh_mm_ss<Duration>& hms);
31 #include "make_string.h"
32 #include "platform_support.h" // locale name macros
33 #include "test_macros.h"
35 #define SV(S) MAKE_STRING_VIEW(CharT, S)
37 template <class CharT
, class Duration
>
38 static std::basic_string
<CharT
> stream_c_locale(std::chrono::hh_mm_ss
<Duration
> hms
) {
39 std::basic_stringstream
<CharT
> sstr
;
44 template <class CharT
, class Duration
>
45 static std::basic_string
<CharT
> stream_fr_FR_locale(std::chrono::hh_mm_ss
<Duration
> hms
) {
46 std::basic_stringstream
<CharT
> sstr
;
47 const std::locale
locale(LOCALE_fr_FR_UTF_8
);
53 template <class CharT
, class Duration
>
54 static std::basic_string
<CharT
> stream_ja_JP_locale(std::chrono::hh_mm_ss
<Duration
> hms
) {
55 std::basic_stringstream
<CharT
> sstr
;
56 const std::locale
locale(LOCALE_ja_JP_UTF_8
);
62 template <class CharT
>
64 // Note std::atto can't be tested since the ratio conversion from std::atto
65 // std::chrono::seconds to std::chrono::hours overflows when intmax_t is a
66 // 64-bit type. This is a limitiation in the constructor of
67 // std::chrono::hh_mm_ss.
69 // C locale - integral power of 10 ratios
70 assert(stream_c_locale
<CharT
>(std::chrono::hh_mm_ss
{std::chrono::duration
<std::intmax_t, std::femto
>{1'234'567'890}}) ==
71 SV("00:00:00.000001234567890"));
72 assert(stream_c_locale
<CharT
>(std::chrono::hh_mm_ss
{std::chrono::duration
<std::intmax_t, std::pico
>{1'234'567'890}}) ==
73 SV("00:00:00.001234567890"));
74 assert(stream_c_locale
<CharT
>(std::chrono::hh_mm_ss
{std::chrono::duration
<std::intmax_t, std::nano
>{1'234'567'890}}) ==
75 SV("00:00:01.234567890"));
76 assert(stream_c_locale
<CharT
>(std::chrono::hh_mm_ss
{std::chrono::duration
<std::intmax_t, std::micro
>{1'234'567}}) ==
77 SV("00:00:01.234567"));
78 assert(stream_c_locale
<CharT
>(std::chrono::hh_mm_ss
{std::chrono::duration
<std::intmax_t, std::milli
>{123'456}}) ==
80 assert(stream_c_locale
<CharT
>(std::chrono::hh_mm_ss
{std::chrono::duration
<std::intmax_t, std::centi
>{12'345}}) ==
82 assert(stream_c_locale
<CharT
>(std::chrono::hh_mm_ss
{std::chrono::duration
<std::intmax_t, std::deci
>{1'234}}) ==
85 assert(stream_c_locale
<CharT
>(std::chrono::hh_mm_ss
{std::chrono::duration
<std::intmax_t>{123}}) == SV("00:02:03"));
87 assert(stream_c_locale
<CharT
>(std::chrono::hh_mm_ss
{std::chrono::duration
<std::intmax_t, std::deca
>{-366}}) ==
89 assert(stream_c_locale
<CharT
>(std::chrono::hh_mm_ss
{std::chrono::duration
<std::intmax_t, std::hecto
>{-72}}) ==
91 assert(stream_c_locale
<CharT
>(std::chrono::hh_mm_ss
{std::chrono::duration
<std::intmax_t, std::kilo
>{-86}}) ==
94 // Starting at mega it will pass one day
96 // fr_FR locale - integral power of not 10 ratios
97 assert(stream_fr_FR_locale
<CharT
>(std::chrono::hh_mm_ss
{
98 std::chrono::duration
<std::intmax_t, std::ratio
<1, 5'000'000>>{5'000}}) == SV("00:00:00,0010000"));
99 assert(stream_fr_FR_locale
<CharT
>(std::chrono::hh_mm_ss
{std::chrono::duration
<std::intmax_t, std::ratio
<1, 8'000>>{3}}) ==
100 SV("00:00:00,000375"));
101 assert(stream_fr_FR_locale
<CharT
>(std::chrono::hh_mm_ss
{std::chrono::duration
<std::intmax_t, std::ratio
<1, 4'000>>{1}}) ==
102 SV("00:00:00,00025"));
103 assert(stream_fr_FR_locale
<CharT
>(std::chrono::hh_mm_ss
{std::chrono::duration
<std::intmax_t, std::ratio
<1, 5'000>>{5}}) ==
104 SV("00:00:00,0010"));
105 assert(stream_fr_FR_locale
<CharT
>(std::chrono::hh_mm_ss
{std::chrono::duration
<std::intmax_t, std::ratio
<1, 8>>{-4}}) ==
106 SV("-00:00:00,500"));
107 assert(stream_fr_FR_locale
<CharT
>(std::chrono::hh_mm_ss
{std::chrono::duration
<std::intmax_t, std::ratio
<1, 4>>{-8}}) ==
109 assert(stream_fr_FR_locale
<CharT
>(std::chrono::hh_mm_ss
{std::chrono::duration
<std::intmax_t, std::ratio
<1, 5>>{-5}}) ==
112 // TODO FMT Note there's no wording on the rounding
113 assert(stream_fr_FR_locale
<CharT
>(std::chrono::hh_mm_ss
{std::chrono::duration
<std::intmax_t, std::ratio
<1, 9>>{5}}) ==
114 SV("00:00:00,555555"));
115 assert(stream_fr_FR_locale
<CharT
>(std::chrono::hh_mm_ss
{std::chrono::duration
<std::intmax_t, std::ratio
<1, 7>>{7}}) ==
116 SV("00:00:01,000000"));
117 assert(stream_fr_FR_locale
<CharT
>(std::chrono::hh_mm_ss
{std::chrono::duration
<std::intmax_t, std::ratio
<1, 6>>{1}}) ==
118 SV("00:00:00,166666"));
119 assert(stream_fr_FR_locale
<CharT
>(std::chrono::hh_mm_ss
{std::chrono::duration
<std::intmax_t, std::ratio
<1, 3>>{2}}) ==
120 SV("00:00:00,666666"));
122 // ja_JP locale - floating points
123 assert(stream_ja_JP_locale
<CharT
>(std::chrono::hh_mm_ss
{
124 std::chrono::duration
<long double, std::femto
>{1'234'567'890.123}}) == SV("00:00:00.000001234567890"));
125 assert(stream_ja_JP_locale
<CharT
>(std::chrono::hh_mm_ss
{
126 std::chrono::duration
<long double, std::pico
>{1'234'567'890.123}}) == SV("00:00:00.001234567890"));
127 assert(stream_ja_JP_locale
<CharT
>(std::chrono::hh_mm_ss
{
128 std::chrono::duration
<long double, std::nano
>{1'234'567'890.123}}) == SV("00:00:01.234567890"));
129 assert(stream_ja_JP_locale
<CharT
>(std::chrono::hh_mm_ss
{std::chrono::duration
<double, std::micro
>{1'234'567.123}}) ==
130 SV("00:00:01.234567"));
131 assert(stream_ja_JP_locale
<CharT
>(std::chrono::hh_mm_ss
{std::chrono::duration
<double, std::milli
>{123'456.123}}) ==
133 assert(stream_ja_JP_locale
<CharT
>(std::chrono::hh_mm_ss
{std::chrono::duration
<double, std::centi
>{12'345.123}}) ==
135 assert(stream_ja_JP_locale
<CharT
>(std::chrono::hh_mm_ss
{std::chrono::duration
<float, std::deci
>{1'234.123}}) ==
138 assert(stream_ja_JP_locale
<CharT
>(std::chrono::hh_mm_ss
{std::chrono::duration
<float>{123.123}}) == SV("00:02:03"));
140 assert(stream_ja_JP_locale
<CharT
>(std::chrono::hh_mm_ss
{std::chrono::duration
<double, std::deca
>{-366.5}}) ==
142 assert(stream_ja_JP_locale
<CharT
>(std::chrono::hh_mm_ss
{std::chrono::duration
<double, std::hecto
>{-72.64}}) ==
144 assert(stream_ja_JP_locale
<CharT
>(std::chrono::hh_mm_ss
{std::chrono::duration
<double, std::kilo
>{-86}}) ==
148 int main(int, char**) {
151 #ifndef TEST_HAS_NO_WIDE_CHARACTERS