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.
This commit is contained in:
Guillaume Maudoux 2019-10-04 10:54:36 +02:00
parent 0571013709
commit a04bae9733

View File

@ -47,6 +47,7 @@ inline std::tm localtime(std::time_t time) {
dispatcher(std::time_t t) : time_(t) {} dispatcher(std::time_t t) : time_(t) {}
bool run() { bool run() {
tzset();
using namespace fmt::internal; using namespace fmt::internal;
return handle(localtime_r(&time_, &tm_)); return handle(localtime_r(&time_, &tm_));
} }