[time] Add `USE_TIME_TIMEZONE` define (#9290)

This commit is contained in:
Jesse Hills
2025-07-02 08:51:25 -05:00
committed by GitHub
parent 289aedcfe2
commit 9b3ece4caf
4 changed files with 25 additions and 2 deletions
@@ -35,8 +35,10 @@ void RealTimeClock::synchronize_epoch_(uint32_t epoch) {
ret = settimeofday(&timev, nullptr);
}
#ifdef USE_TIME_TIMEZONE
// Move timezone back to local timezone.
this->apply_timezone_();
#endif
if (ret != 0) {
ESP_LOGW(TAG, "setimeofday() failed with code %d", ret);
@@ -49,10 +51,12 @@ void RealTimeClock::synchronize_epoch_(uint32_t epoch) {
this->time_sync_callback_.call();
}
#ifdef USE_TIME_TIMEZONE
void RealTimeClock::apply_timezone_() {
setenv("TZ", this->timezone_.c_str(), 1);
tzset();
}
#endif
} // namespace time
} // namespace esphome