@@ -224,106 +224,9 @@ TEST(xchar_test, chrono) {
224224 EXPECT_EQ (L" 42s" , fmt::format (L" {}" , std::chrono::seconds (42 )));
225225 EXPECT_EQ (fmt::format (L" {:%F}" , tm), L" 2016-04-25" );
226226 EXPECT_EQ (fmt::format (L" {:%T}" , tm), L" 11:22:33" );
227- }
228-
229- std::wstring system_wcsftime (const std::wstring& format, const std::tm* timeptr,
230- std::locale* locptr = nullptr ) {
231- auto loc = locptr ? *locptr : std::locale::classic ();
232- auto & facet = std::use_facet<std::time_put<wchar_t >>(loc);
233- std::wostringstream os;
234- os.imbue (loc);
235- facet.put (os, os, L' ' , timeptr, format.c_str (),
236- format.c_str () + format.size ());
237- #ifdef _WIN32
238- // Workaround a bug in older versions of Universal CRT.
239- auto str = os.str ();
240- if (str == L" -0000" ) str = L" +0000" ;
241- return str;
242- #else
243- return os.str ();
244- #endif
245- }
246-
247- TEST (chrono_test_wchar, time_point) {
248- auto t1 = std::chrono::time_point_cast<std::chrono::seconds>(
249- std::chrono::system_clock::now ());
250-
251- std::vector<std::wstring> spec_list = {
252- L" %%" , L" %n" , L" %t" , L" %Y" , L" %EY" , L" %y" , L" %Oy" , L" %Ey" , L" %C" ,
253- L" %EC" , L" %G" , L" %g" , L" %b" , L" %h" , L" %B" , L" %m" , L" %Om" , L" %U" ,
254- L" %OU" , L" %W" , L" %OW" , L" %V" , L" %OV" , L" %j" , L" %d" , L" %Od" , L" %e" ,
255- L" %Oe" , L" %a" , L" %A" , L" %w" , L" %Ow" , L" %u" , L" %Ou" , L" %H" , L" %OH" ,
256- L" %I" , L" %OI" , L" %M" , L" %OM" , L" %S" , L" %OS" , L" %x" , L" %Ex" , L" %X" ,
257- L" %EX" , L" %D" , L" %F" , L" %R" , L" %T" , L" %p" };
258- #ifndef _WIN32
259- // Disabled on Windows, because these formats is not consistent among
260- // platforms.
261- spec_list.insert (spec_list.end (), {L" %c" , L" %Ec" , L" %r" });
262- #elif !FMT_HAS_C99_STRFTIME
263- // Only C89 conversion specifiers when using MSVCRT instead of UCRT
264- spec_list = {L" %%" , L" %Y" , L" %y" , L" %b" , L" %B" , L" %m" , L" %U" ,
265- L" %W" , L" %j" , L" %d" , L" %a" , L" %A" , L" %w" , L" %H" ,
266- L" %I" , L" %M" , L" %S" , L" %x" , L" %X" , L" %p" };
267- #endif
268- spec_list.push_back (L" %Y-%m-%d %H:%M:%S" );
269227
270- for (const auto & spec : spec_list) {
271- auto t = std::chrono::system_clock::to_time_t (t1);
272- auto tm = *std::gmtime (&t);
273-
274- auto sys_output = system_wcsftime (spec, &tm);
275-
276- auto fmt_spec = fmt::format (L" {{:{}}}" , spec);
277- EXPECT_EQ (sys_output, fmt::format (fmt::runtime (fmt_spec), t1));
278- EXPECT_EQ (sys_output, fmt::format (fmt::runtime (fmt_spec), tm));
279- }
280-
281- // Timezone formatters tests makes sense for localtime.
282- #if FMT_HAS_C99_STRFTIME
283- spec_list = {L" %z" , L" %Z" };
284- #else
285- spec_list = {L" %Z" };
286- #endif
287- for (const auto & spec : spec_list) {
288- auto t = std::chrono::system_clock::to_time_t (t1);
289- auto tm = *std::localtime (&t);
290-
291- auto sys_output = system_wcsftime (spec, &tm);
292-
293- auto fmt_spec = fmt::format (L" {{:{}}}" , spec);
294- EXPECT_EQ (sys_output, fmt::format (fmt::runtime (fmt_spec), tm));
295-
296- if (spec == L" %z" ) {
297- sys_output.insert (sys_output.end () - 2 , 1 , L' :' );
298- EXPECT_EQ (sys_output, fmt::format (L" {:%Ez}" , tm));
299- EXPECT_EQ (sys_output, fmt::format (L" {:%Oz}" , tm));
300- }
301- }
302-
303- // Separate tests for UTC, since std::time_put can use local time and ignoring
304- // the timezone in std::tm (if it presents on platform).
305- if (fmt::detail::has_member_data_tm_zone<std::tm>::value) {
306- auto t = std::chrono::system_clock::to_time_t (t1);
307- auto tm = *std::gmtime (&t);
308-
309- std::vector<std::wstring> tz_names = {L" GMT" , L" UTC" };
310- EXPECT_THAT (tz_names, Contains (fmt::format (L" {:%Z}" , t1)));
311- EXPECT_THAT (tz_names, Contains (fmt::format (L" {:%Z}" , tm)));
312- }
313-
314- if (fmt::detail::has_member_data_tm_gmtoff<std::tm>::value) {
315- auto t = std::chrono::system_clock::to_time_t (t1);
316- auto tm = *std::gmtime (&t);
317-
318- EXPECT_EQ (L" +0000" , fmt::format (L" {:%z}" , t1));
319- EXPECT_EQ (L" +0000" , fmt::format (L" {:%z}" , tm));
320-
321- EXPECT_EQ (L" +00:00" , fmt::format (L" {:%Ez}" , t1));
322- EXPECT_EQ (L" +00:00" , fmt::format (L" {:%Ez}" , tm));
323-
324- EXPECT_EQ (L" +00:00" , fmt::format (L" {:%Oz}" , t1));
325- EXPECT_EQ (L" +00:00" , fmt::format (L" {:%Oz}" , tm));
326- }
228+ auto t = fmt::sys_time<std::chrono::seconds>(std::chrono::seconds (290088000 ));
229+ EXPECT_EQ (fmt::format (" {:%Y-%m-%d %H:%M:%S}" , t), " 1979-03-12 12:00:00" );
327230}
328231
329232TEST (xchar_test, color) {
0 commit comments