@@ -353,36 +353,71 @@ 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 " );
356+
357357 EXPECT_EQ (fmt::format (" {}" , time), " 1979-03-12 12:00:00" );
358358 EXPECT_EQ (fmt::format (" {:}" , time), " 1979-03-12 12:00:00" );
359359
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));
360+ constexpr struct {
361+ const char * format;
362+ const char * output;
363+ } data[] = {{" {:%%}" , " %" },
364+ {" {:%n}" , " \n " },
365+ {" {:%t}" , " \t " },
366+ {" {:%Y}" , " 1979" },
367+ {" {:%EY}" , " 1979" },
368+ {" {:%y}" , " 79" },
369+ {" {:%Oy}" , " 79" },
370+ {" {:%Ey}" , " 79" },
371+ {" {:%C}" , " 19" },
372+ {" {:%EC}" , " 19" },
373+ {" {:%G}" , " 1979" },
374+ {" {:%g}" , " 79" },
375+ {" {:%b}" , " Mar" },
376+ {" {:%h}" , " Mar" },
377+ {" {:%B}" , " March" },
378+ {" {:%m}" , " 03" },
379+ {" {:%Om}" , " 03" },
380+ {" {:%U}" , " 10" },
381+ {" {:%OU}" , " 10" },
382+ {" {:%W}" , " 11" },
383+ {" {:%OW}" , " 11" },
384+ {" {:%V}" , " 11" },
385+ {" {:%OV}" , " 11" },
386+ {" {:%j}" , " 071" },
387+ {" {:%d}" , " 12" },
388+ {" {:%Od}" , " 12" },
389+ {" {:%e}" , " 12" },
390+ {" {:%Oe}" , " 12" },
391+ {" {:%a}" , " Mon" },
392+ {" {:%A}" , " Monday" },
393+ {" {:%w}" , " 1" },
394+ {" {:%Ow}" , " 1" },
395+ {" {:%u}" , " 1" },
396+ {" {:%Ou}" , " 1" },
397+ {" {:%H}" , " 12" },
398+ {" {:%OH}" , " 12" },
399+ {" {:%I}" , " 12" },
400+ {" {:%OI}" , " 12" },
401+ {" {:%M}" , " 00" },
402+ {" {:%OM}" , " 00" },
403+ {" {:%S}" , " 00" },
404+ {" {:%OS}" , " 00" },
405+ {" {:%x}" , " 03/12/79" },
406+ {" {:%Ex}" , " 03/12/79" },
407+ {" {:%X}" , " 12:00:00" },
408+ {" {:%EX}" , " 12:00:00" },
409+ {" {:%D}" , " 03/12/79" },
410+ {" {:%F}" , " 1979-03-12" },
411+ {" {:%R}" , " 12:00" },
412+ {" {:%T}" , " 12:00:00" },
413+ {" {:%p}" , " PM" },
414+ {" {:%c}" , " Mon Mar 12 12:00:00 1979" },
415+ {" {:%Ec}" , " Mon Mar 12 12:00:00 1979" },
416+ {" {:%r}" , " 12:00:00 PM" },
417+ {" {:%Y-%m-%d %H:%M:%S}" , " 1979-03-12 12:00:00" }};
418+
419+ for (auto d : data) {
420+ EXPECT_EQ (fmt::format (d.format , time), d.output );
386421 }
387422
388423 EXPECT_THROW_MSG ((void )fmt::format (fmt::runtime (" {:%z}" ), time),
0 commit comments