23 #include "gmock/gmock.h" 24 #include "gtest/gtest.h" 26 namespace chrono = std::chrono;
29 namespace time_internal {
36 #define ExpectTime(tp, tz, y, m, d, hh, mm, ss, off, isdst, zone) \ 38 time_zone::absolute_lookup al = tz.lookup(tp); \ 39 EXPECT_EQ(y, al.cs.year()); \ 40 EXPECT_EQ(m, al.cs.month()); \ 41 EXPECT_EQ(d, al.cs.day()); \ 42 EXPECT_EQ(hh, al.cs.hour()); \ 43 EXPECT_EQ(mm, al.cs.minute()); \ 44 EXPECT_EQ(ss, al.cs.second()); \ 45 EXPECT_EQ(off, al.offset); \ 46 EXPECT_TRUE(isdst == al.is_dst); \ 47 EXPECT_STREQ(zone, al.abbr); \ 59 void TestFormatSpecifier(time_point<D> tp, time_zone tz,
const std::string& fmt,
60 const std::string& ans) {
61 EXPECT_EQ(ans,
format(fmt, tp, tz)) << fmt;
62 EXPECT_EQ(
"xxx " + ans,
format(
"xxx " + fmt, tp, tz));
63 EXPECT_EQ(ans +
" yyy",
format(fmt +
" yyy", tp, tz));
64 EXPECT_EQ(
"xxx " + ans +
" yyy",
format(
"xxx " + fmt +
" yyy", tp, tz));
74 const char kFmt[] =
"%H:%M:%E*S";
77 chrono::system_clock::from_time_t(1420167845) +
78 chrono::milliseconds(123) + chrono::microseconds(456) +
79 chrono::nanoseconds(789);
82 format(kFmt, chrono::time_point_cast<chrono::nanoseconds>(t0), utc));
85 format(kFmt, chrono::time_point_cast<chrono::microseconds>(t0), utc));
88 format(kFmt, chrono::time_point_cast<chrono::milliseconds>(t0), utc));
90 format(kFmt, chrono::time_point_cast<chrono::seconds>(t0), utc));
92 format(kFmt, chrono::time_point_cast<absl::time_internal::cctz::seconds>(t0), utc));
94 format(kFmt, chrono::time_point_cast<chrono::minutes>(t0), utc));
96 format(kFmt, chrono::time_point_cast<chrono::hours>(t0), utc));
100 const char kFmt[] =
"%H:%M:%E*S";
104 chrono::system_clock::from_time_t(0)) +
108 "12:34:56.123456789012345",
111 "12:34:56.012345678901234",
114 "12:34:56.001234567890123",
117 "12:34:56.000123456789012",
120 EXPECT_EQ(
"12:34:56.000000000000123",
122 EXPECT_EQ(
"12:34:56.000000000000012",
124 EXPECT_EQ(
"12:34:56.000000000000001",
133 EXPECT_EQ(
"",
format(
"", tp, tz));
134 EXPECT_EQ(
" ",
format(
" ", tp, tz));
135 EXPECT_EQ(
" ",
format(
" ", tp, tz));
136 EXPECT_EQ(
"xxx",
format(
"xxx", tp, tz));
137 std::string big(128,
'x');
138 EXPECT_EQ(big,
format(big, tp, tz));
140 std::string bigger(100000,
'x');
141 EXPECT_EQ(bigger,
format(bigger, tp, tz));
144 tp += chrono::milliseconds(6) + chrono::microseconds(7) +
145 chrono::nanoseconds(8);
146 EXPECT_EQ(
"1970-01-01",
format(
"%Y-%m-%d", tp, tz));
147 EXPECT_EQ(
"13:04:05",
format(
"%H:%M:%S", tp, tz));
148 EXPECT_EQ(
"13:04:05.006",
format(
"%H:%M:%E3S", tp, tz));
149 EXPECT_EQ(
"13:04:05.006007",
format(
"%H:%M:%E6S", tp, tz));
150 EXPECT_EQ(
"13:04:05.006007008",
format(
"%H:%M:%E9S", tp, tz));
155 auto tp = chrono::system_clock::from_time_t(0);
157 TestFormatSpecifier(tp, tz,
"%d",
"01");
158 TestFormatSpecifier(tp, tz,
"%e",
" 1");
159 TestFormatSpecifier(tp, tz,
"%H",
"00");
160 TestFormatSpecifier(tp, tz,
"%I",
"12");
161 TestFormatSpecifier(tp, tz,
"%j",
"001");
162 TestFormatSpecifier(tp, tz,
"%m",
"01");
163 TestFormatSpecifier(tp, tz,
"%M",
"00");
164 TestFormatSpecifier(tp, tz,
"%S",
"00");
165 TestFormatSpecifier(tp, tz,
"%U",
"00");
166 #if !defined(__EMSCRIPTEN__) 167 TestFormatSpecifier(tp, tz,
"%w",
"4");
169 TestFormatSpecifier(tp, tz,
"%W",
"00");
170 TestFormatSpecifier(tp, tz,
"%y",
"70");
171 TestFormatSpecifier(tp, tz,
"%Y",
"1970");
172 TestFormatSpecifier(tp, tz,
"%z",
"+0000");
173 TestFormatSpecifier(tp, tz,
"%Z",
"UTC");
174 TestFormatSpecifier(tp, tz,
"%%",
"%");
176 #if defined(__linux__) 178 TestFormatSpecifier(tp, tz,
"%C",
"19");
179 TestFormatSpecifier(tp, tz,
"%D",
"01/01/70");
180 TestFormatSpecifier(tp, tz,
"%F",
"1970-01-01");
181 TestFormatSpecifier(tp, tz,
"%g",
"70");
182 TestFormatSpecifier(tp, tz,
"%G",
"1970");
183 TestFormatSpecifier(tp, tz,
"%k",
" 0");
184 TestFormatSpecifier(tp, tz,
"%l",
"12");
185 TestFormatSpecifier(tp, tz,
"%n",
"\n");
186 TestFormatSpecifier(tp, tz,
"%R",
"00:00");
187 TestFormatSpecifier(tp, tz,
"%t",
"\t");
188 TestFormatSpecifier(tp, tz,
"%T",
"00:00:00");
189 TestFormatSpecifier(tp, tz,
"%u",
"4");
190 TestFormatSpecifier(tp, tz,
"%V",
"01");
191 TestFormatSpecifier(tp, tz,
"%s",
"0");
197 auto tp = chrono::system_clock::from_time_t(0);
199 TestFormatSpecifier(tp, tz,
"%a",
"Thu");
200 TestFormatSpecifier(tp, tz,
"%A",
"Thursday");
201 TestFormatSpecifier(tp, tz,
"%b",
"Jan");
202 TestFormatSpecifier(tp, tz,
"%B",
"January");
206 EXPECT_THAT(s, testing::HasSubstr(
"1970"));
207 EXPECT_THAT(s, testing::HasSubstr(
"00:00:00"));
209 TestFormatSpecifier(tp, tz,
"%p",
"AM");
210 TestFormatSpecifier(tp, tz,
"%x",
"01/01/70");
211 TestFormatSpecifier(tp, tz,
"%X",
"00:00:00");
213 #if defined(__linux__) 215 TestFormatSpecifier(tp, tz,
"%h",
"Jan");
216 TestFormatSpecifier(tp, tz,
"%P",
"am");
217 TestFormatSpecifier(tp, tz,
"%r",
"12:00:00 AM");
220 TestFormatSpecifier(tp, tz,
"%Ec",
"Thu Jan 1 00:00:00 1970");
221 TestFormatSpecifier(tp, tz,
"%EC",
"19");
222 TestFormatSpecifier(tp, tz,
"%Ex",
"01/01/70");
223 TestFormatSpecifier(tp, tz,
"%EX",
"00:00:00");
224 TestFormatSpecifier(tp, tz,
"%Ey",
"70");
225 TestFormatSpecifier(tp, tz,
"%EY",
"1970");
228 TestFormatSpecifier(tp, tz,
"%Od",
"01");
229 TestFormatSpecifier(tp, tz,
"%Oe",
" 1");
230 TestFormatSpecifier(tp, tz,
"%OH",
"00");
231 TestFormatSpecifier(tp, tz,
"%OI",
"12");
232 TestFormatSpecifier(tp, tz,
"%Om",
"01");
233 TestFormatSpecifier(tp, tz,
"%OM",
"00");
234 TestFormatSpecifier(tp, tz,
"%OS",
"00");
235 TestFormatSpecifier(tp, tz,
"%Ou",
"4");
236 TestFormatSpecifier(tp, tz,
"%OU",
"00");
237 TestFormatSpecifier(tp, tz,
"%OV",
"01");
238 TestFormatSpecifier(tp, tz,
"%Ow",
"4");
239 TestFormatSpecifier(tp, tz,
"%OW",
"00");
240 TestFormatSpecifier(tp, tz,
"%Oy",
"70");
246 auto tp = chrono::system_clock::from_time_t(0);
248 TestFormatSpecifier(tp, tz,
"%%",
"%");
249 TestFormatSpecifier(tp, tz,
"%%a",
"%a");
250 TestFormatSpecifier(tp, tz,
"%%b",
"%b");
251 TestFormatSpecifier(tp, tz,
"%%Ea",
"%Ea");
252 TestFormatSpecifier(tp, tz,
"%%Es",
"%Es");
253 TestFormatSpecifier(tp, tz,
"%%E3S",
"%E3S");
254 TestFormatSpecifier(tp, tz,
"%%OS",
"%OS");
255 TestFormatSpecifier(tp, tz,
"%%O3S",
"%O3S");
258 TestFormatSpecifier(tp, tz,
"%%%Y",
"%1970");
259 TestFormatSpecifier(tp, tz,
"%%%E3S",
"%00.000");
260 TestFormatSpecifier(tp, tz,
"%%%%E3S",
"%%E3S");
269 EXPECT_EQ(
"05",
format(
"%E*S", tp, tz));
270 EXPECT_EQ(
"05",
format(
"%E0S", tp, tz));
271 EXPECT_EQ(
"05.0",
format(
"%E1S", tp, tz));
272 EXPECT_EQ(
"05.00",
format(
"%E2S", tp, tz));
273 EXPECT_EQ(
"05.000",
format(
"%E3S", tp, tz));
274 EXPECT_EQ(
"05.0000",
format(
"%E4S", tp, tz));
275 EXPECT_EQ(
"05.00000",
format(
"%E5S", tp, tz));
276 EXPECT_EQ(
"05.000000",
format(
"%E6S", tp, tz));
277 EXPECT_EQ(
"05.0000000",
format(
"%E7S", tp, tz));
278 EXPECT_EQ(
"05.00000000",
format(
"%E8S", tp, tz));
279 EXPECT_EQ(
"05.000000000",
format(
"%E9S", tp, tz));
280 EXPECT_EQ(
"05.0000000000",
format(
"%E10S", tp, tz));
281 EXPECT_EQ(
"05.00000000000",
format(
"%E11S", tp, tz));
282 EXPECT_EQ(
"05.000000000000",
format(
"%E12S", tp, tz));
283 EXPECT_EQ(
"05.0000000000000",
format(
"%E13S", tp, tz));
284 EXPECT_EQ(
"05.00000000000000",
format(
"%E14S", tp, tz));
285 EXPECT_EQ(
"05.000000000000000",
format(
"%E15S", tp, tz));
288 tp += chrono::milliseconds(6) + chrono::microseconds(7) +
289 chrono::nanoseconds(8);
290 EXPECT_EQ(
"05.006007008",
format(
"%E*S", tp, tz));
291 EXPECT_EQ(
"05",
format(
"%E0S", tp, tz));
292 EXPECT_EQ(
"05.0",
format(
"%E1S", tp, tz));
293 EXPECT_EQ(
"05.00",
format(
"%E2S", tp, tz));
294 EXPECT_EQ(
"05.006",
format(
"%E3S", tp, tz));
295 EXPECT_EQ(
"05.0060",
format(
"%E4S", tp, tz));
296 EXPECT_EQ(
"05.00600",
format(
"%E5S", tp, tz));
297 EXPECT_EQ(
"05.006007",
format(
"%E6S", tp, tz));
298 EXPECT_EQ(
"05.0060070",
format(
"%E7S", tp, tz));
299 EXPECT_EQ(
"05.00600700",
format(
"%E8S", tp, tz));
300 EXPECT_EQ(
"05.006007008",
format(
"%E9S", tp, tz));
301 EXPECT_EQ(
"05.0060070080",
format(
"%E10S", tp, tz));
302 EXPECT_EQ(
"05.00600700800",
format(
"%E11S", tp, tz));
303 EXPECT_EQ(
"05.006007008000",
format(
"%E12S", tp, tz));
304 EXPECT_EQ(
"05.0060070080000",
format(
"%E13S", tp, tz));
305 EXPECT_EQ(
"05.00600700800000",
format(
"%E14S", tp, tz));
306 EXPECT_EQ(
"05.006007008000000",
format(
"%E15S", tp, tz));
309 tp = chrono::system_clock::from_time_t(0) + chrono::microseconds(-1);
310 EXPECT_EQ(
"1969-12-31 23:59:59.999999",
311 format(
"%Y-%m-%d %H:%M:%E*S", tp, tz));
316 tp = chrono::system_clock::from_time_t(0) +
317 chrono::microseconds(1395024427333304);
318 EXPECT_EQ(
"2014-03-17 02:47:07.333304",
319 format(
"%Y-%m-%d %H:%M:%E*S", tp, tz));
320 tp += chrono::microseconds(1);
321 EXPECT_EQ(
"2014-03-17 02:47:07.333305",
322 format(
"%Y-%m-%d %H:%M:%E*S", tp, tz));
331 EXPECT_EQ(
"0",
format(
"%E*f", tp, tz));
332 EXPECT_EQ(
"",
format(
"%E0f", tp, tz));
333 EXPECT_EQ(
"0",
format(
"%E1f", tp, tz));
334 EXPECT_EQ(
"00",
format(
"%E2f", tp, tz));
335 EXPECT_EQ(
"000",
format(
"%E3f", tp, tz));
336 EXPECT_EQ(
"0000",
format(
"%E4f", tp, tz));
337 EXPECT_EQ(
"00000",
format(
"%E5f", tp, tz));
338 EXPECT_EQ(
"000000",
format(
"%E6f", tp, tz));
339 EXPECT_EQ(
"0000000",
format(
"%E7f", tp, tz));
340 EXPECT_EQ(
"00000000",
format(
"%E8f", tp, tz));
341 EXPECT_EQ(
"000000000",
format(
"%E9f", tp, tz));
342 EXPECT_EQ(
"0000000000",
format(
"%E10f", tp, tz));
343 EXPECT_EQ(
"00000000000",
format(
"%E11f", tp, tz));
344 EXPECT_EQ(
"000000000000",
format(
"%E12f", tp, tz));
345 EXPECT_EQ(
"0000000000000",
format(
"%E13f", tp, tz));
346 EXPECT_EQ(
"00000000000000",
format(
"%E14f", tp, tz));
347 EXPECT_EQ(
"000000000000000",
format(
"%E15f", tp, tz));
350 tp += chrono::milliseconds(6) + chrono::microseconds(7) +
351 chrono::nanoseconds(8);
352 EXPECT_EQ(
"006007008",
format(
"%E*f", tp, tz));
353 EXPECT_EQ(
"",
format(
"%E0f", tp, tz));
354 EXPECT_EQ(
"0",
format(
"%E1f", tp, tz));
355 EXPECT_EQ(
"00",
format(
"%E2f", tp, tz));
356 EXPECT_EQ(
"006",
format(
"%E3f", tp, tz));
357 EXPECT_EQ(
"0060",
format(
"%E4f", tp, tz));
358 EXPECT_EQ(
"00600",
format(
"%E5f", tp, tz));
359 EXPECT_EQ(
"006007",
format(
"%E6f", tp, tz));
360 EXPECT_EQ(
"0060070",
format(
"%E7f", tp, tz));
361 EXPECT_EQ(
"00600700",
format(
"%E8f", tp, tz));
362 EXPECT_EQ(
"006007008",
format(
"%E9f", tp, tz));
363 EXPECT_EQ(
"0060070080",
format(
"%E10f", tp, tz));
364 EXPECT_EQ(
"00600700800",
format(
"%E11f", tp, tz));
365 EXPECT_EQ(
"006007008000",
format(
"%E12f", tp, tz));
366 EXPECT_EQ(
"0060070080000",
format(
"%E13f", tp, tz));
367 EXPECT_EQ(
"00600700800000",
format(
"%E14f", tp, tz));
368 EXPECT_EQ(
"006007008000000",
format(
"%E15f", tp, tz));
371 tp = chrono::system_clock::from_time_t(0) + chrono::microseconds(-1);
372 EXPECT_EQ(
"1969-12-31 23:59:59.999999",
373 format(
"%Y-%m-%d %H:%M:%S.%E*f", tp, tz));
378 tp = chrono::system_clock::from_time_t(0) +
379 chrono::microseconds(1395024427333304);
380 EXPECT_EQ(
"2014-03-17 02:47:07.333304",
381 format(
"%Y-%m-%d %H:%M:%S.%E*f", tp, tz));
382 tp += chrono::microseconds(1);
383 EXPECT_EQ(
"2014-03-17 02:47:07.333305",
384 format(
"%Y-%m-%d %H:%M:%S.%E*f", tp, tz));
393 auto fmt_A = [](
const std::string&
prec) {
return "%E" +
prec +
"S"; };
394 auto fmt_B = [](
const std::string&
prec) {
return "%S.%E" +
prec +
"f"; };
400 EXPECT_EQ(
"05",
format(fmt_A(
"*"), tp, tz));
401 EXPECT_EQ(
"05.0",
format(fmt_B(
"*"), tp, tz));
403 EXPECT_EQ(
"05",
format(fmt_A(
"0"), tp, tz));
404 EXPECT_EQ(
"05.",
format(fmt_B(
"0"), tp, tz));
407 const std::string
a =
format(fmt_A(std::to_string(
prec)), tp, tz);
408 const std::string
b =
format(fmt_B(std::to_string(
prec)), tp, tz);
409 EXPECT_EQ(a, b) <<
"prec=" <<
prec;
414 tp += chrono::milliseconds(6) + chrono::microseconds(7) +
415 chrono::nanoseconds(8);
416 EXPECT_EQ(
"05.006007008",
format(fmt_A(
"*"), tp, tz));
417 EXPECT_EQ(
"05.006007008",
format(fmt_B(
"*"), tp, tz));
419 EXPECT_EQ(
"05",
format(fmt_A(
"0"), tp, tz));
420 EXPECT_EQ(
"05.",
format(fmt_B(
"0"), tp, tz));
423 const std::string
a =
format(fmt_A(std::to_string(
prec)), tp, tz);
424 const std::string
b =
format(fmt_B(std::to_string(
prec)), tp, tz);
425 EXPECT_EQ(a, b) <<
"prec=" <<
prec;
430 const auto tp = chrono::system_clock::from_time_t(0);
433 TestFormatSpecifier(tp, tz,
"%z",
"+0000");
434 TestFormatSpecifier(tp, tz,
"%:z",
"+00:00");
435 TestFormatSpecifier(tp, tz,
"%Ez",
"+00:00");
438 TestFormatSpecifier(tp, tz,
"%z",
"+0000");
439 TestFormatSpecifier(tp, tz,
"%:z",
"+00:00");
440 TestFormatSpecifier(tp, tz,
"%Ez",
"+00:00");
443 TestFormatSpecifier(tp, tz,
"%z",
"+0000");
444 TestFormatSpecifier(tp, tz,
"%:z",
"+00:00");
445 TestFormatSpecifier(tp, tz,
"%Ez",
"+00:00");
448 TestFormatSpecifier(tp, tz,
"%z",
"+0034");
449 TestFormatSpecifier(tp, tz,
"%:z",
"+00:34");
450 TestFormatSpecifier(tp, tz,
"%Ez",
"+00:34");
453 TestFormatSpecifier(tp, tz,
"%z",
"-0034");
454 TestFormatSpecifier(tp, tz,
"%:z",
"-00:34");
455 TestFormatSpecifier(tp, tz,
"%Ez",
"-00:34");
458 TestFormatSpecifier(tp, tz,
"%z",
"+0034");
459 TestFormatSpecifier(tp, tz,
"%:z",
"+00:34");
460 TestFormatSpecifier(tp, tz,
"%Ez",
"+00:34");
463 TestFormatSpecifier(tp, tz,
"%z",
"-0034");
464 TestFormatSpecifier(tp, tz,
"%:z",
"-00:34");
465 TestFormatSpecifier(tp, tz,
"%Ez",
"-00:34");
468 TestFormatSpecifier(tp, tz,
"%z",
"+1200");
469 TestFormatSpecifier(tp, tz,
"%:z",
"+12:00");
470 TestFormatSpecifier(tp, tz,
"%Ez",
"+12:00");
473 TestFormatSpecifier(tp, tz,
"%z",
"-1200");
474 TestFormatSpecifier(tp, tz,
"%:z",
"-12:00");
475 TestFormatSpecifier(tp, tz,
"%Ez",
"-12:00");
478 TestFormatSpecifier(tp, tz,
"%z",
"+1200");
479 TestFormatSpecifier(tp, tz,
"%:z",
"+12:00");
480 TestFormatSpecifier(tp, tz,
"%Ez",
"+12:00");
483 TestFormatSpecifier(tp, tz,
"%z",
"-1200");
484 TestFormatSpecifier(tp, tz,
"%:z",
"-12:00");
485 TestFormatSpecifier(tp, tz,
"%Ez",
"-12:00");
488 TestFormatSpecifier(tp, tz,
"%z",
"+1234");
489 TestFormatSpecifier(tp, tz,
"%:z",
"+12:34");
490 TestFormatSpecifier(tp, tz,
"%Ez",
"+12:34");
493 TestFormatSpecifier(tp, tz,
"%z",
"-1234");
494 TestFormatSpecifier(tp, tz,
"%:z",
"-12:34");
495 TestFormatSpecifier(tp, tz,
"%Ez",
"-12:34");
499 TestFormatSpecifier(tp, tz,
"%z",
"+1234");
500 TestFormatSpecifier(tp, tz,
"%:z",
"+12:34");
501 TestFormatSpecifier(tp, tz,
"%Ez",
"+12:34");
505 TestFormatSpecifier(tp, tz,
"%z",
"-1234");
506 TestFormatSpecifier(tp, tz,
"%:z",
"-12:34");
507 TestFormatSpecifier(tp, tz,
"%Ez",
"-12:34");
511 const auto tp = chrono::system_clock::from_time_t(0);
514 TestFormatSpecifier(tp, tz,
"%E*z",
"+00:00:00");
515 TestFormatSpecifier(tp, tz,
"%::z",
"+00:00:00");
516 TestFormatSpecifier(tp, tz,
"%:::z",
"+00");
519 TestFormatSpecifier(tp, tz,
"%E*z",
"+00:00:56");
520 TestFormatSpecifier(tp, tz,
"%::z",
"+00:00:56");
521 TestFormatSpecifier(tp, tz,
"%:::z",
"+00:00:56");
524 TestFormatSpecifier(tp, tz,
"%E*z",
"-00:00:56");
525 TestFormatSpecifier(tp, tz,
"%::z",
"-00:00:56");
526 TestFormatSpecifier(tp, tz,
"%:::z",
"-00:00:56");
529 TestFormatSpecifier(tp, tz,
"%E*z",
"+00:34:00");
530 TestFormatSpecifier(tp, tz,
"%::z",
"+00:34:00");
531 TestFormatSpecifier(tp, tz,
"%:::z",
"+00:34");
534 TestFormatSpecifier(tp, tz,
"%E*z",
"-00:34:00");
535 TestFormatSpecifier(tp, tz,
"%::z",
"-00:34:00");
536 TestFormatSpecifier(tp, tz,
"%:::z",
"-00:34");
539 TestFormatSpecifier(tp, tz,
"%E*z",
"+00:34:56");
540 TestFormatSpecifier(tp, tz,
"%::z",
"+00:34:56");
541 TestFormatSpecifier(tp, tz,
"%:::z",
"+00:34:56");
544 TestFormatSpecifier(tp, tz,
"%E*z",
"-00:34:56");
545 TestFormatSpecifier(tp, tz,
"%::z",
"-00:34:56");
546 TestFormatSpecifier(tp, tz,
"%:::z",
"-00:34:56");
549 TestFormatSpecifier(tp, tz,
"%E*z",
"+12:00:00");
550 TestFormatSpecifier(tp, tz,
"%::z",
"+12:00:00");
551 TestFormatSpecifier(tp, tz,
"%:::z",
"+12");
554 TestFormatSpecifier(tp, tz,
"%E*z",
"-12:00:00");
555 TestFormatSpecifier(tp, tz,
"%::z",
"-12:00:00");
556 TestFormatSpecifier(tp, tz,
"%:::z",
"-12");
559 TestFormatSpecifier(tp, tz,
"%E*z",
"+12:00:56");
560 TestFormatSpecifier(tp, tz,
"%::z",
"+12:00:56");
561 TestFormatSpecifier(tp, tz,
"%:::z",
"+12:00:56");
564 TestFormatSpecifier(tp, tz,
"%E*z",
"-12:00:56");
565 TestFormatSpecifier(tp, tz,
"%::z",
"-12:00:56");
566 TestFormatSpecifier(tp, tz,
"%:::z",
"-12:00:56");
569 TestFormatSpecifier(tp, tz,
"%E*z",
"+12:34:00");
570 TestFormatSpecifier(tp, tz,
"%::z",
"+12:34:00");
571 TestFormatSpecifier(tp, tz,
"%:::z",
"+12:34");
574 TestFormatSpecifier(tp, tz,
"%E*z",
"-12:34:00");
575 TestFormatSpecifier(tp, tz,
"%::z",
"-12:34:00");
576 TestFormatSpecifier(tp, tz,
"%:::z",
"-12:34");
580 TestFormatSpecifier(tp, tz,
"%E*z",
"+12:34:56");
581 TestFormatSpecifier(tp, tz,
"%::z",
"+12:34:56");
582 TestFormatSpecifier(tp, tz,
"%:::z",
"+12:34:56");
586 TestFormatSpecifier(tp, tz,
"%E*z",
"-12:34:56");
587 TestFormatSpecifier(tp, tz,
"%::z",
"-12:34:56");
588 TestFormatSpecifier(tp, tz,
"%:::z",
"-12:34:56");
593 const char e4y_fmt[] =
"%E4Y%m%d";
597 EXPECT_EQ(
"-9991127",
format(e4y_fmt, tp, utc));
599 EXPECT_EQ(
"-0991127",
format(e4y_fmt, tp, utc));
601 EXPECT_EQ(
"-0091127",
format(e4y_fmt, tp, utc));
603 EXPECT_EQ(
"-0011127",
format(e4y_fmt, tp, utc));
605 EXPECT_EQ(
"00001127",
format(e4y_fmt, tp, utc));
607 EXPECT_EQ(
"00011127",
format(e4y_fmt, tp, utc));
609 EXPECT_EQ(
"00091127",
format(e4y_fmt, tp, utc));
611 EXPECT_EQ(
"00991127",
format(e4y_fmt, tp, utc));
613 EXPECT_EQ(
"09991127",
format(e4y_fmt, tp, utc));
615 EXPECT_EQ(
"99991127",
format(e4y_fmt, tp, utc));
619 EXPECT_EQ(
"-10001127",
format(e4y_fmt, tp, utc));
621 EXPECT_EQ(
"100001127",
format(e4y_fmt, tp, utc));
633 tp += chrono::milliseconds(100);
637 tp += chrono::milliseconds(20);
641 tp += chrono::milliseconds(3);
645 tp += chrono::microseconds(400);
649 tp += chrono::microseconds(50);
653 tp += chrono::microseconds(6);
657 tp += chrono::nanoseconds(700);
661 tp += chrono::nanoseconds(80);
665 tp += chrono::nanoseconds(9);
666 EXPECT_EQ(
"1977-06-28T09:08:07.123456789-07:00",
685 const char kFmt[] =
"%H:%M:%E*S";
689 EXPECT_TRUE(
parse(kFmt,
"03:04:05.123456789", utc, &tp_ns));
690 EXPECT_EQ(
"03:04:05.123456789",
format(kFmt, tp_ns, utc));
691 EXPECT_TRUE(
parse(kFmt,
"03:04:05.123456", utc, &tp_ns));
692 EXPECT_EQ(
"03:04:05.123456",
format(kFmt, tp_ns, utc));
695 EXPECT_TRUE(
parse(kFmt,
"03:04:05.123456789", utc, &tp_us));
696 EXPECT_EQ(
"03:04:05.123456",
format(kFmt, tp_us, utc));
697 EXPECT_TRUE(
parse(kFmt,
"03:04:05.123456", utc, &tp_us));
698 EXPECT_EQ(
"03:04:05.123456",
format(kFmt, tp_us, utc));
699 EXPECT_TRUE(
parse(kFmt,
"03:04:05.123", utc, &tp_us));
700 EXPECT_EQ(
"03:04:05.123",
format(kFmt, tp_us, utc));
703 EXPECT_TRUE(
parse(kFmt,
"03:04:05.123456", utc, &tp_ms));
704 EXPECT_EQ(
"03:04:05.123",
format(kFmt, tp_ms, utc));
705 EXPECT_TRUE(
parse(kFmt,
"03:04:05.123", utc, &tp_ms));
706 EXPECT_EQ(
"03:04:05.123",
format(kFmt, tp_ms, utc));
707 EXPECT_TRUE(
parse(kFmt,
"03:04:05", utc, &tp_ms));
708 EXPECT_EQ(
"03:04:05",
format(kFmt, tp_ms, utc));
711 EXPECT_TRUE(
parse(kFmt,
"03:04:05.123", utc, &tp_s));
712 EXPECT_EQ(
"03:04:05",
format(kFmt, tp_s, utc));
713 EXPECT_TRUE(
parse(kFmt,
"03:04:05", utc, &tp_s));
714 EXPECT_EQ(
"03:04:05",
format(kFmt, tp_s, utc));
717 EXPECT_TRUE(
parse(kFmt,
"03:04:05", utc, &tp_m));
718 EXPECT_EQ(
"03:04:00",
format(kFmt, tp_m, utc));
721 EXPECT_TRUE(
parse(kFmt,
"03:04:05", utc, &tp_h));
722 EXPECT_EQ(
"03:00:00",
format(kFmt, tp_h, utc));
726 const char kFmt[] =
"%H:%M:%E*S";
731 EXPECT_TRUE(
detail::parse(kFmt,
"12:34:56.123456789012345", utc, &tp, &fs));
732 EXPECT_EQ(
"12:34:56.123456789012345",
detail::format(kFmt, tp, fs, utc));
733 EXPECT_TRUE(
detail::parse(kFmt,
"12:34:56.012345678901234", utc, &tp, &fs));
734 EXPECT_EQ(
"12:34:56.012345678901234",
detail::format(kFmt, tp, fs, utc));
735 EXPECT_TRUE(
detail::parse(kFmt,
"12:34:56.001234567890123", utc, &tp, &fs));
736 EXPECT_EQ(
"12:34:56.001234567890123",
detail::format(kFmt, tp, fs, utc));
737 EXPECT_TRUE(
detail::parse(kFmt,
"12:34:56.000000000000123", utc, &tp, &fs));
738 EXPECT_EQ(
"12:34:56.000000000000123",
detail::format(kFmt, tp, fs, utc));
739 EXPECT_TRUE(
detail::parse(kFmt,
"12:34:56.000000000000012", utc, &tp, &fs));
740 EXPECT_EQ(
"12:34:56.000000000000012",
detail::format(kFmt, tp, fs, utc));
741 EXPECT_TRUE(
detail::parse(kFmt,
"12:34:56.000000000000001", utc, &tp, &fs));
742 EXPECT_EQ(
"12:34:56.000000000000001",
detail::format(kFmt, tp, fs, utc));
748 chrono::system_clock::from_time_t(1234567890);
751 EXPECT_TRUE(
parse(
"",
"", tz, &tp));
752 EXPECT_EQ(chrono::system_clock::from_time_t(0), tp);
753 EXPECT_TRUE(
parse(
" ",
" ", tz, &tp));
754 EXPECT_TRUE(
parse(
" ",
" ", tz, &tp));
755 EXPECT_TRUE(
parse(
"x",
"x", tz, &tp));
756 EXPECT_TRUE(
parse(
"xxx",
"xxx", tz, &tp));
759 parse(
"%Y-%m-%d %H:%M:%S %z",
"2013-06-28 19:08:09 -0800", tz, &tp));
760 ExpectTime(tp, tz, 2013, 6, 29, 3, 8, 9, 0,
false,
"UTC");
769 EXPECT_TRUE(
parse(
"%Y-%m-%d %H:%M:%S",
"2013-06-28 19:08:09", tz, &tp));
770 ExpectTime(tp, tz, 2013, 6, 28, 19, 8, 9, -7 * 60 * 60,
true,
"PDT");
773 EXPECT_TRUE(
parse(
"%Y-%m-%d %H:%M:%S %z",
"2013-06-28 19:08:09 +0800",
775 ExpectTime(tp, tz, 2013, 6, 28, 19 - 8 - 7, 8, 9, -7 * 60 * 60,
true,
"PDT");
779 EXPECT_TRUE(
parse(
"%Y-%m-%d %H:%M:%S",
"2011-03-13 02:15:00", tz, &tp));
780 ExpectTime(tp, tz, 2011, 3, 13, 3, 15, 0, -7 * 60 * 60,
true,
"PDT");
784 EXPECT_TRUE(
parse(
"%Y-%m-%d %H:%M:%S",
"2011-11-06 01:15:00", tz, &tp));
785 ExpectTime(tp, tz, 2011, 11, 6, 1, 15, 0, -7 * 60 * 60,
true,
"PDT");
795 ExpectTime(tp, tz, 2013, 6, 28, 8, 8, 59, -7 * 60 * 60,
true,
"PDT");
799 ExpectTime(tp, tz, 2013, 6, 28, 8, 8, 59, -7 * 60 * 60,
true,
"PDT");
803 ExpectTime(tp, tz, 2013, 6, 28, 8, 9, 0, -7 * 60 * 60,
true,
"PDT");
807 ExpectTime(tp, tz, 2013, 6, 28, 8, 9, 0, -7 * 60 * 60,
true,
"PDT");
815 auto tp = chrono::system_clock::from_time_t(0);
818 EXPECT_FALSE(
parse(
"%S",
"123", tz, &tp));
821 EXPECT_FALSE(
parse(
"%Q",
"x", tz, &tp));
824 EXPECT_FALSE(
parse(
"%m-%d",
"2-3 blah", tz, &tp));
827 EXPECT_TRUE(
parse(
"%m-%d",
"2-3 ", tz, &tp));
832 EXPECT_FALSE(
parse(
"%m-%d",
"2-31", tz, &tp));
835 EXPECT_TRUE(
parse(
"%z",
"-0203", tz, &tp));
836 EXPECT_FALSE(
parse(
"%z",
"- 2 3", tz, &tp));
837 EXPECT_TRUE(
parse(
"%Ez",
"-02:03", tz, &tp));
838 EXPECT_FALSE(
parse(
"%Ez",
"- 2: 3", tz, &tp));
841 EXPECT_FALSE(
parse(
"%Ez",
"+-08:00", tz, &tp));
842 EXPECT_FALSE(
parse(
"%Ez",
"-+08:00", tz, &tp));
845 EXPECT_FALSE(
parse(
"%Y",
"-0", tz, &tp));
846 EXPECT_FALSE(
parse(
"%E4Y",
"-0", tz, &tp));
847 EXPECT_FALSE(
parse(
"%H",
"-0", tz, &tp));
848 EXPECT_FALSE(
parse(
"%M",
"-0", tz, &tp));
849 EXPECT_FALSE(
parse(
"%S",
"-0", tz, &tp));
850 EXPECT_FALSE(
parse(
"%z",
"+-000", tz, &tp));
851 EXPECT_FALSE(
parse(
"%Ez",
"+-0:00", tz, &tp));
852 EXPECT_FALSE(
parse(
"%z",
"-00-0", tz, &tp));
853 EXPECT_FALSE(
parse(
"%Ez",
"-00:-0", tz, &tp));
858 auto tp = chrono::system_clock::from_time_t(0);
862 EXPECT_TRUE(
parse(
"%d",
"15", tz, &tp));
863 EXPECT_EQ(15,
convert(tp, tz).day());
867 EXPECT_TRUE(
parse(
"%e",
"15", tz, &tp));
868 EXPECT_EQ(15,
convert(tp, tz).day());
871 EXPECT_TRUE(
parse(
"%H",
"17", tz, &tp));
872 EXPECT_EQ(17,
convert(tp, tz).hour());
875 EXPECT_TRUE(
parse(
"%I",
"5", tz, &tp));
876 EXPECT_EQ(5,
convert(tp, tz).hour());
879 EXPECT_TRUE(
parse(
"%j",
"32", tz, &tp));
882 EXPECT_TRUE(
parse(
"%m",
"11", tz, &tp));
883 EXPECT_EQ(11,
convert(tp, tz).month());
886 EXPECT_TRUE(
parse(
"%M",
"33", tz, &tp));
887 EXPECT_EQ(33,
convert(tp, tz).minute());
890 EXPECT_TRUE(
parse(
"%S",
"55", tz, &tp));
891 EXPECT_EQ(55,
convert(tp, tz).second());
894 EXPECT_TRUE(
parse(
"%U",
"15", tz, &tp));
897 EXPECT_TRUE(
parse(
"%w",
"2", tz, &tp));
900 EXPECT_TRUE(
parse(
"%W",
"22", tz, &tp));
903 EXPECT_TRUE(
parse(
"%y",
"04", tz, &tp));
904 EXPECT_EQ(2004,
convert(tp, tz).year());
907 EXPECT_TRUE(
parse(
"%Y",
"2004", tz, &tp));
908 EXPECT_EQ(2004,
convert(tp, tz).year());
910 EXPECT_TRUE(
parse(
"%%",
"%", tz, &tp));
912 #if defined(__linux__) 920 EXPECT_TRUE(
parse(
"%C %y",
"20 04", tz, &tp));
921 EXPECT_EQ(2004,
convert(tp, tz).year());
925 EXPECT_TRUE(
parse(
"%D",
"02/03/04", tz, &tp));
926 EXPECT_EQ(2,
convert(tp, tz).month());
927 EXPECT_EQ(3,
convert(tp, tz).day());
928 EXPECT_EQ(2004,
convert(tp, tz).year());
930 EXPECT_TRUE(
parse(
"%n",
"\n", tz, &tp));
933 EXPECT_TRUE(
parse(
"%R",
"03:44", tz, &tp));
934 EXPECT_EQ(3,
convert(tp, tz).hour());
935 EXPECT_EQ(44,
convert(tp, tz).minute());
937 EXPECT_TRUE(
parse(
"%t",
"\t\v\f\n\r ", tz, &tp));
940 EXPECT_TRUE(
parse(
"%T",
"03:44:55", tz, &tp));
941 EXPECT_EQ(3,
convert(tp, tz).hour());
942 EXPECT_EQ(44,
convert(tp, tz).minute());
943 EXPECT_EQ(55,
convert(tp, tz).second());
946 EXPECT_TRUE(
parse(
"%s",
"1234567890", tz, &tp));
947 EXPECT_EQ(chrono::system_clock::from_time_t(1234567890), tp);
953 EXPECT_TRUE(
parse(
"%s",
"1234567890", lax, &tp));
954 EXPECT_EQ(chrono::system_clock::from_time_t(1234567890), tp);
961 EXPECT_TRUE(
parse(
"%s",
"1414917000", lax, &tp));
962 EXPECT_EQ(chrono::system_clock::from_time_t(1414917000), tp);
964 EXPECT_TRUE(
parse(
"%s",
"1414920600", lax, &tp));
965 EXPECT_EQ(chrono::system_clock::from_time_t(1414920600), tp);
971 auto tp = chrono::system_clock::from_time_t(0);
975 EXPECT_TRUE(
parse(
"%a",
"Mon", tz, &tp));
978 EXPECT_TRUE(
parse(
"%A",
"Monday", tz, &tp));
981 EXPECT_TRUE(
parse(
"%b",
"Feb", tz, &tp));
982 EXPECT_EQ(2,
convert(tp, tz).month());
985 EXPECT_TRUE(
parse(
"%B",
"February", tz, &tp));
986 EXPECT_EQ(2,
convert(tp, tz).month());
989 EXPECT_TRUE(
parse(
"%p",
"AM", tz, &tp));
991 EXPECT_TRUE(
parse(
"%I %p",
"5 PM", tz, &tp));
992 EXPECT_EQ(17,
convert(tp, tz).hour());
995 EXPECT_TRUE(
parse(
"%x",
"02/03/04", tz, &tp));
996 if (
convert(tp, tz).month() == 2) {
997 EXPECT_EQ(3,
convert(tp, tz).day());
999 EXPECT_EQ(2,
convert(tp, tz).day());
1000 EXPECT_EQ(3,
convert(tp, tz).month());
1002 EXPECT_EQ(2004,
convert(tp, tz).year());
1005 EXPECT_TRUE(
parse(
"%X",
"15:44:55", tz, &tp));
1006 EXPECT_EQ(15,
convert(tp, tz).hour());
1007 EXPECT_EQ(44,
convert(tp, tz).minute());
1008 EXPECT_EQ(55,
convert(tp, tz).second());
1010 #if defined(__linux__) 1014 EXPECT_TRUE(
parse(
"%h",
"Feb", tz, &tp));
1015 EXPECT_EQ(2,
convert(tp, tz).month());
1018 EXPECT_TRUE(
parse(
"%l %p",
"5 PM", tz, &tp));
1019 EXPECT_EQ(17,
convert(tp, tz).hour());
1022 EXPECT_TRUE(
parse(
"%r",
"03:44:55 PM", tz, &tp));
1023 EXPECT_EQ(15,
convert(tp, tz).hour());
1024 EXPECT_EQ(44,
convert(tp, tz).minute());
1025 EXPECT_EQ(55,
convert(tp, tz).second());
1028 EXPECT_TRUE(
parse(
"%Ec",
"Tue Nov 19 05:06:07 2013", tz, &tp));
1034 EXPECT_TRUE(
parse(
"%Ex",
"02/03/04", tz, &tp));
1035 EXPECT_EQ(2,
convert(tp, tz).month());
1036 EXPECT_EQ(3,
convert(tp, tz).day());
1037 EXPECT_EQ(2004,
convert(tp, tz).year());
1040 EXPECT_TRUE(
parse(
"%EX",
"15:44:55", tz, &tp));
1041 EXPECT_EQ(15,
convert(tp, tz).hour());
1042 EXPECT_EQ(44,
convert(tp, tz).minute());
1043 EXPECT_EQ(55,
convert(tp, tz).second());
1052 EXPECT_TRUE(
parse(
"%EY",
"2004", tz, &tp));
1053 EXPECT_EQ(2004,
convert(tp, tz).year());
1058 EXPECT_TRUE(
parse(
"%Od",
"15", tz, &tp));
1059 EXPECT_EQ(15,
convert(tp, tz).day());
1062 EXPECT_TRUE(
parse(
"%Oe",
"15", tz, &tp));
1063 EXPECT_EQ(15,
convert(tp, tz).day());
1066 EXPECT_TRUE(
parse(
"%OH",
"17", tz, &tp));
1067 EXPECT_EQ(17,
convert(tp, tz).hour());
1070 EXPECT_TRUE(
parse(
"%OI",
"5", tz, &tp));
1071 EXPECT_EQ(5,
convert(tp, tz).hour());
1074 EXPECT_TRUE(
parse(
"%Om",
"11", tz, &tp));
1075 EXPECT_EQ(11,
convert(tp, tz).month());
1078 EXPECT_TRUE(
parse(
"%OM",
"33", tz, &tp));
1079 EXPECT_EQ(33,
convert(tp, tz).minute());
1082 EXPECT_TRUE(
parse(
"%OS",
"55", tz, &tp));
1083 EXPECT_EQ(55,
convert(tp, tz).second());
1086 EXPECT_TRUE(
parse(
"%OU",
"15", tz, &tp));
1089 EXPECT_TRUE(
parse(
"%Ow",
"2", tz, &tp));
1092 EXPECT_TRUE(
parse(
"%OW",
"22", tz, &tp));
1095 EXPECT_TRUE(
parse(
"%Oy",
"04", tz, &tp));
1096 EXPECT_EQ(2004,
convert(tp, tz).year());
1103 chrono::system_clock::from_time_t(0);
1106 auto precisions = {
"*",
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
1107 "8",
"9",
"10",
"11",
"12",
"13",
"14",
"15"};
1108 for (
const std::string&
prec : precisions) {
1109 const std::string fmt =
"%E" +
prec +
"S";
1112 EXPECT_TRUE(
parse(fmt,
"5", tz, &tp));
1115 EXPECT_TRUE(
parse(fmt,
"05", tz, &tp));
1118 EXPECT_TRUE(
parse(fmt,
"05.0", tz, &tp));
1121 EXPECT_TRUE(
parse(fmt,
"05.00", tz, &tp));
1124 EXPECT_TRUE(
parse(fmt,
"05.6", tz, &tp));
1125 EXPECT_EQ(unix_epoch +
chrono::seconds(5) + chrono::milliseconds(600), tp);
1127 EXPECT_TRUE(
parse(fmt,
"05.60", tz, &tp));
1128 EXPECT_EQ(unix_epoch +
chrono::seconds(5) + chrono::milliseconds(600), tp);
1130 EXPECT_TRUE(
parse(fmt,
"05.600", tz, &tp));
1131 EXPECT_EQ(unix_epoch +
chrono::seconds(5) + chrono::milliseconds(600), tp);
1133 EXPECT_TRUE(
parse(fmt,
"05.67", tz, &tp));
1134 EXPECT_EQ(unix_epoch +
chrono::seconds(5) + chrono::milliseconds(670), tp);
1136 EXPECT_TRUE(
parse(fmt,
"05.670", tz, &tp));
1137 EXPECT_EQ(unix_epoch +
chrono::seconds(5) + chrono::milliseconds(670), tp);
1139 EXPECT_TRUE(
parse(fmt,
"05.678", tz, &tp));
1140 EXPECT_EQ(unix_epoch +
chrono::seconds(5) + chrono::milliseconds(678), tp);
1147 EXPECT_TRUE(
parse(
"%E*S",
"0.2147483647", tz, &tp));
1148 EXPECT_EQ(unix_epoch + chrono::nanoseconds(214748364), tp);
1150 EXPECT_TRUE(
parse(
"%E*S",
"0.2147483648", tz, &tp));
1151 EXPECT_EQ(unix_epoch + chrono::nanoseconds(214748364), tp);
1157 "%E*S",
"0.214748364801234567890123456789012345678901234567890123456789",
1159 EXPECT_EQ(unix_epoch + chrono::nanoseconds(214748364), tp);
1165 for (
int ms = 0; ms < 1000; ms += 111) {
1166 for (
int us = 0; us < 1000; us += 27) {
1167 const int micros = ms * 1000 + us;
1168 for (
int ns = 0; ns < 1000; ns += 9) {
1169 const auto expected = chrono::system_clock::from_time_t(0) +
1170 chrono::nanoseconds(micros * 1000 + ns);
1171 std::ostringstream oss;
1172 oss <<
"0." << std::setfill(
'0') << std::setw(3);
1173 oss << ms << std::setw(3) << us << std::setw(3) << ns;
1174 const std::string input = oss.str();
1175 EXPECT_TRUE(
parse(
"%E*S", input, tz, &tp));
1176 EXPECT_EQ(expected, tp) << input;
1185 chrono::system_clock::from_time_t(0);
1188 auto precisions = {
"*",
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
1189 "8",
"9",
"10",
"11",
"12",
"13",
"14",
"15"};
1190 for (
const std::string&
prec : precisions) {
1191 const std::string fmt =
"%E" +
prec +
"f";
1194 EXPECT_TRUE(
parse(fmt,
"", tz, &tp));
1195 EXPECT_EQ(unix_epoch, tp);
1197 EXPECT_TRUE(
parse(fmt,
"6", tz, &tp));
1198 EXPECT_EQ(unix_epoch + chrono::milliseconds(600), tp);
1200 EXPECT_TRUE(
parse(fmt,
"60", tz, &tp));
1201 EXPECT_EQ(unix_epoch + chrono::milliseconds(600), tp);
1203 EXPECT_TRUE(
parse(fmt,
"600", tz, &tp));
1204 EXPECT_EQ(unix_epoch + chrono::milliseconds(600), tp);
1206 EXPECT_TRUE(
parse(fmt,
"67", tz, &tp));
1207 EXPECT_EQ(unix_epoch + chrono::milliseconds(670), tp);
1209 EXPECT_TRUE(
parse(fmt,
"670", tz, &tp));
1210 EXPECT_EQ(unix_epoch + chrono::milliseconds(670), tp);
1212 EXPECT_TRUE(
parse(fmt,
"678", tz, &tp));
1213 EXPECT_EQ(unix_epoch + chrono::milliseconds(678), tp);
1215 EXPECT_TRUE(
parse(fmt,
"6789", tz, &tp));
1217 unix_epoch + chrono::milliseconds(678) + chrono::microseconds(900), tp);
1224 EXPECT_TRUE(
parse(
"%E*f",
"2147483647", tz, &tp));
1225 EXPECT_EQ(unix_epoch + chrono::nanoseconds(214748364), tp);
1227 EXPECT_TRUE(
parse(
"%E*f",
"2147483648", tz, &tp));
1228 EXPECT_EQ(unix_epoch + chrono::nanoseconds(214748364), tp);
1234 "%E*f",
"214748364801234567890123456789012345678901234567890123456789",
1236 EXPECT_EQ(unix_epoch + chrono::nanoseconds(214748364), tp);
1242 for (
int ms = 0; ms < 1000; ms += 111) {
1243 for (
int us = 0; us < 1000; us += 27) {
1244 const int micros = ms * 1000 + us;
1245 for (
int ns = 0; ns < 1000; ns += 9) {
1246 std::ostringstream oss;
1247 oss << std::setfill(
'0') << std::setw(3) << ms;
1248 oss << std::setw(3) << us << std::setw(3) << ns;
1249 const std::string nanos = oss.str();
1250 const auto expected = chrono::system_clock::from_time_t(0) +
1251 chrono::nanoseconds(micros * 1000 + ns);
1252 for (
int ps = 0; ps < 1000; ps += 250) {
1253 std::ostringstream oss;
1254 oss << std::setfill(
'0') << std::setw(3) << ps;
1255 const std::string input = nanos + oss.str() +
"999";
1256 EXPECT_TRUE(
parse(
"%E*f", input, tz, &tp));
1257 EXPECT_EQ(expected + chrono::nanoseconds(ps) / 1000, tp) << input;
1268 EXPECT_TRUE(
parse(
"%Ez",
"+00:00", utc, &tp));
1270 EXPECT_TRUE(
parse(
"%Ez",
"-12:34", utc, &tp));
1272 EXPECT_TRUE(
parse(
"%Ez",
"+12:34", utc, &tp));
1274 EXPECT_FALSE(
parse(
"%Ez",
"-12:3", utc, &tp));
1276 for (
auto fmt : {
"%Ez",
"%z"}) {
1277 EXPECT_TRUE(
parse(fmt,
"+0000", utc, &tp));
1279 EXPECT_TRUE(
parse(fmt,
"-1234", utc, &tp));
1281 EXPECT_TRUE(
parse(fmt,
"+1234", utc, &tp));
1283 EXPECT_FALSE(
parse(fmt,
"-123", utc, &tp));
1285 EXPECT_TRUE(
parse(fmt,
"+00", utc, &tp));
1287 EXPECT_TRUE(
parse(fmt,
"-12", utc, &tp));
1289 EXPECT_TRUE(
parse(fmt,
"+12", utc, &tp));
1291 EXPECT_FALSE(
parse(fmt,
"-1", utc, &tp));
1299 for (
auto fmt : {
"%Ez",
"%E*z",
"%:z",
"%::z",
"%:::z"}) {
1300 EXPECT_TRUE(
parse(fmt,
"+00:00:00", utc, &tp));
1302 EXPECT_TRUE(
parse(fmt,
"-12:34:56", utc, &tp));
1304 EXPECT_TRUE(
parse(fmt,
"+12:34:56", utc, &tp));
1306 EXPECT_FALSE(
parse(fmt,
"-12:34:5", utc, &tp));
1308 EXPECT_TRUE(
parse(fmt,
"+000000", utc, &tp));
1310 EXPECT_TRUE(
parse(fmt,
"-123456", utc, &tp));
1312 EXPECT_TRUE(
parse(fmt,
"+123456", utc, &tp));
1314 EXPECT_FALSE(
parse(fmt,
"-12345", utc, &tp));
1316 EXPECT_TRUE(
parse(fmt,
"+00:00", utc, &tp));
1318 EXPECT_TRUE(
parse(fmt,
"-12:34", utc, &tp));
1320 EXPECT_TRUE(
parse(fmt,
"+12:34", utc, &tp));
1322 EXPECT_FALSE(
parse(fmt,
"-12:3", utc, &tp));
1324 EXPECT_TRUE(
parse(fmt,
"+0000", utc, &tp));
1326 EXPECT_TRUE(
parse(fmt,
"-1234", utc, &tp));
1328 EXPECT_TRUE(
parse(fmt,
"+1234", utc, &tp));
1330 EXPECT_FALSE(
parse(fmt,
"-123", utc, &tp));
1332 EXPECT_TRUE(
parse(fmt,
"+00", utc, &tp));
1334 EXPECT_TRUE(
parse(fmt,
"-12", utc, &tp));
1336 EXPECT_TRUE(
parse(fmt,
"+12", utc, &tp));
1338 EXPECT_FALSE(
parse(fmt,
"-1", utc, &tp));
1344 const char e4y_fmt[] =
"%E4Y%m%d";
1348 EXPECT_TRUE(
parse(e4y_fmt,
"-9991127", utc, &tp));
1350 EXPECT_TRUE(
parse(e4y_fmt,
"-0991127", utc, &tp));
1352 EXPECT_TRUE(
parse(e4y_fmt,
"-0091127", utc, &tp));
1354 EXPECT_TRUE(
parse(e4y_fmt,
"-0011127", utc, &tp));
1356 EXPECT_TRUE(
parse(e4y_fmt,
"00001127", utc, &tp));
1358 EXPECT_TRUE(
parse(e4y_fmt,
"00011127", utc, &tp));
1360 EXPECT_TRUE(
parse(e4y_fmt,
"00091127", utc, &tp));
1362 EXPECT_TRUE(
parse(e4y_fmt,
"00991127", utc, &tp));
1364 EXPECT_TRUE(
parse(e4y_fmt,
"09991127", utc, &tp));
1366 EXPECT_TRUE(
parse(e4y_fmt,
"99991127", utc, &tp));
1370 EXPECT_FALSE(
parse(e4y_fmt,
"-10001127", utc, &tp));
1371 EXPECT_FALSE(
parse(e4y_fmt,
"100001127", utc, &tp));
1378 ExpectTime(tp, tz, 2014, 2, 12, 20, 21, 0, 0,
false,
"UTC");
1419 EXPECT_FALSE(
parse(
RFC3339_sec,
"9223372036854775807-12-31T23:59:59-00:01",
1421 EXPECT_FALSE(
parse(
RFC3339_sec,
"-9223372036854775808-01-01T00:00:00+00:01",
1437 const auto subseconds = chrono::nanoseconds(654321);
1444 EXPECT_EQ(
in + subseconds, out);
1455 #if defined(_WIN32) || defined(_WIN64) 1458 #elif defined(__EMSCRIPTEN__) 1468 const std::string s =
format(
"%c",
in, utc);
1469 EXPECT_TRUE(
parse(
"%c", s, utc, &out)) << s;
1475 TEST(FormatParse, RoundTripDistantFuture) {
1484 TEST(FormatParse, RoundTripDistantPast) {
const char RFC1123_no_wday[]
bool Parse(FlagMarshallingOpFn op, absl::string_view text, void *dst, std::string *error)
time_zone fixed_time_zone(const seconds &offset)
const char RFC3339_full[]
std::chrono::duration< std::int_fast64_t, std::femto > femtoseconds
std::string format(const std::string &fmt, const time_point< D > &tp, const time_zone &tz)
bool parse(const std::string &fmt, const std::string &input, const time_zone &tz, time_point< D > *tpp)
std::chrono::duration< std::int_fast64_t > seconds
std::string format(const std::string &, const time_point< seconds > &, const femtoseconds &, const time_zone &)
bool parse(const std::string &, const std::string &, const time_zone &, time_point< seconds > *, femtoseconds *, std::string *err=nullptr)
std::chrono::time_point< std::chrono::system_clock, D > time_point
const char RFC1123_full[]
bool Format(FormatRawSink raw_sink, const FormatSpec< Args... > &format, const Args &...args)
time_zone utc_time_zone()
TEST(CivilTime, DefaultConstruction)
bool load_time_zone(const std::string &name, time_zone *tz)
civil_second convert(const time_point< D > &tp, const time_zone &tz)
detail::civil_second civil_second