[time] Fix settimeofday() failure on ESP8266 (#14707)

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
J. Nick Koston
2026-03-12 07:15:34 -10:00
committed by GitHub
parent 03c091adfc
commit fd1d016795
+6 -6
View File
@@ -88,16 +88,16 @@ void RealTimeClock::synchronize_epoch_(uint32_t epoch) {
struct timeval timev { struct timeval timev {
.tv_sec = static_cast<time_t>(epoch), .tv_usec = 0, .tv_sec = static_cast<time_t>(epoch), .tv_usec = 0,
}; };
#ifdef USE_ESP8266
// ESP8266 settimeofday() requires tz to be nullptr
int ret = settimeofday(&timev, nullptr);
#else
struct timezone tz = {0, 0}; struct timezone tz = {0, 0};
int ret = settimeofday(&timev, &tz); int ret = settimeofday(&timev, &tz);
if (ret != 0 && errno == EINVAL) { #endif
// Some ESP8266 frameworks abort when timezone parameter is not NULL
// while ESP32 expects it not to be NULL
ret = settimeofday(&timev, nullptr);
}
if (ret != 0) { if (ret != 0) {
ESP_LOGW(TAG, "setimeofday() failed with code %d", ret); ESP_LOGW(TAG, "settimeofday() failed with code %d", ret);
} }
#endif #endif
auto time = this->now(); auto time = this->now();