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