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