@@ -353,36 +353,70 @@ TEST(chrono_test, system_clock_time_point) {
353353TEST (chrono_test, local_time) {
354354 auto time =
355355 fmt::local_time<std::chrono::seconds>(std::chrono::seconds (290088000 ));
356- EXPECT_EQ (fmt::format (" {:%Y-%m-%d %H:%M:%S}" , time), " 1979-03-12 12:00:00" );
357- EXPECT_EQ (fmt::format (" {}" , time), " 1979-03-12 12:00:00" );
358- EXPECT_EQ (fmt::format (" {:}" , time), " 1979-03-12 12:00:00" );
359356
360- std::vector<std::string> specs = {
361- " %%" , " %n" , " %t" , " %Y" , " %EY" , " %y" , " %Oy" , " %Ey" , " %C" ,
362- " %EC" , " %G" , " %g" , " %b" , " %h" , " %B" , " %m" , " %Om" , " %U" ,
363- " %OU" , " %W" , " %OW" , " %V" , " %OV" , " %j" , " %d" , " %Od" , " %e" ,
364- " %Oe" , " %a" , " %A" , " %w" , " %Ow" , " %u" , " %Ou" , " %H" , " %OH" ,
365- " %I" , " %OI" , " %M" , " %OM" , " %S" , " %OS" , " %x" , " %Ex" , " %X" ,
366- " %EX" , " %D" , " %F" , " %R" , " %T" , " %p" };
367- #ifndef _WIN32
368- // Disabled on Windows because these formats are not consistent among
369- // platforms.
370- specs.insert (specs.end (), {" %c" , " %Ec" , " %r" });
371- #elif !FMT_HAS_C99_STRFTIME
372- // Only C89 conversion specifiers when using MSVCRT instead of UCRT
373- specs = {" %%" , " %Y" , " %y" , " %b" , " %B" , " %m" , " %U" , " %W" , " %j" , " %d" , " %a" ,
374- " %A" , " %w" , " %H" , " %I" , " %M" , " %S" , " %x" , " %X" , " %p" };
375- #endif
376- specs.push_back (" %Y-%m-%d %H:%M:%S" );
377-
378- for (const auto & spec : specs) {
379- auto tm = fmt::gmtime (time.time_since_epoch ().count ());
380- auto sys_output = system_strftime (spec, &tm);
381-
382- auto fmt_spec = fmt::format (" {{:{}}}" , spec);
383- EXPECT_EQ (sys_output, fmt::format (fmt::runtime (fmt_spec), time))
384- << fmt_spec;
385- EXPECT_EQ (sys_output, fmt::format (fmt::runtime (fmt_spec), tm));
357+ constexpr struct {
358+ const char * format;
359+ const char * output;
360+ } data[] = {{" {}" , " 1979-03-12 12:00:00" },
361+ {" {:}" , " 1979-03-12 12:00:00" },
362+ {" {:%%}" , " %" },
363+ {" {:%n}" , " \n " },
364+ {" {:%t}" , " \t " },
365+ {" {:%Y}" , " 1979" },
366+ {" {:%EY}" , " 1979" },
367+ {" {:%y}" , " 79" },
368+ {" {:%Oy}" , " 79" },
369+ {" {:%Ey}" , " 79" },
370+ {" {:%C}" , " 19" },
371+ {" {:%EC}" , " 19" },
372+ {" {:%G}" , " 1979" },
373+ {" {:%g}" , " 79" },
374+ {" {:%b}" , " Mar" },
375+ {" {:%h}" , " Mar" },
376+ {" {:%B}" , " March" },
377+ {" {:%m}" , " 03" },
378+ {" {:%Om}" , " 03" },
379+ {" {:%U}" , " 10" },
380+ {" {:%OU}" , " 10" },
381+ {" {:%W}" , " 11" },
382+ {" {:%OW}" , " 11" },
383+ {" {:%V}" , " 11" },
384+ {" {:%OV}" , " 11" },
385+ {" {:%j}" , " 071" },
386+ {" {:%d}" , " 12" },
387+ {" {:%Od}" , " 12" },
388+ {" {:%e}" , " 12" },
389+ {" {:%Oe}" , " 12" },
390+ {" {:%a}" , " Mon" },
391+ {" {:%A}" , " Monday" },
392+ {" {:%w}" , " 1" },
393+ {" {:%Ow}" , " 1" },
394+ {" {:%u}" , " 1" },
395+ {" {:%Ou}" , " 1" },
396+ {" {:%H}" , " 12" },
397+ {" {:%OH}" , " 12" },
398+ {" {:%I}" , " 12" },
399+ {" {:%OI}" , " 12" },
400+ {" {:%M}" , " 00" },
401+ {" {:%OM}" , " 00" },
402+ {" {:%S}" , " 00" },
403+ {" {:%OS}" , " 00" },
404+ {" {:%x}" , " 03/12/79" },
405+ {" {:%Ex}" , " 03/12/79" },
406+ {" {:%X}" , " 12:00:00" },
407+ {" {:%EX}" , " 12:00:00" },
408+ {" {:%D}" , " 03/12/79" },
409+ {" {:%F}" , " 1979-03-12" },
410+ {" {:%R}" , " 12:00" },
411+ {" {:%T}" , " 12:00:00" },
412+ {" {:%p}" , " PM" },
413+ {" {:%c}" , " Mon Mar 12 12:00:00 1979" },
414+ {" {:%Ec}" , " Mon Mar 12 12:00:00 1979" },
415+ {" {:%r}" , " 12:00:00 PM" },
416+ {" {:%Y-%m-%d %H:%M:%S}" , " 1979-03-12 12:00:00" }};
417+
418+ for (auto d : data) {
419+ EXPECT_EQ (fmt::format (d.format , time), d.output );
386420 }
387421
388422 EXPECT_THROW_MSG ((void )fmt::format (fmt::runtime (" {:%z}" ), time),
0 commit comments