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