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