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