From a04bae9733c9de930c91df4c0b0f69d94ec8a78e Mon Sep 17 00:00:00 2001 From: Guillaume Maudoux Date: Fri, 4 Oct 2019 10:54:36 +0200 Subject: [PATCH] Make localtime() aware of timezone changes According to POSIX.1-2004, localtime() is required to behave as though tzset(3) was called, while localtime_r() does not have this requirement. For portable code tzset(3) should be called before localtime_r(). See https://stackoverflow.com/questions/19170721/real-time-awareness-of-timezone-change-in-localtime-vs-localtime-r#answer-19170798 for more. --- include/fmt/chrono.h | 1 + 1 file changed, 1 insertion(+) diff --git a/include/fmt/chrono.h b/include/fmt/chrono.h index e0fd21b1..be8fd1bc 100644 --- a/include/fmt/chrono.h +++ b/include/fmt/chrono.h @@ -47,6 +47,7 @@ inline std::tm localtime(std::time_t time) { dispatcher(std::time_t t) : time_(t) {} bool run() { + tzset(); using namespace fmt::internal; return handle(localtime_r(&time_, &tm_)); }