This commit is contained in:
J. Nick Koston
2026-01-30 01:03:42 -06:00
parent 9628c213b5
commit 9b8556c2b2
2 changed files with 7 additions and 8 deletions
+1 -8
View File
@@ -1,8 +1,5 @@
#if defined(USE_HOST)
#include "logger.h"
#ifdef USE_TIME_TIMEZONE
#include "esphome/components/time/posix_tz.h"
#endif
namespace esphome::logger {
@@ -14,11 +11,7 @@ void HOT Logger::write_msg_(const char *msg, size_t len) {
time_t rawtime;
::time(&rawtime);
struct tm timeinfo;
#ifdef USE_TIME_TIMEZONE
time::epoch_to_local_tm(rawtime, time::get_global_tz(), &timeinfo);
#else
localtime_r(&rawtime, &timeinfo); // Thread-safe version
#endif
localtime_r(&rawtime, &timeinfo); // TZ env var set by time component
size_t pos = strftime(buffer, TIMESTAMP_LEN + 1, "[%H:%M:%S]", &timeinfo);
// Copy message (with newline already included by caller)
@@ -104,6 +104,12 @@ void RealTimeClock::apply_timezone_(const char *tz) {
return;
}
#ifdef USE_HOST
// On host platform, also set TZ environment variable for libc compatibility
setenv("TZ", tz, 1);
tzset();
#endif
// Parse the POSIX TZ string using our custom parser
if (!parse_posix_tz(tz, parsed)) {
ESP_LOGW(TAG, "Failed to parse timezone: %s", tz);