Skip to content

Commit cb6c343

Browse files
committed
Fix local_time test
1 parent 7ac97cb commit cb6c343

File tree

1 file changed

+2
-10
lines changed

1 file changed

+2
-10
lines changed

test/chrono-test.cc

+2-10
Original file line numberDiff line numberDiff line change
@@ -375,16 +375,12 @@ TEST(chrono_test, local_time) {
375375
#endif
376376
specs.push_back("%Y-%m-%d %H:%M:%S");
377377

378-
#if FMT_USE_LOCAL_TIME
379378
# ifdef _WIN32
380379
return; // Not supported on Windows.
381380
# endif
382381

383382
for (const auto& spec : specs) {
384-
auto sys_time = std::chrono::system_clock::to_time_t(
385-
std::chrono::current_zone()->to_sys(t));
386-
auto tm = *std::localtime(&sys_time);
387-
383+
auto tm = fmt::gmtime(t.time_since_epoch().count());
388384
auto sys_output = system_strftime(spec, &tm);
389385

390386
auto fmt_spec = fmt::format("{{:{}}}", spec);
@@ -393,10 +389,7 @@ TEST(chrono_test, local_time) {
393389
}
394390

395391
if (std::find(specs.cbegin(), specs.cend(), "%z") != specs.cend()) {
396-
auto sys_time = std::chrono::system_clock::to_time_t(
397-
std::chrono::current_zone()->to_sys(t));
398-
auto tm = *std::localtime(&sys_time);
399-
392+
auto tm = fmt::gmtime(t.time_since_epoch().count());
400393
auto sys_output = system_strftime("%z", &tm);
401394
sys_output.insert(sys_output.end() - 2, 1, ':');
402395

@@ -406,7 +399,6 @@ TEST(chrono_test, local_time) {
406399
EXPECT_EQ(sys_output, fmt::format("{:%Oz}", t));
407400
EXPECT_EQ(sys_output, fmt::format("{:%Oz}", tm));
408401
}
409-
#endif // FMT_USE_LOCAL_TIME
410402
}
411403

412404
TEST(chrono_test, daylight_savings_time_end) {

0 commit comments

Comments
 (0)