| 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-localization |
| 11 | // UNSUPPORTED: GCC-ALWAYS_INLINE-FIXME |
| 12 | |
| 13 | // TODO FMT This test should not require std::to_chars(floating-point) |
| 14 | // XFAIL: availability-fp_to_chars-missing |
| 15 | |
| 16 | // TODO FMT Investigate Windows issues. |
| 17 | // XFAIL: msvc |
| 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::year_month_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 "string_literal.h" |
| 39 | #include "test_macros.h" |
| 40 | |
| 41 | template <class CharT> |
| 42 | static void test_no_chrono_specs() { |
| 43 | // Valid year, valid month, valid day |
| 44 | check(SV("1970-01-31" ), |
| 45 | SV("{}" ), |
| 46 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::month{1}, std::chrono::day{31}}); |
| 47 | check(SV("*1970-01-31*" ), |
| 48 | SV("{:*^12}" ), |
| 49 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::month{1}, std::chrono::day{31}}); |
| 50 | check(SV("*1970-01-31" ), |
| 51 | SV("{:*>11}" ), |
| 52 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::month{1}, std::chrono::day{31}}); |
| 53 | |
| 54 | // Valid year, valid month, invalid day |
| 55 | check(SV("1970-02-31 is not a valid date" ), |
| 56 | SV("{}" ), |
| 57 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::month{2}, std::chrono::day{31}}); |
| 58 | check(SV("*1970-02-31 is not a valid date*" ), |
| 59 | SV("{:*^32}" ), |
| 60 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::month{2}, std::chrono::day{31}}); |
| 61 | check(SV("*1970-02-31 is not a valid date" ), |
| 62 | SV("{:*>31}" ), |
| 63 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::month{2}, std::chrono::day{31}}); |
| 64 | |
| 65 | // Valid year, invalid month, valid day |
| 66 | check(SV("1970-00-31 is not a valid date" ), |
| 67 | SV("{}" ), |
| 68 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::month{0}, std::chrono::day{31}}); |
| 69 | check(SV("*1970-00-31 is not a valid date*" ), |
| 70 | SV("{:*^32}" ), |
| 71 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::month{0}, std::chrono::day{31}}); |
| 72 | check(SV("*1970-00-31 is not a valid date" ), |
| 73 | SV("{:*>31}" ), |
| 74 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::month{0}, std::chrono::day{31}}); |
| 75 | |
| 76 | // Valid year, invalid month, invalid day |
| 77 | check(SV("1970-00-32 is not a valid date" ), |
| 78 | SV("{}" ), |
| 79 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::month{0}, std::chrono::day{32}}); |
| 80 | check(SV("*1970-00-32 is not a valid date*" ), |
| 81 | SV("{:*^32}" ), |
| 82 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::month{0}, std::chrono::day{32}}); |
| 83 | check(SV("*1970-00-32 is not a valid date" ), |
| 84 | SV("{:*>31}" ), |
| 85 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::month{0}, std::chrono::day{32}}); |
| 86 | |
| 87 | // Invalid year, valid month, valid day |
| 88 | check(SV("-32768-01-31 is not a valid date" ), |
| 89 | SV("{}" ), |
| 90 | std::chrono::year_month_day{std::chrono::year{-32768}, std::chrono::month{1}, std::chrono::day{31}}); |
| 91 | check(SV("*-32768-01-31 is not a valid date*" ), |
| 92 | SV("{:*^34}" ), |
| 93 | std::chrono::year_month_day{std::chrono::year{-32768}, std::chrono::month{1}, std::chrono::day{31}}); |
| 94 | check(SV("*-32768-01-31 is not a valid date" ), |
| 95 | SV("{:*>33}" ), |
| 96 | std::chrono::year_month_day{std::chrono::year{-32768}, std::chrono::month{1}, std::chrono::day{31}}); |
| 97 | |
| 98 | // Invalid year, valid month, invalid day |
| 99 | check(SV("-32768-01-32 is not a valid date" ), |
| 100 | SV("{}" ), |
| 101 | std::chrono::year_month_day{std::chrono::year{-32768}, std::chrono::month{1}, std::chrono::day{32}}); |
| 102 | check(SV("*-32768-01-32 is not a valid date*" ), |
| 103 | SV("{:*^34}" ), |
| 104 | std::chrono::year_month_day{std::chrono::year{-32768}, std::chrono::month{1}, std::chrono::day{32}}); |
| 105 | check(SV("*-32768-01-32 is not a valid date" ), |
| 106 | SV("{:*>33}" ), |
| 107 | std::chrono::year_month_day{std::chrono::year{-32768}, std::chrono::month{1}, std::chrono::day{32}}); |
| 108 | |
| 109 | // Invalid year, invalid month, valid day |
| 110 | check(SV("-32768-00-31 is not a valid date" ), |
| 111 | SV("{}" ), |
| 112 | std::chrono::year_month_day{std::chrono::year{-32768}, std::chrono::month{0}, std::chrono::day{31}}); |
| 113 | check(SV("*-32768-00-31 is not a valid date*" ), |
| 114 | SV("{:*^34}" ), |
| 115 | std::chrono::year_month_day{std::chrono::year{-32768}, std::chrono::month{0}, std::chrono::day{31}}); |
| 116 | check(SV("*-32768-00-31 is not a valid date" ), |
| 117 | SV("{:*>33}" ), |
| 118 | std::chrono::year_month_day{std::chrono::year{-32768}, std::chrono::month{0}, std::chrono::day{31}}); |
| 119 | |
| 120 | // Invalid year, invalid month, invalid day |
| 121 | check(SV("-32768-00-32 is not a valid date" ), |
| 122 | SV("{}" ), |
| 123 | std::chrono::year_month_day{std::chrono::year{-32768}, std::chrono::month{0}, std::chrono::day{32}}); |
| 124 | check(SV("*-32768-00-32 is not a valid date*" ), |
| 125 | SV("{:*^34}" ), |
| 126 | std::chrono::year_month_day{std::chrono::year{-32768}, std::chrono::month{0}, std::chrono::day{32}}); |
| 127 | check(SV("*-32768-00-32 is not a valid date" ), |
| 128 | SV("{:*>33}" ), |
| 129 | std::chrono::year_month_day{std::chrono::year{-32768}, std::chrono::month{0}, std::chrono::day{32}}); |
| 130 | } |
| 131 | |
| 132 | // TODO FMT Should x throw? |
| 133 | template <class CharT> |
| 134 | static void test_invalid_values() { |
| 135 | // Test that %a, %A, %b, %B, %h, %j, %u, %U, %V, %w, %W, %Ou, %OU, %OV, %Ow, and %OW throw an exception. |
| 136 | check_exception("Formatting a weekday name needs a valid weekday" , |
| 137 | SV("{:%A}" ), |
| 138 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::month{1}, std::chrono::day{0}}); |
| 139 | check_exception("Formatting a weekday name needs a valid weekday" , |
| 140 | SV("{:%A}" ), |
| 141 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::month{1}, std::chrono::day{32}}); |
| 142 | check_exception("Formatting a weekday name needs a valid weekday" , |
| 143 | SV("{:%A}" ), |
| 144 | std::chrono::year_month_day{ |
| 145 | std::chrono::year{1970}, std::chrono::month{2}, std::chrono::day{29}}); // not a leap year |
| 146 | check_exception("Formatting a weekday name needs a valid weekday" , |
| 147 | SV("{:%A}" ), |
| 148 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::month{0}, std::chrono::day{31}}); |
| 149 | check_exception("Formatting a weekday name needs a valid weekday" , |
| 150 | SV("{:%A}" ), |
| 151 | std::chrono::year_month_day{std::chrono::year{-32768}, std::chrono::month{1}, std::chrono::day{31}}); |
| 152 | |
| 153 | check_exception("Formatting a weekday name needs a valid weekday" , |
| 154 | SV("{:%a}" ), |
| 155 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::month{1}, std::chrono::day{0}}); |
| 156 | check_exception("Formatting a weekday name needs a valid weekday" , |
| 157 | SV("{:%a}" ), |
| 158 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::month{1}, std::chrono::day{32}}); |
| 159 | check_exception("Formatting a weekday name needs a valid weekday" , |
| 160 | SV("{:%a}" ), |
| 161 | std::chrono::year_month_day{ |
| 162 | std::chrono::year{1970}, std::chrono::month{2}, std::chrono::day{29}}); // not a leap year |
| 163 | check_exception("Formatting a weekday name needs a valid weekday" , |
| 164 | SV("{:%a}" ), |
| 165 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::month{0}, std::chrono::day{31}}); |
| 166 | check_exception("Formatting a weekday name needs a valid weekday" , |
| 167 | SV("{:%a}" ), |
| 168 | std::chrono::year_month_day{std::chrono::year{-32768}, std::chrono::month{1}, std::chrono::day{31}}); |
| 169 | |
| 170 | check_exception("Formatting a month name from an invalid month number" , |
| 171 | SV("{:%B}" ), |
| 172 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::month{0}, std::chrono::day{31}}); |
| 173 | check_exception("Formatting a month name from an invalid month number" , |
| 174 | SV("{:%B}" ), |
| 175 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::month{13}, std::chrono::day{31}}); |
| 176 | check_exception("Formatting a month name from an invalid month number" , |
| 177 | SV("{:%B}" ), |
| 178 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::month{255}, std::chrono::day{31}}); |
| 179 | |
| 180 | check_exception("Formatting a month name from an invalid month number" , |
| 181 | SV("{:%b}" ), |
| 182 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::month{200}, std::chrono::day{31}}); |
| 183 | check_exception("Formatting a month name from an invalid month number" , |
| 184 | SV("{:%b}" ), |
| 185 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::month{13}, std::chrono::day{31}}); |
| 186 | check_exception("Formatting a month name from an invalid month number" , |
| 187 | SV("{:%b}" ), |
| 188 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::month{255}, std::chrono::day{31}}); |
| 189 | |
| 190 | check_exception("Formatting a month name from an invalid month number" , |
| 191 | SV("{:%h}" ), |
| 192 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::month{0}, std::chrono::day{31}}); |
| 193 | check_exception("Formatting a month name from an invalid month number" , |
| 194 | SV("{:%h}" ), |
| 195 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::month{13}, std::chrono::day{31}}); |
| 196 | check_exception("Formatting a month name from an invalid month number" , |
| 197 | SV("{:%h}" ), |
| 198 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::month{255}, std::chrono::day{31}}); |
| 199 | |
| 200 | check_exception("Formatting a day of year needs a valid date" , |
| 201 | SV("{:%j}" ), |
| 202 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::month{1}, std::chrono::day{0}}); |
| 203 | check_exception("Formatting a day of year needs a valid date" , |
| 204 | SV("{:%j}" ), |
| 205 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::month{1}, std::chrono::day{32}}); |
| 206 | check_exception("Formatting a day of year needs a valid date" , |
| 207 | SV("{:%j}" ), |
| 208 | std::chrono::year_month_day{ |
| 209 | std::chrono::year{1970}, std::chrono::month{2}, std::chrono::day{29}}); // not a leap year |
| 210 | check_exception("Formatting a day of year needs a valid date" , |
| 211 | SV("{:%j}" ), |
| 212 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::month{0}, std::chrono::day{31}}); |
| 213 | check_exception("Formatting a day of year needs a valid date" , |
| 214 | SV("{:%j}" ), |
| 215 | std::chrono::year_month_day{std::chrono::year{-32768}, std::chrono::month{1}, std::chrono::day{31}}); |
| 216 | |
| 217 | check_exception("Formatting a weekday needs a valid weekday" , |
| 218 | SV("{:%u}" ), |
| 219 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::month{1}, std::chrono::day{0}}); |
| 220 | check_exception("Formatting a weekday needs a valid weekday" , |
| 221 | SV("{:%u}" ), |
| 222 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::month{1}, std::chrono::day{32}}); |
| 223 | check_exception("Formatting a weekday needs a valid weekday" , |
| 224 | SV("{:%u}" ), |
| 225 | std::chrono::year_month_day{ |
| 226 | std::chrono::year{1970}, std::chrono::month{2}, std::chrono::day{29}}); // not a leap year |
| 227 | check_exception("Formatting a weekday needs a valid weekday" , |
| 228 | SV("{:%u}" ), |
| 229 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::month{0}, std::chrono::day{31}}); |
| 230 | check_exception("Formatting a weekday needs a valid weekday" , |
| 231 | SV("{:%u}" ), |
| 232 | std::chrono::year_month_day{std::chrono::year{-32768}, std::chrono::month{1}, std::chrono::day{31}}); |
| 233 | |
| 234 | check_exception("Formatting a week of year needs a valid date" , |
| 235 | SV("{:%U}" ), |
| 236 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::month{1}, std::chrono::day{0}}); |
| 237 | check_exception("Formatting a week of year needs a valid date" , |
| 238 | SV("{:%U}" ), |
| 239 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::month{1}, std::chrono::day{32}}); |
| 240 | check_exception("Formatting a week of year needs a valid date" , |
| 241 | SV("{:%U}" ), |
| 242 | std::chrono::year_month_day{ |
| 243 | std::chrono::year{1970}, std::chrono::month{2}, std::chrono::day{29}}); // not a leap year |
| 244 | check_exception("Formatting a week of year needs a valid date" , |
| 245 | SV("{:%U}" ), |
| 246 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::month{0}, std::chrono::day{31}}); |
| 247 | check_exception("Formatting a week of year needs a valid date" , |
| 248 | SV("{:%U}" ), |
| 249 | std::chrono::year_month_day{std::chrono::year{-32768}, std::chrono::month{1}, std::chrono::day{31}}); |
| 250 | |
| 251 | check_exception("Formatting a week of year needs a valid date" , |
| 252 | SV("{:%V}" ), |
| 253 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::month{1}, std::chrono::day{0}}); |
| 254 | check_exception("Formatting a week of year needs a valid date" , |
| 255 | SV("{:%V}" ), |
| 256 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::month{1}, std::chrono::day{32}}); |
| 257 | check_exception("Formatting a week of year needs a valid date" , |
| 258 | SV("{:%V}" ), |
| 259 | std::chrono::year_month_day{ |
| 260 | std::chrono::year{1970}, std::chrono::month{2}, std::chrono::day{29}}); // not a leap year |
| 261 | check_exception("Formatting a week of year needs a valid date" , |
| 262 | SV("{:%V}" ), |
| 263 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::month{0}, std::chrono::day{31}}); |
| 264 | check_exception("Formatting a week of year needs a valid date" , |
| 265 | SV("{:%V}" ), |
| 266 | std::chrono::year_month_day{std::chrono::year{-32768}, std::chrono::month{1}, std::chrono::day{31}}); |
| 267 | |
| 268 | check_exception("Formatting a weekday needs a valid weekday" , |
| 269 | SV("{:%w}" ), |
| 270 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::month{1}, std::chrono::day{0}}); |
| 271 | check_exception("Formatting a weekday needs a valid weekday" , |
| 272 | SV("{:%w}" ), |
| 273 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::month{1}, std::chrono::day{32}}); |
| 274 | check_exception("Formatting a weekday needs a valid weekday" , |
| 275 | SV("{:%w}" ), |
| 276 | std::chrono::year_month_day{ |
| 277 | std::chrono::year{1970}, std::chrono::month{2}, std::chrono::day{29}}); // not a leap year |
| 278 | check_exception("Formatting a weekday needs a valid weekday" , |
| 279 | SV("{:%w}" ), |
| 280 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::month{0}, std::chrono::day{31}}); |
| 281 | check_exception("Formatting a weekday needs a valid weekday" , |
| 282 | SV("{:%w}" ), |
| 283 | std::chrono::year_month_day{std::chrono::year{-32768}, std::chrono::month{1}, std::chrono::day{31}}); |
| 284 | |
| 285 | check_exception("Formatting a week of year needs a valid date" , |
| 286 | SV("{:%W}" ), |
| 287 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::month{1}, std::chrono::day{0}}); |
| 288 | check_exception("Formatting a week of year needs a valid date" , |
| 289 | SV("{:%W}" ), |
| 290 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::month{1}, std::chrono::day{32}}); |
| 291 | check_exception("Formatting a week of year needs a valid date" , |
| 292 | SV("{:%W}" ), |
| 293 | std::chrono::year_month_day{ |
| 294 | std::chrono::year{1970}, std::chrono::month{2}, std::chrono::day{29}}); // not a leap year |
| 295 | check_exception("Formatting a week of year needs a valid date" , |
| 296 | SV("{:%W}" ), |
| 297 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::month{0}, std::chrono::day{31}}); |
| 298 | check_exception("Formatting a week of year needs a valid date" , |
| 299 | SV("{:%W}" ), |
| 300 | std::chrono::year_month_day{std::chrono::year{-32768}, std::chrono::month{1}, std::chrono::day{31}}); |
| 301 | |
| 302 | check_exception("Formatting a weekday needs a valid weekday" , |
| 303 | SV("{:%Ou}" ), |
| 304 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::month{1}, std::chrono::day{0}}); |
| 305 | check_exception("Formatting a weekday needs a valid weekday" , |
| 306 | SV("{:%Ou}" ), |
| 307 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::month{1}, std::chrono::day{32}}); |
| 308 | check_exception("Formatting a weekday needs a valid weekday" , |
| 309 | SV("{:%Ou}" ), |
| 310 | std::chrono::year_month_day{ |
| 311 | std::chrono::year{1970}, std::chrono::month{2}, std::chrono::day{29}}); // not a leap year |
| 312 | check_exception("Formatting a weekday needs a valid weekday" , |
| 313 | SV("{:%Ou}" ), |
| 314 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::month{0}, std::chrono::day{31}}); |
| 315 | check_exception("Formatting a weekday needs a valid weekday" , |
| 316 | SV("{:%Ou}" ), |
| 317 | std::chrono::year_month_day{std::chrono::year{-32768}, std::chrono::month{1}, std::chrono::day{31}}); |
| 318 | |
| 319 | check_exception("Formatting a week of year needs a valid date" , |
| 320 | SV("{:%OU}" ), |
| 321 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::month{1}, std::chrono::day{0}}); |
| 322 | check_exception("Formatting a week of year needs a valid date" , |
| 323 | SV("{:%OU}" ), |
| 324 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::month{1}, std::chrono::day{32}}); |
| 325 | check_exception("Formatting a week of year needs a valid date" , |
| 326 | SV("{:%OU}" ), |
| 327 | std::chrono::year_month_day{ |
| 328 | std::chrono::year{1970}, std::chrono::month{2}, std::chrono::day{29}}); // not a leap year |
| 329 | check_exception("Formatting a week of year needs a valid date" , |
| 330 | SV("{:%OU}" ), |
| 331 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::month{0}, std::chrono::day{31}}); |
| 332 | check_exception("Formatting a week of year needs a valid date" , |
| 333 | SV("{:%OU}" ), |
| 334 | std::chrono::year_month_day{std::chrono::year{-32768}, std::chrono::month{1}, std::chrono::day{31}}); |
| 335 | |
| 336 | check_exception("Formatting a week of year needs a valid date" , |
| 337 | SV("{:%OV}" ), |
| 338 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::month{1}, std::chrono::day{0}}); |
| 339 | check_exception("Formatting a week of year needs a valid date" , |
| 340 | SV("{:%OV}" ), |
| 341 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::month{1}, std::chrono::day{32}}); |
| 342 | check_exception("Formatting a week of year needs a valid date" , |
| 343 | SV("{:%OV}" ), |
| 344 | std::chrono::year_month_day{ |
| 345 | std::chrono::year{1970}, std::chrono::month{2}, std::chrono::day{29}}); // not a leap year |
| 346 | check_exception("Formatting a week of year needs a valid date" , |
| 347 | SV("{:%OV}" ), |
| 348 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::month{0}, std::chrono::day{31}}); |
| 349 | check_exception("Formatting a week of year needs a valid date" , |
| 350 | SV("{:%OV}" ), |
| 351 | std::chrono::year_month_day{std::chrono::year{-32768}, std::chrono::month{1}, std::chrono::day{31}}); |
| 352 | |
| 353 | check_exception("Formatting a weekday needs a valid weekday" , |
| 354 | SV("{:%Ow}" ), |
| 355 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::month{1}, std::chrono::day{0}}); |
| 356 | check_exception("Formatting a weekday needs a valid weekday" , |
| 357 | SV("{:%Ow}" ), |
| 358 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::month{1}, std::chrono::day{32}}); |
| 359 | check_exception("Formatting a weekday needs a valid weekday" , |
| 360 | SV("{:%Ow}" ), |
| 361 | std::chrono::year_month_day{ |
| 362 | std::chrono::year{1970}, std::chrono::month{2}, std::chrono::day{29}}); // not a leap year |
| 363 | check_exception("Formatting a weekday needs a valid weekday" , |
| 364 | SV("{:%Ow}" ), |
| 365 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::month{0}, std::chrono::day{31}}); |
| 366 | check_exception("Formatting a weekday needs a valid weekday" , |
| 367 | SV("{:%Ow}" ), |
| 368 | std::chrono::year_month_day{std::chrono::year{-32768}, std::chrono::month{1}, std::chrono::day{31}}); |
| 369 | |
| 370 | check_exception("Formatting a week of year needs a valid date" , |
| 371 | SV("{:%OW}" ), |
| 372 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::month{1}, std::chrono::day{0}}); |
| 373 | check_exception("Formatting a week of year needs a valid date" , |
| 374 | SV("{:%OW}" ), |
| 375 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::month{1}, std::chrono::day{32}}); |
| 376 | check_exception("Formatting a week of year needs a valid date" , |
| 377 | SV("{:%OW}" ), |
| 378 | std::chrono::year_month_day{ |
| 379 | std::chrono::year{1970}, std::chrono::month{2}, std::chrono::day{29}}); // not a leap year |
| 380 | check_exception("Formatting a week of year needs a valid date" , |
| 381 | SV("{:%OW}" ), |
| 382 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::month{0}, std::chrono::day{31}}); |
| 383 | check_exception("Formatting a week of year needs a valid date" , |
| 384 | SV("{:%OW}" ), |
| 385 | std::chrono::year_month_day{std::chrono::year{-32768}, std::chrono::month{1}, std::chrono::day{31}}); |
| 386 | } |
| 387 | |
| 388 | template <class CharT> |
| 389 | static void test_valid_md_values() { |
| 390 | constexpr std::basic_string_view<CharT> fmt = |
| 391 | SV("{:%%b='%b'%t%%B='%B'%t%%h='%h'%t%%m='%m'%t%%Om='%Om'%t%%d='%d'%t%%e='%e'%t%%Od='%Od'%t%%Oe='%Oe'%n}" ); |
| 392 | constexpr std::basic_string_view<CharT> lfmt = |
| 393 | SV("{:L%%b='%b'%t%%B='%B'%t%%h='%h'%t%%m='%m'%t%%Om='%Om'%t%%d='%d'%t%%e='%e'%t%%Od='%Od'%t%%Oe='%Oe'%n}" ); |
| 394 | |
| 395 | const std::locale loc(LOCALE_ja_JP_UTF_8); |
| 396 | std::locale::global(std::locale(LOCALE_fr_FR_UTF_8)); |
| 397 | |
| 398 | // Non localized output using C-locale |
| 399 | #ifdef _WIN32 |
| 400 | check(SV("%b='Jan'\t%B='January'\t%h='Jan'\t%m='01'\t%Om='01'\t%d=''\t%e=''\t%Od=''\t%Oe=''\n" ), |
| 401 | fmt, |
| 402 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::January, std::chrono::day{0}}); |
| 403 | #else |
| 404 | check(SV("%b='Jan'\t%B='January'\t%h='Jan'\t%m='01'\t%Om='01'\t%d='00'\t%e=' 0'\t%Od='00'\t%Oe=' 0'\n" ), |
| 405 | fmt, |
| 406 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::January, std::chrono::day{0}}); |
| 407 | #endif |
| 408 | check(SV("%b='Feb'\t%B='February'\t%h='Feb'\t%m='02'\t%Om='02'\t%d='01'\t%e=' 1'\t%Od='01'\t%Oe=' 1'\n" ), |
| 409 | fmt, |
| 410 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::February, std::chrono::day{1}}); |
| 411 | check(SV("%b='Mar'\t%B='March'\t%h='Mar'\t%m='03'\t%Om='03'\t%d='09'\t%e=' 9'\t%Od='09'\t%Oe=' 9'\n" ), |
| 412 | fmt, |
| 413 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::March, std::chrono::day{9}}); |
| 414 | check(SV("%b='Apr'\t%B='April'\t%h='Apr'\t%m='04'\t%Om='04'\t%d='10'\t%e='10'\t%Od='10'\t%Oe='10'\n" ), |
| 415 | fmt, |
| 416 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::April, std::chrono::day{10}}); |
| 417 | check(SV("%b='May'\t%B='May'\t%h='May'\t%m='05'\t%Om='05'\t%d='28'\t%e='28'\t%Od='28'\t%Oe='28'\n" ), |
| 418 | fmt, |
| 419 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::May, std::chrono::day{28}}); |
| 420 | check(SV("%b='Jun'\t%B='June'\t%h='Jun'\t%m='06'\t%Om='06'\t%d='29'\t%e='29'\t%Od='29'\t%Oe='29'\n" ), |
| 421 | fmt, |
| 422 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::June, std::chrono::day{29}}); |
| 423 | check(SV("%b='Jul'\t%B='July'\t%h='Jul'\t%m='07'\t%Om='07'\t%d='30'\t%e='30'\t%Od='30'\t%Oe='30'\n" ), |
| 424 | fmt, |
| 425 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::July, std::chrono::day{30}}); |
| 426 | check(SV("%b='Aug'\t%B='August'\t%h='Aug'\t%m='08'\t%Om='08'\t%d='31'\t%e='31'\t%Od='31'\t%Oe='31'\n" ), |
| 427 | fmt, |
| 428 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::August, std::chrono::day{31}}); |
| 429 | #ifdef _WIN32 |
| 430 | check(SV("%b='Sep'\t%B='September'\t%h='Sep'\t%m='09'\t%Om='09'\t%d=''\t%e=''\t%Od=''\t%Oe=''\n" ), |
| 431 | fmt, |
| 432 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::September, std::chrono::day{32}}); |
| 433 | check(SV("%b='Oct'\t%B='October'\t%h='Oct'\t%m='10'\t%Om='10'\t%d=''\t%e=''\t%Od=''\t%Oe=''\n" ), |
| 434 | fmt, |
| 435 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::October, std::chrono::day{99}}); |
| 436 | check(SV("%b='Nov'\t%B='November'\t%h='Nov'\t%m='11'\t%Om='11'\t%d=''\t%e=''\t%Od=''\t%Oe=''\n" ), |
| 437 | fmt, |
| 438 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::November, std::chrono::day{100}}); |
| 439 | check(SV("%b='Dec'\t%B='December'\t%h='Dec'\t%m='12'\t%Om='12'\t%d=''\t%e=''\t%Od=''\t%Oe=''\n" ), |
| 440 | fmt, |
| 441 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::December, std::chrono::day{255}}); |
| 442 | #else // _WIN32 |
| 443 | check(SV("%b='Sep'\t%B='September'\t%h='Sep'\t%m='09'\t%Om='09'\t%d='32'\t%e='32'\t%Od='32'\t%Oe='32'\n" ), |
| 444 | fmt, |
| 445 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::September, std::chrono::day{32}}); |
| 446 | check(SV("%b='Oct'\t%B='October'\t%h='Oct'\t%m='10'\t%Om='10'\t%d='99'\t%e='99'\t%Od='99'\t%Oe='99'\n" ), |
| 447 | fmt, |
| 448 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::October, std::chrono::day{99}}); |
| 449 | # if defined(_AIX) |
| 450 | check(SV("%b='Nov'\t%B='November'\t%h='Nov'\t%m='11'\t%Om='11'\t%d='00'\t%e=' 0'\t%Od='00'\t%Oe=' 0'\n" ), |
| 451 | fmt, |
| 452 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::November, std::chrono::day{100}}); |
| 453 | check(SV("%b='Dec'\t%B='December'\t%h='Dec'\t%m='12'\t%Om='12'\t%d='55'\t%e='55'\t%Od='55'\t%Oe='55'\n" ), |
| 454 | fmt, |
| 455 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::December, std::chrono::day{255}}); |
| 456 | # else // defined(_AIX) |
| 457 | check(SV("%b='Nov'\t%B='November'\t%h='Nov'\t%m='11'\t%Om='11'\t%d='100'\t%e='100'\t%Od='100'\t%Oe='100'\n" ), |
| 458 | fmt, |
| 459 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::November, std::chrono::day{100}}); |
| 460 | check(SV("%b='Dec'\t%B='December'\t%h='Dec'\t%m='12'\t%Om='12'\t%d='255'\t%e='255'\t%Od='255'\t%Oe='255'\n" ), |
| 461 | fmt, |
| 462 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::December, std::chrono::day{255}}); |
| 463 | # endif // defined(_AIX) |
| 464 | #endif // _WIN32 |
| 465 | |
| 466 | // Use the global locale (fr_FR) |
| 467 | #if defined(__APPLE__) |
| 468 | check(SV("%b='jan'\t%B='janvier'\t%h='jan'\t%m='01'\t%Om='01'\t%d='00'\t%e=' 0'\t%Od='00'\t%Oe=' 0'\n" ), |
| 469 | lfmt, |
| 470 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::January, std::chrono::day{0}}); |
| 471 | check(SV("%b='fév'\t%B='février'\t%h='fév'\t%m='02'\t%Om='02'\t%d='01'\t%e=' 1'\t%Od='01'\t%Oe=' 1'\n" ), |
| 472 | lfmt, |
| 473 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::February, std::chrono::day{1}}); |
| 474 | check(SV("%b='mar'\t%B='mars'\t%h='mar'\t%m='03'\t%Om='03'\t%d='09'\t%e=' 9'\t%Od='09'\t%Oe=' 9'\n" ), |
| 475 | lfmt, |
| 476 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::March, std::chrono::day{9}}); |
| 477 | check(SV("%b='avr'\t%B='avril'\t%h='avr'\t%m='04'\t%Om='04'\t%d='10'\t%e='10'\t%Od='10'\t%Oe='10'\n" ), |
| 478 | lfmt, |
| 479 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::April, std::chrono::day{10}}); |
| 480 | check(SV("%b='mai'\t%B='mai'\t%h='mai'\t%m='05'\t%Om='05'\t%d='28'\t%e='28'\t%Od='28'\t%Oe='28'\n" ), |
| 481 | lfmt, |
| 482 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::May, std::chrono::day{28}}); |
| 483 | check(SV("%b='jui'\t%B='juin'\t%h='jui'\t%m='06'\t%Om='06'\t%d='29'\t%e='29'\t%Od='29'\t%Oe='29'\n" ), |
| 484 | lfmt, |
| 485 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::June, std::chrono::day{29}}); |
| 486 | check(SV("%b='jul'\t%B='juillet'\t%h='jul'\t%m='07'\t%Om='07'\t%d='30'\t%e='30'\t%Od='30'\t%Oe='30'\n" ), |
| 487 | lfmt, |
| 488 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::July, std::chrono::day{30}}); |
| 489 | check(SV("%b='aoû'\t%B='août'\t%h='aoû'\t%m='08'\t%Om='08'\t%d='31'\t%e='31'\t%Od='31'\t%Oe='31'\n" ), |
| 490 | lfmt, |
| 491 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::August, std::chrono::day{31}}); |
| 492 | check(SV("%b='sep'\t%B='septembre'\t%h='sep'\t%m='09'\t%Om='09'\t%d='32'\t%e='32'\t%Od='32'\t%Oe='32'\n" ), |
| 493 | lfmt, |
| 494 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::September, std::chrono::day{32}}); |
| 495 | check(SV("%b='oct'\t%B='octobre'\t%h='oct'\t%m='10'\t%Om='10'\t%d='99'\t%e='99'\t%Od='99'\t%Oe='99'\n" ), |
| 496 | lfmt, |
| 497 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::October, std::chrono::day{99}}); |
| 498 | check(SV("%b='nov'\t%B='novembre'\t%h='nov'\t%m='11'\t%Om='11'\t%d='100'\t%e='100'\t%Od='100'\t%Oe='100'\n" ), |
| 499 | lfmt, |
| 500 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::November, std::chrono::day{100}}); |
| 501 | check(SV("%b='déc'\t%B='décembre'\t%h='déc'\t%m='12'\t%Om='12'\t%d='255'\t%e='255'\t%Od='255'\t%Oe='255'\n" ), |
| 502 | lfmt, |
| 503 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::December, std::chrono::day{255}}); |
| 504 | #else // defined(__APPLE__) |
| 505 | # ifdef _WIN32 |
| 506 | check(SV("%b='janv.'\t%B='janvier'\t%h='janv.'\t%m='01'\t%Om='01'\t%d=''\t%e=''\t%Od=''\t%Oe=''\n" ), |
| 507 | lfmt, |
| 508 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::January, std::chrono::day{0}}); |
| 509 | # else |
| 510 | check(SV("%b='janv.'\t%B='janvier'\t%h='janv.'\t%m='01'\t%Om='01'\t%d='00'\t%e=' 0'\t%Od='00'\t%Oe=' 0'\n" ), |
| 511 | lfmt, |
| 512 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::January, std::chrono::day{0}}); |
| 513 | # endif |
| 514 | check(SV("%b='févr.'\t%B='février'\t%h='févr.'\t%m='02'\t%Om='02'\t%d='01'\t%e=' 1'\t%Od='01'\t%Oe=' 1'\n" ), |
| 515 | lfmt, |
| 516 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::February, std::chrono::day{1}}); |
| 517 | check(SV("%b='mars'\t%B='mars'\t%h='mars'\t%m='03'\t%Om='03'\t%d='09'\t%e=' 9'\t%Od='09'\t%Oe=' 9'\n" ), |
| 518 | lfmt, |
| 519 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::March, std::chrono::day{9}}); |
| 520 | check( |
| 521 | # if defined(_WIN32) || defined(_AIX) || defined(__FreeBSD__) |
| 522 | SV("%b='avr.'\t%B='avril'\t%h='avr.'\t%m='04'\t%Om='04'\t%d='10'\t%e='10'\t%Od='10'\t%Oe='10'\n" ), |
| 523 | # else // defined(_WIN32) || defined(_AIX) || defined(__FreeBSD__) |
| 524 | SV("%b='avril'\t%B='avril'\t%h='avril'\t%m='04'\t%Om='04'\t%d='10'\t%e='10'\t%Od='10'\t%Oe='10'\n" ), |
| 525 | # endif // defined(_WIN32) || defined(_AIX) || defined(__FreeBSD__) |
| 526 | lfmt, |
| 527 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::April, std::chrono::day{10}}); |
| 528 | check(SV("%b='mai'\t%B='mai'\t%h='mai'\t%m='05'\t%Om='05'\t%d='28'\t%e='28'\t%Od='28'\t%Oe='28'\n" ), |
| 529 | lfmt, |
| 530 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::May, std::chrono::day{28}}); |
| 531 | check(SV("%b='juin'\t%B='juin'\t%h='juin'\t%m='06'\t%Om='06'\t%d='29'\t%e='29'\t%Od='29'\t%Oe='29'\n" ), |
| 532 | lfmt, |
| 533 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::June, std::chrono::day{29}}); |
| 534 | check(SV("%b='juil.'\t%B='juillet'\t%h='juil.'\t%m='07'\t%Om='07'\t%d='30'\t%e='30'\t%Od='30'\t%Oe='30'\n" ), |
| 535 | lfmt, |
| 536 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::July, std::chrono::day{30}}); |
| 537 | check(SV("%b='août'\t%B='août'\t%h='août'\t%m='08'\t%Om='08'\t%d='31'\t%e='31'\t%Od='31'\t%Oe='31'\n" ), |
| 538 | lfmt, |
| 539 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::August, std::chrono::day{31}}); |
| 540 | # ifdef _WIN32 |
| 541 | check(SV("%b='sept.'\t%B='septembre'\t%h='sept.'\t%m='09'\t%Om='09'\t%d=''\t%e=''\t%Od=''\t%Oe=''\n" ), |
| 542 | lfmt, |
| 543 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::September, std::chrono::day{32}}); |
| 544 | check(SV("%b='oct.'\t%B='octobre'\t%h='oct.'\t%m='10'\t%Om='10'\t%d=''\t%e=''\t%Od=''\t%Oe=''\n" ), |
| 545 | lfmt, |
| 546 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::October, std::chrono::day{99}}); |
| 547 | check(SV("%b='nov.'\t%B='novembre'\t%h='nov.'\t%m='11'\t%Om='11'\t%d=''\t%e=''\t%Od=''\t%Oe=''\n" ), |
| 548 | lfmt, |
| 549 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::November, std::chrono::day{100}}); |
| 550 | check(SV("%b='déc.'\t%B='décembre'\t%h='déc.'\t%m='12'\t%Om='12'\t%d=''\t%e=''\t%Od=''\t%Oe=''\n" ), |
| 551 | lfmt, |
| 552 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::December, std::chrono::day{255}}); |
| 553 | # else // _WIN32 |
| 554 | check(SV("%b='sept.'\t%B='septembre'\t%h='sept.'\t%m='09'\t%Om='09'\t%d='32'\t%e='32'\t%Od='32'\t%Oe='32'\n" ), |
| 555 | lfmt, |
| 556 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::September, std::chrono::day{32}}); |
| 557 | check(SV("%b='oct.'\t%B='octobre'\t%h='oct.'\t%m='10'\t%Om='10'\t%d='99'\t%e='99'\t%Od='99'\t%Oe='99'\n" ), |
| 558 | lfmt, |
| 559 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::October, std::chrono::day{99}}); |
| 560 | # if defined(_AIX) |
| 561 | check(SV("%b='nov.'\t%B='novembre'\t%h='nov.'\t%m='11'\t%Om='11'\t%d='00'\t%e=' 0'\t%Od='00'\t%Oe=' 0'\n" ), |
| 562 | lfmt, |
| 563 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::November, std::chrono::day{100}}); |
| 564 | check(SV("%b='déc.'\t%B='décembre'\t%h='déc.'\t%m='12'\t%Om='12'\t%d='55'\t%e='55'\t%Od='55'\t%Oe='55'\n" ), |
| 565 | lfmt, |
| 566 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::December, std::chrono::day{255}}); |
| 567 | # else // defined(_AIX) |
| 568 | check(SV("%b='nov.'\t%B='novembre'\t%h='nov.'\t%m='11'\t%Om='11'\t%d='100'\t%e='100'\t%Od='100'\t%Oe='100'\n" ), |
| 569 | lfmt, |
| 570 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::November, std::chrono::day{100}}); |
| 571 | check(SV("%b='déc.'\t%B='décembre'\t%h='déc.'\t%m='12'\t%Om='12'\t%d='255'\t%e='255'\t%Od='255'\t%Oe='255'\n" ), |
| 572 | lfmt, |
| 573 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::December, std::chrono::day{255}}); |
| 574 | # endif // defined(_AIX) |
| 575 | # endif // _WIN32 |
| 576 | #endif // defined(__APPLE__) |
| 577 | |
| 578 | // Use supplied locale (ja_JP) |
| 579 | #if defined(_WIN32) |
| 580 | check(loc, |
| 581 | SV("%b='1'\t%B='1月'\t%h='1'\t%m='01'\t%Om='01'\t%d=''\t%e=''\t%Od=''\t%Oe=''\n" ), |
| 582 | lfmt, |
| 583 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::January, std::chrono::day{0}}); |
| 584 | check(loc, |
| 585 | SV("%b='2'\t%B='2月'\t%h='2'\t%m='02'\t%Om='02'\t%d='01'\t%e=' 1'\t%Od='01'\t%Oe=' 1'\n" ), |
| 586 | lfmt, |
| 587 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::February, std::chrono::day{1}}); |
| 588 | check(loc, |
| 589 | SV("%b='3'\t%B='3月'\t%h='3'\t%m='03'\t%Om='03'\t%d='09'\t%e=' 9'\t%Od='09'\t%Oe=' 9'\n" ), |
| 590 | lfmt, |
| 591 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::March, std::chrono::day{9}}); |
| 592 | check(loc, |
| 593 | SV("%b='4'\t%B='4月'\t%h='4'\t%m='04'\t%Om='04'\t%d='10'\t%e='10'\t%Od='10'\t%Oe='10'\n" ), |
| 594 | lfmt, |
| 595 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::April, std::chrono::day{10}}); |
| 596 | check(loc, |
| 597 | SV("%b='5'\t%B='5月'\t%h='5'\t%m='05'\t%Om='05'\t%d='28'\t%e='28'\t%Od='28'\t%Oe='28'\n" ), |
| 598 | lfmt, |
| 599 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::May, std::chrono::day{28}}); |
| 600 | check(loc, |
| 601 | SV("%b='6'\t%B='6月'\t%h='6'\t%m='06'\t%Om='06'\t%d='29'\t%e='29'\t%Od='29'\t%Oe='29'\n" ), |
| 602 | lfmt, |
| 603 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::June, std::chrono::day{29}}); |
| 604 | check(loc, |
| 605 | SV("%b='7'\t%B='7月'\t%h='7'\t%m='07'\t%Om='07'\t%d='30'\t%e='30'\t%Od='30'\t%Oe='30'\n" ), |
| 606 | lfmt, |
| 607 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::July, std::chrono::day{30}}); |
| 608 | check(loc, |
| 609 | SV("%b='8'\t%B='8月'\t%h='8'\t%m='08'\t%Om='08'\t%d='31'\t%e='31'\t%Od='31'\t%Oe='31'\n" ), |
| 610 | lfmt, |
| 611 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::August, std::chrono::day{31}}); |
| 612 | check(loc, |
| 613 | SV("%b='9'\t%B='9月'\t%h='9'\t%m='09'\t%Om='09'\t%d=''\t%e=''\t%Od=''\t%Oe=''\n" ), |
| 614 | lfmt, |
| 615 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::September, std::chrono::day{32}}); |
| 616 | check(loc, |
| 617 | SV("%b='10'\t%B='10月'\t%h='10'\t%m='10'\t%Om='10'\t%d=''\t%e=''\t%Od=''\t%Oe=''\n" ), |
| 618 | lfmt, |
| 619 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::October, std::chrono::day{99}}); |
| 620 | check(loc, |
| 621 | SV("%b='11'\t%B='11月'\t%h='11'\t%m='11'\t%Om='11'\t%d=''\t%e=''\t%Od=''\t%Oe=''\n" ), |
| 622 | lfmt, |
| 623 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::November, std::chrono::day{100}}); |
| 624 | check(loc, |
| 625 | SV("%b='12'\t%B='12月'\t%h='12'\t%m='12'\t%Om='12'\t%d=''\t%e=''\t%Od=''\t%Oe=''\n" ), |
| 626 | lfmt, |
| 627 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::December, std::chrono::day{255}}); |
| 628 | #elif defined(_AIX) // defined(_WIN32) |
| 629 | check(loc, |
| 630 | SV("%b='1月'\t%B='1月'\t%h='1月'\t%m='01'\t%Om='01'\t%d='00'\t%e=' 0'\t%Od='00'\t%Oe=' 0'\n" ), |
| 631 | lfmt, |
| 632 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::January, std::chrono::day{0}}); |
| 633 | check(loc, |
| 634 | SV("%b='2月'\t%B='2月'\t%h='2月'\t%m='02'\t%Om='02'\t%d='01'\t%e=' 1'\t%Od='01'\t%Oe=' 1'\n" ), |
| 635 | lfmt, |
| 636 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::February, std::chrono::day{1}}); |
| 637 | check(loc, |
| 638 | SV("%b='3月'\t%B='3月'\t%h='3月'\t%m='03'\t%Om='03'\t%d='09'\t%e=' 9'\t%Od='09'\t%Oe=' 9'\n" ), |
| 639 | lfmt, |
| 640 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::March, std::chrono::day{9}}); |
| 641 | check(loc, |
| 642 | SV("%b='4月'\t%B='4月'\t%h='4月'\t%m='04'\t%Om='04'\t%d='10'\t%e='10'\t%Od='10'\t%Oe='10'\n" ), |
| 643 | lfmt, |
| 644 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::April, std::chrono::day{10}}); |
| 645 | check(loc, |
| 646 | SV("%b='5月'\t%B='5月'\t%h='5月'\t%m='05'\t%Om='05'\t%d='28'\t%e='28'\t%Od='28'\t%Oe='28'\n" ), |
| 647 | lfmt, |
| 648 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::May, std::chrono::day{28}}); |
| 649 | check(loc, |
| 650 | SV("%b='6月'\t%B='6月'\t%h='6月'\t%m='06'\t%Om='06'\t%d='29'\t%e='29'\t%Od='29'\t%Oe='29'\n" ), |
| 651 | lfmt, |
| 652 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::June, std::chrono::day{29}}); |
| 653 | check(loc, |
| 654 | SV("%b='7月'\t%B='7月'\t%h='7月'\t%m='07'\t%Om='07'\t%d='30'\t%e='30'\t%Od='30'\t%Oe='30'\n" ), |
| 655 | lfmt, |
| 656 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::July, std::chrono::day{30}}); |
| 657 | check(loc, |
| 658 | SV("%b='8月'\t%B='8月'\t%h='8月'\t%m='08'\t%Om='08'\t%d='31'\t%e='31'\t%Od='31'\t%Oe='31'\n" ), |
| 659 | lfmt, |
| 660 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::August, std::chrono::day{31}}); |
| 661 | check(loc, |
| 662 | SV("%b='9月'\t%B='9月'\t%h='9月'\t%m='09'\t%Om='09'\t%d='32'\t%e='32'\t%Od='32'\t%Oe='32'\n" ), |
| 663 | lfmt, |
| 664 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::September, std::chrono::day{32}}); |
| 665 | check(loc, |
| 666 | SV("%b='10月'\t%B='10月'\t%h='10月'\t%m='10'\t%Om='10'\t%d='99'\t%e='99'\t%Od='99'\t%Oe='99'\n" ), |
| 667 | lfmt, |
| 668 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::October, std::chrono::day{99}}); |
| 669 | check(loc, |
| 670 | SV("%b='11月'\t%B='11月'\t%h='11月'\t%m='11'\t%Om='11'\t%d='00'\t%e=' 0'\t%Od='00'\t%Oe=' 0'\n" ), |
| 671 | lfmt, |
| 672 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::November, std::chrono::day{100}}); |
| 673 | check(loc, |
| 674 | SV("%b='12月'\t%B='12月'\t%h='12月'\t%m='12'\t%Om='12'\t%d='55'\t%e='55'\t%Od='55'\t%Oe='55'\n" ), |
| 675 | lfmt, |
| 676 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::December, std::chrono::day{255}}); |
| 677 | #elif defined(__FreeBSD__) // defined(_WIN32) |
| 678 | check(loc, |
| 679 | SV("%b=' 1月'\t%B='1月'\t%h=' 1月'\t%m='01'\t%Om='01'\t%d='00'\t%e=' 0'\t%Od='00'\t%Oe=' 0'\n" ), |
| 680 | lfmt, |
| 681 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::January, std::chrono::day{0}}); |
| 682 | check(loc, |
| 683 | SV("%b=' 2月'\t%B='2月'\t%h=' 2月'\t%m='02'\t%Om='02'\t%d='01'\t%e=' 1'\t%Od='01'\t%Oe=' 1'\n" ), |
| 684 | lfmt, |
| 685 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::February, std::chrono::day{1}}); |
| 686 | check(loc, |
| 687 | SV("%b=' 3月'\t%B='3月'\t%h=' 3月'\t%m='03'\t%Om='03'\t%d='09'\t%e=' 9'\t%Od='09'\t%Oe=' 9'\n" ), |
| 688 | lfmt, |
| 689 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::March, std::chrono::day{9}}); |
| 690 | check(loc, |
| 691 | SV("%b=' 4月'\t%B='4月'\t%h=' 4月'\t%m='04'\t%Om='04'\t%d='10'\t%e='10'\t%Od='10'\t%Oe='10'\n" ), |
| 692 | lfmt, |
| 693 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::April, std::chrono::day{10}}); |
| 694 | check(loc, |
| 695 | SV("%b=' 5月'\t%B='5月'\t%h=' 5月'\t%m='05'\t%Om='05'\t%d='28'\t%e='28'\t%Od='28'\t%Oe='28'\n" ), |
| 696 | lfmt, |
| 697 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::May, std::chrono::day{28}}); |
| 698 | check(loc, |
| 699 | SV("%b=' 6月'\t%B='6月'\t%h=' 6月'\t%m='06'\t%Om='06'\t%d='29'\t%e='29'\t%Od='29'\t%Oe='29'\n" ), |
| 700 | lfmt, |
| 701 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::June, std::chrono::day{29}}); |
| 702 | check(loc, |
| 703 | SV("%b=' 7月'\t%B='7月'\t%h=' 7月'\t%m='07'\t%Om='07'\t%d='30'\t%e='30'\t%Od='30'\t%Oe='30'\n" ), |
| 704 | lfmt, |
| 705 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::July, std::chrono::day{30}}); |
| 706 | check(loc, |
| 707 | SV("%b=' 8月'\t%B='8月'\t%h=' 8月'\t%m='08'\t%Om='08'\t%d='31'\t%e='31'\t%Od='31'\t%Oe='31'\n" ), |
| 708 | lfmt, |
| 709 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::August, std::chrono::day{31}}); |
| 710 | check(loc, |
| 711 | SV("%b=' 9月'\t%B='9月'\t%h=' 9月'\t%m='09'\t%Om='09'\t%d='32'\t%e='32'\t%Od='32'\t%Oe='32'\n" ), |
| 712 | lfmt, |
| 713 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::September, std::chrono::day{32}}); |
| 714 | check(loc, |
| 715 | SV("%b='10月'\t%B='10月'\t%h='10月'\t%m='10'\t%Om='10'\t%d='99'\t%e='99'\t%Od='99'\t%Oe='99'\n" ), |
| 716 | lfmt, |
| 717 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::October, std::chrono::day{99}}); |
| 718 | check(loc, |
| 719 | SV("%b='11月'\t%B='11月'\t%h='11月'\t%m='11'\t%Om='11'\t%d='100'\t%e='100'\t%Od='100'\t%Oe='100'\n" ), |
| 720 | lfmt, |
| 721 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::November, std::chrono::day{100}}); |
| 722 | check(loc, |
| 723 | SV("%b='12月'\t%B='12月'\t%h='12月'\t%m='12'\t%Om='12'\t%d='255'\t%e='255'\t%Od='255'\t%Oe='255'\n" ), |
| 724 | lfmt, |
| 725 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::December, std::chrono::day{255}}); |
| 726 | #elif defined(__APPLE__) // defined(_WIN32) |
| 727 | check(loc, |
| 728 | SV("%b=' 1'\t%B='1月'\t%h=' 1'\t%m='01'\t%Om='01'\t%d='00'\t%e=' 0'\t%Od='00'\t%Oe=' 0'\n" ), |
| 729 | lfmt, |
| 730 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::January, std::chrono::day{0}}); |
| 731 | check(loc, |
| 732 | SV("%b=' 2'\t%B='2月'\t%h=' 2'\t%m='02'\t%Om='02'\t%d='01'\t%e=' 1'\t%Od='01'\t%Oe=' 1'\n" ), |
| 733 | lfmt, |
| 734 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::February, std::chrono::day{1}}); |
| 735 | check(loc, |
| 736 | SV("%b=' 3'\t%B='3月'\t%h=' 3'\t%m='03'\t%Om='03'\t%d='09'\t%e=' 9'\t%Od='09'\t%Oe=' 9'\n" ), |
| 737 | lfmt, |
| 738 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::March, std::chrono::day{9}}); |
| 739 | check(loc, |
| 740 | SV("%b=' 4'\t%B='4月'\t%h=' 4'\t%m='04'\t%Om='04'\t%d='10'\t%e='10'\t%Od='10'\t%Oe='10'\n" ), |
| 741 | lfmt, |
| 742 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::April, std::chrono::day{10}}); |
| 743 | check(loc, |
| 744 | SV("%b=' 5'\t%B='5月'\t%h=' 5'\t%m='05'\t%Om='05'\t%d='28'\t%e='28'\t%Od='28'\t%Oe='28'\n" ), |
| 745 | lfmt, |
| 746 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::May, std::chrono::day{28}}); |
| 747 | check(loc, |
| 748 | SV("%b=' 6'\t%B='6月'\t%h=' 6'\t%m='06'\t%Om='06'\t%d='29'\t%e='29'\t%Od='29'\t%Oe='29'\n" ), |
| 749 | lfmt, |
| 750 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::June, std::chrono::day{29}}); |
| 751 | check(loc, |
| 752 | SV("%b=' 7'\t%B='7月'\t%h=' 7'\t%m='07'\t%Om='07'\t%d='30'\t%e='30'\t%Od='30'\t%Oe='30'\n" ), |
| 753 | lfmt, |
| 754 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::July, std::chrono::day{30}}); |
| 755 | check(loc, |
| 756 | SV("%b=' 8'\t%B='8月'\t%h=' 8'\t%m='08'\t%Om='08'\t%d='31'\t%e='31'\t%Od='31'\t%Oe='31'\n" ), |
| 757 | lfmt, |
| 758 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::August, std::chrono::day{31}}); |
| 759 | check(loc, |
| 760 | SV("%b=' 9'\t%B='9月'\t%h=' 9'\t%m='09'\t%Om='09'\t%d='32'\t%e='32'\t%Od='32'\t%Oe='32'\n" ), |
| 761 | lfmt, |
| 762 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::September, std::chrono::day{32}}); |
| 763 | check(loc, |
| 764 | SV("%b='10'\t%B='10月'\t%h='10'\t%m='10'\t%Om='10'\t%d='99'\t%e='99'\t%Od='99'\t%Oe='99'\n" ), |
| 765 | lfmt, |
| 766 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::October, std::chrono::day{99}}); |
| 767 | check(loc, |
| 768 | SV("%b='11'\t%B='11月'\t%h='11'\t%m='11'\t%Om='11'\t%d='100'\t%e='100'\t%Od='100'\t%Oe='100'\n" ), |
| 769 | lfmt, |
| 770 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::November, std::chrono::day{100}}); |
| 771 | check(loc, |
| 772 | SV("%b='12'\t%B='12月'\t%h='12'\t%m='12'\t%Om='12'\t%d='255'\t%e='255'\t%Od='255'\t%Oe='255'\n" ), |
| 773 | lfmt, |
| 774 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::December, std::chrono::day{255}}); |
| 775 | #else // defined(_WIN32) |
| 776 | check(loc, |
| 777 | SV("%b=' 1月'\t%B='1月'\t%h=' 1月'\t%m='01'\t%Om='一'\t%d='00'\t%e=' 0'\t%Od='〇'\t%Oe='〇'\n" ), |
| 778 | lfmt, |
| 779 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::January, std::chrono::day{0}}); |
| 780 | check(loc, |
| 781 | SV("%b=' 2月'\t%B='2月'\t%h=' 2月'\t%m='02'\t%Om='二'\t%d='01'\t%e=' 1'\t%Od='一'\t%Oe='一'\n" ), |
| 782 | lfmt, |
| 783 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::February, std::chrono::day{1}}); |
| 784 | check(loc, |
| 785 | SV("%b=' 3月'\t%B='3月'\t%h=' 3月'\t%m='03'\t%Om='三'\t%d='09'\t%e=' 9'\t%Od='九'\t%Oe='九'\n" ), |
| 786 | lfmt, |
| 787 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::March, std::chrono::day{9}}); |
| 788 | check(loc, |
| 789 | SV("%b=' 4月'\t%B='4月'\t%h=' 4月'\t%m='04'\t%Om='四'\t%d='10'\t%e='10'\t%Od='十'\t%Oe='十'\n" ), |
| 790 | lfmt, |
| 791 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::April, std::chrono::day{10}}); |
| 792 | check(loc, |
| 793 | SV("%b=' 5月'\t%B='5月'\t%h=' 5月'\t%m='05'\t%Om='五'\t%d='28'\t%e='28'\t%Od='二十八'\t%Oe='二十八'\n" ), |
| 794 | lfmt, |
| 795 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::May, std::chrono::day{28}}); |
| 796 | check(loc, |
| 797 | SV("%b=' 6月'\t%B='6月'\t%h=' 6月'\t%m='06'\t%Om='六'\t%d='29'\t%e='29'\t%Od='二十九'\t%Oe='二十九'\n" ), |
| 798 | lfmt, |
| 799 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::June, std::chrono::day{29}}); |
| 800 | check(loc, |
| 801 | SV("%b=' 7月'\t%B='7月'\t%h=' 7月'\t%m='07'\t%Om='七'\t%d='30'\t%e='30'\t%Od='三十'\t%Oe='三十'\n" ), |
| 802 | lfmt, |
| 803 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::July, std::chrono::day{30}}); |
| 804 | check(loc, |
| 805 | SV("%b=' 8月'\t%B='8月'\t%h=' 8月'\t%m='08'\t%Om='八'\t%d='31'\t%e='31'\t%Od='三十一'\t%Oe='三十一'\n" ), |
| 806 | lfmt, |
| 807 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::August, std::chrono::day{31}}); |
| 808 | check(loc, |
| 809 | SV("%b=' 9月'\t%B='9月'\t%h=' 9月'\t%m='09'\t%Om='九'\t%d='32'\t%e='32'\t%Od='三十二'\t%Oe='三十二'\n" ), |
| 810 | lfmt, |
| 811 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::September, std::chrono::day{32}}); |
| 812 | check(loc, |
| 813 | SV("%b='10月'\t%B='10月'\t%h='10月'\t%m='10'\t%Om='十'\t%d='99'\t%e='99'\t%Od='九十九'\t%Oe='九十九'\n" ), |
| 814 | lfmt, |
| 815 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::October, std::chrono::day{99}}); |
| 816 | check(loc, |
| 817 | SV("%b='11月'\t%B='11月'\t%h='11月'\t%m='11'\t%Om='十一'\t%d='100'\t%e='100'\t%Od='100'\t%Oe='100'\n" ), |
| 818 | lfmt, |
| 819 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::November, std::chrono::day{100}}); |
| 820 | check(loc, |
| 821 | SV("%b='12月'\t%B='12月'\t%h='12月'\t%m='12'\t%Om='十二'\t%d='255'\t%e='255'\t%Od='255'\t%Oe='255'\n" ), |
| 822 | lfmt, |
| 823 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::December, std::chrono::day{255}}); |
| 824 | #endif // defined(_WIN32) |
| 825 | |
| 826 | std::locale::global(loc: std::locale::classic()); |
| 827 | } |
| 828 | |
| 829 | template <class CharT> |
| 830 | static void test_valid_ymd_values() { |
| 831 | constexpr std::basic_string_view<CharT> fmt = SV( |
| 832 | "{:" |
| 833 | "%%C='%C'%t" |
| 834 | "%%D='%D'%t" |
| 835 | "%%F='%F'%t" |
| 836 | "%%j='%j'%t" |
| 837 | "%%g='%g'%t" |
| 838 | "%%G='%G'%t" |
| 839 | "%%u='%u'%t" |
| 840 | "%%U='%U'%t" |
| 841 | "%%V='%V'%t" |
| 842 | "%%w='%w'%t" |
| 843 | "%%W='%W'%t" |
| 844 | "%%x='%x'%t" |
| 845 | "%%y='%y'%t" |
| 846 | "%%Y='%Y'%t" |
| 847 | "%%Ex='%Ex'%t" |
| 848 | "%%EC='%EC'%t" |
| 849 | "%%Ey='%Ey'%t" |
| 850 | "%%EY='%EY'%t" |
| 851 | "%%Ou='%Ou'%t" |
| 852 | "%%OU='%OU'%t" |
| 853 | "%%OV='%OV'%t" |
| 854 | "%%Ow='%Ow'%t" |
| 855 | "%%OW='%OW'%t" |
| 856 | "%%Oy='%Oy'%t" |
| 857 | "%n}" ); |
| 858 | |
| 859 | constexpr std::basic_string_view<CharT> lfmt = SV( |
| 860 | "{:L" |
| 861 | "%%C='%C'%t" |
| 862 | "%%D='%D'%t" |
| 863 | "%%F='%F'%t" |
| 864 | "%%j='%j'%t" |
| 865 | "%%g='%g'%t" |
| 866 | "%%G='%G'%t" |
| 867 | "%%u='%u'%t" |
| 868 | "%%U='%U'%t" |
| 869 | "%%V='%V'%t" |
| 870 | "%%w='%w'%t" |
| 871 | "%%W='%W'%t" |
| 872 | "%%x='%x'%t" |
| 873 | "%%y='%y'%t" |
| 874 | "%%Y='%Y'%t" |
| 875 | "%%Ex='%Ex'%t" |
| 876 | "%%EC='%EC'%t" |
| 877 | "%%Ey='%Ey'%t" |
| 878 | "%%EY='%EY'%t" |
| 879 | "%%Ou='%Ou'%t" |
| 880 | "%%OU='%OU'%t" |
| 881 | "%%OV='%OV'%t" |
| 882 | "%%Ow='%Ow'%t" |
| 883 | "%%OW='%OW'%t" |
| 884 | "%%Oy='%Oy'%t" |
| 885 | "%n}" ); |
| 886 | |
| 887 | const std::locale loc(LOCALE_ja_JP_UTF_8); |
| 888 | std::locale::global(std::locale(LOCALE_fr_FR_UTF_8)); |
| 889 | |
| 890 | // Non localized output using C-locale |
| 891 | check( |
| 892 | SV("%C='19'\t" |
| 893 | "%D='01/01/70'\t" |
| 894 | "%F='1970-01-01'\t" |
| 895 | "%j='001'\t" |
| 896 | "%g='70'\t" |
| 897 | "%G='1970'\t" |
| 898 | "%u='4'\t" |
| 899 | "%U='00'\t" |
| 900 | "%V='01'\t" |
| 901 | "%w='4'\t" |
| 902 | "%W='00'\t" |
| 903 | "%x='01/01/70'\t" |
| 904 | "%y='70'\t" |
| 905 | "%Y='1970'\t" |
| 906 | "%Ex='01/01/70'\t" |
| 907 | "%EC='19'\t" |
| 908 | "%Ey='70'\t" |
| 909 | "%EY='1970'\t" |
| 910 | "%Ou='4'\t" |
| 911 | "%OU='00'\t" |
| 912 | "%OV='01'\t" |
| 913 | "%Ow='4'\t" |
| 914 | "%OW='00'\t" |
| 915 | "%Oy='70'\t" |
| 916 | "\n" ), |
| 917 | fmt, |
| 918 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::January, std::chrono::day{1}}); |
| 919 | |
| 920 | check( |
| 921 | SV("%C='20'\t" |
| 922 | "%D='05/29/04'\t" |
| 923 | "%F='2004-05-29'\t" |
| 924 | "%j='150'\t" |
| 925 | "%g='04'\t" |
| 926 | "%G='2004'\t" |
| 927 | "%u='6'\t" |
| 928 | "%U='21'\t" |
| 929 | "%V='22'\t" |
| 930 | "%w='6'\t" |
| 931 | "%W='21'\t" |
| 932 | "%x='05/29/04'\t" |
| 933 | "%y='04'\t" |
| 934 | "%Y='2004'\t" |
| 935 | "%Ex='05/29/04'\t" |
| 936 | "%EC='20'\t" |
| 937 | "%Ey='04'\t" |
| 938 | "%EY='2004'\t" |
| 939 | "%Ou='6'\t" |
| 940 | "%OU='21'\t" |
| 941 | "%OV='22'\t" |
| 942 | "%Ow='6'\t" |
| 943 | "%OW='21'\t" |
| 944 | "%Oy='04'\t" |
| 945 | "\n" ), |
| 946 | fmt, |
| 947 | std::chrono::year_month_day{std::chrono::year{2004}, std::chrono::May, std::chrono::day{29}}); |
| 948 | |
| 949 | // Use the global locale (fr_FR) |
| 950 | check( |
| 951 | SV("%C='19'\t" |
| 952 | "%D='01/01/70'\t" |
| 953 | "%F='1970-01-01'\t" |
| 954 | "%j='001'\t" |
| 955 | "%g='70'\t" |
| 956 | "%G='1970'\t" |
| 957 | "%u='4'\t" |
| 958 | "%U='00'\t" |
| 959 | "%V='01'\t" |
| 960 | "%w='4'\t" |
| 961 | "%W='00'\t" |
| 962 | #if defined(__APPLE__) || defined(__FreeBSD__) |
| 963 | "%x='01.01.1970'\t" |
| 964 | #else |
| 965 | "%x='01/01/1970'\t" |
| 966 | #endif |
| 967 | "%y='70'\t" |
| 968 | "%Y='1970'\t" |
| 969 | #if defined(__APPLE__) || defined(__FreeBSD__) |
| 970 | "%Ex='01.01.1970'\t" |
| 971 | #else |
| 972 | "%Ex='01/01/1970'\t" |
| 973 | #endif |
| 974 | "%EC='19'\t" |
| 975 | "%Ey='70'\t" |
| 976 | "%EY='1970'\t" |
| 977 | "%Ou='4'\t" |
| 978 | "%OU='00'\t" |
| 979 | "%OV='01'\t" |
| 980 | "%Ow='4'\t" |
| 981 | "%OW='00'\t" |
| 982 | "%Oy='70'\t" |
| 983 | "\n" ), |
| 984 | lfmt, |
| 985 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::January, std::chrono::day{1}}); |
| 986 | |
| 987 | check( |
| 988 | SV("%C='20'\t" |
| 989 | "%D='05/29/04'\t" |
| 990 | "%F='2004-05-29'\t" |
| 991 | "%j='150'\t" |
| 992 | "%g='04'\t" |
| 993 | "%G='2004'\t" |
| 994 | "%u='6'\t" |
| 995 | "%U='21'\t" |
| 996 | "%V='22'\t" |
| 997 | "%w='6'\t" |
| 998 | "%W='21'\t" |
| 999 | #if defined(__APPLE__) || defined(__FreeBSD__) |
| 1000 | "%x='29.05.2004'\t" |
| 1001 | #else |
| 1002 | "%x='29/05/2004'\t" |
| 1003 | #endif |
| 1004 | "%y='04'\t" |
| 1005 | "%Y='2004'\t" |
| 1006 | #if defined(__APPLE__) || defined(__FreeBSD__) |
| 1007 | "%Ex='29.05.2004'\t" |
| 1008 | #else |
| 1009 | "%Ex='29/05/2004'\t" |
| 1010 | #endif |
| 1011 | "%EC='20'\t" |
| 1012 | "%Ey='04'\t" |
| 1013 | "%EY='2004'\t" |
| 1014 | "%Ou='6'\t" |
| 1015 | "%OU='21'\t" |
| 1016 | "%OV='22'\t" |
| 1017 | "%Ow='6'\t" |
| 1018 | "%OW='21'\t" |
| 1019 | "%Oy='04'\t" |
| 1020 | "\n" ), |
| 1021 | lfmt, |
| 1022 | std::chrono::year_month_day{std::chrono::year{2004}, std::chrono::May, std::chrono::day{29}}); |
| 1023 | |
| 1024 | // Use supplied locale (ja_JP) |
| 1025 | check( |
| 1026 | loc, |
| 1027 | SV("%C='19'\t" |
| 1028 | "%D='01/01/70'\t" |
| 1029 | "%F='1970-01-01'\t" |
| 1030 | "%j='001'\t" |
| 1031 | "%g='70'\t" |
| 1032 | "%G='1970'\t" |
| 1033 | "%u='4'\t" |
| 1034 | "%U='00'\t" |
| 1035 | "%V='01'\t" |
| 1036 | "%w='4'\t" |
| 1037 | "%W='00'\t" |
| 1038 | #if defined(__APPLE__) || defined(_AIX) || defined(_WIN32) || defined(__FreeBSD__) |
| 1039 | "%x='1970/01/01'\t" |
| 1040 | #else // defined(__APPLE__) || defined(_AIX) || defined(_WIN32) || defined(__FreeBSD__) |
| 1041 | "%x='1970年01月01日'\t" |
| 1042 | #endif // defined(__APPLE__) || defined(_AIX) || defined(_WIN32) || defined(__FreeBSD__) |
| 1043 | "%y='70'\t" |
| 1044 | "%Y='1970'\t" |
| 1045 | #if defined(__APPLE__) || defined(_AIX) || defined(_WIN32) || defined(__FreeBSD__) |
| 1046 | "%Ex='1970/01/01'\t" |
| 1047 | "%EC='19'\t" |
| 1048 | "%Ey='70'\t" |
| 1049 | "%EY='1970'\t" |
| 1050 | "%Ou='4'\t" |
| 1051 | "%OU='00'\t" |
| 1052 | "%OV='01'\t" |
| 1053 | "%Ow='4'\t" |
| 1054 | "%OW='00'\t" |
| 1055 | "%Oy='70'\t" |
| 1056 | #else // defined(__APPLE__) || defined(_AIX) || defined(_WIN32) || defined(__FreeBSD__) |
| 1057 | "%Ex='昭和45年01月01日'\t" |
| 1058 | "%EC='昭和'\t" |
| 1059 | "%Ey='45'\t" |
| 1060 | "%EY='昭和45年'\t" |
| 1061 | "%Ou='四'\t" |
| 1062 | "%OU='〇'\t" |
| 1063 | "%OV='一'\t" |
| 1064 | "%Ow='四'\t" |
| 1065 | "%OW='〇'\t" |
| 1066 | "%Oy='七十'\t" |
| 1067 | #endif // defined(__APPLE__) || defined(_AIX) || defined(_WIN32) || defined(__FreeBSD__) |
| 1068 | "\n" ), |
| 1069 | lfmt, |
| 1070 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::January, std::chrono::day{1}}); |
| 1071 | |
| 1072 | check( |
| 1073 | loc, |
| 1074 | SV("%C='20'\t" |
| 1075 | "%D='05/29/04'\t" |
| 1076 | "%F='2004-05-29'\t" |
| 1077 | "%j='150'\t" |
| 1078 | "%g='04'\t" |
| 1079 | "%G='2004'\t" |
| 1080 | "%u='6'\t" |
| 1081 | "%U='21'\t" |
| 1082 | "%V='22'\t" |
| 1083 | "%w='6'\t" |
| 1084 | "%W='21'\t" |
| 1085 | #if defined(__APPLE__) || defined(_AIX) || defined(_WIN32) || defined(__FreeBSD__) |
| 1086 | "%x='2004/05/29'\t" |
| 1087 | #else // defined(__APPLE__) || defined(_AIX) || defined(_WIN32) || defined(__FreeBSD__) |
| 1088 | "%x='2004年05月29日'\t" |
| 1089 | #endif // defined(__APPLE__) || defined(_AIX) || defined(_WIN32) || defined(__FreeBSD__) |
| 1090 | "%y='04'\t" |
| 1091 | "%Y='2004'\t" |
| 1092 | #if defined(__APPLE__) || defined(_AIX) || defined(_WIN32) || defined(__FreeBSD__) |
| 1093 | "%Ex='2004/05/29'\t" |
| 1094 | "%EC='20'\t" |
| 1095 | "%Ey='04'\t" |
| 1096 | "%EY='2004'\t" |
| 1097 | "%Ou='6'\t" |
| 1098 | "%OU='21'\t" |
| 1099 | "%OV='22'\t" |
| 1100 | "%Ow='6'\t" |
| 1101 | "%OW='21'\t" |
| 1102 | "%Oy='04'\t" |
| 1103 | #else // defined(__APPLE__) || defined(_AIX) || defined(_WIN32) || defined(__FreeBSD__) |
| 1104 | "%Ex='平成16年05月29日'\t" |
| 1105 | "%EC='平成'\t" |
| 1106 | "%Ey='16'\t" |
| 1107 | "%EY='平成16年'\t" |
| 1108 | "%Ou='六'\t" |
| 1109 | "%OU='二十一'\t" |
| 1110 | "%OV='二十二'\t" |
| 1111 | "%Ow='六'\t" |
| 1112 | "%OW='二十一'\t" |
| 1113 | "%Oy='四'\t" |
| 1114 | #endif // defined(__APPLE__) || defined(_AIX) || defined(_WIN32) || defined(__FreeBSD__) |
| 1115 | "\n" ), |
| 1116 | lfmt, |
| 1117 | std::chrono::year_month_day{std::chrono::year{2004}, std::chrono::May, std::chrono::day{29}}); |
| 1118 | |
| 1119 | std::locale::global(loc: std::locale::classic()); |
| 1120 | } |
| 1121 | |
| 1122 | template <class CharT> |
| 1123 | static void test_valid_values() { |
| 1124 | // Fields only using month and day. |
| 1125 | test_valid_md_values<CharT>(); |
| 1126 | // Fields only using year, month, and day. |
| 1127 | test_valid_ymd_values<CharT>(); |
| 1128 | } |
| 1129 | |
| 1130 | template <class CharT> |
| 1131 | static void test() { |
| 1132 | test_no_chrono_specs<CharT>(); |
| 1133 | test_invalid_values<CharT>(); |
| 1134 | test_valid_values<CharT>(); |
| 1135 | check_invalid_types<CharT>( |
| 1136 | {SV("a" ), SV("A" ), SV("b" ), SV("B" ), SV("C" ), SV("d" ), SV("D" ), SV("e" ), SV("EC" ), |
| 1137 | SV("Ex" ), SV("Ey" ), SV("EY" ), SV("F" ), SV("g" ), SV("G" ), SV("h" ), SV("j" ), SV("m" ), |
| 1138 | SV("Od" ), SV("Oe" ), SV("Om" ), SV("Ou" ), SV("OU" ), SV("OV" ), SV("Ow" ), SV("OW" ), SV("Oy" ), |
| 1139 | SV("u" ), SV("U" ), SV("V" ), SV("w" ), SV("W" ), SV("x" ), SV("y" ), SV("Y" )}, |
| 1140 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::January, std::chrono::day{31}}); |
| 1141 | |
| 1142 | check_exception("The format specifier expects a '%' or a '}'" , |
| 1143 | SV("{:A" ), |
| 1144 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::January, std::chrono::day{31}}); |
| 1145 | check_exception("The chrono specifiers contain a '{'" , |
| 1146 | SV("{:%%{" ), |
| 1147 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::January, std::chrono::day{31}}); |
| 1148 | check_exception("End of input while parsing a conversion specifier" , |
| 1149 | SV("{:%" ), |
| 1150 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::January, std::chrono::day{31}}); |
| 1151 | check_exception("End of input while parsing the modifier E" , |
| 1152 | SV("{:%E" ), |
| 1153 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::January, std::chrono::day{31}}); |
| 1154 | check_exception("End of input while parsing the modifier O" , |
| 1155 | SV("{:%O" ), |
| 1156 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::January, std::chrono::day{31}}); |
| 1157 | |
| 1158 | // Precision not allowed |
| 1159 | check_exception("The format specifier expects a '%' or a '}'" , |
| 1160 | SV("{:.3}" ), |
| 1161 | std::chrono::year_month_day{std::chrono::year{1970}, std::chrono::January, std::chrono::day{31}}); |
| 1162 | } |
| 1163 | |
| 1164 | int main(int, char**) { |
| 1165 | test<char>(); |
| 1166 | |
| 1167 | #ifndef TEST_HAS_NO_WIDE_CHARACTERS |
| 1168 | test<wchar_t>(); |
| 1169 | #endif |
| 1170 | |
| 1171 | return 0; |
| 1172 | } |
| 1173 | |