From f317f58545493f7421557befa349061a5eecc5e3 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Fri, 30 Jan 2026 01:09:06 -0600 Subject: [PATCH] cleanups --- esphome/components/time/posix_tz.cpp | 2 +- esphome/components/time/posix_tz.h | 7 +++++-- esphome/core/time.cpp | 2 +- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/esphome/components/time/posix_tz.cpp b/esphome/components/time/posix_tz.cpp index e57d3b3a2f9..06140599a96 100644 --- a/esphome/components/time/posix_tz.cpp +++ b/esphome/components/time/posix_tz.cpp @@ -336,7 +336,7 @@ time_t __attribute__((noinline)) calculate_dst_transition(int year, const DSTRul } // namespace internal bool __attribute__((noinline)) is_in_dst(time_t utc_epoch, const ParsedTimezone &tz) { - if (!tz.has_dst) { + if (!tz.has_dst()) { return false; } diff --git a/esphome/components/time/posix_tz.h b/esphome/components/time/posix_tz.h index 6dbb09296e5..5446ddb9df6 100644 --- a/esphome/components/time/posix_tz.h +++ b/esphome/components/time/posix_tz.h @@ -9,6 +9,7 @@ namespace esphome::time { /// Type of DST transition rule enum class DSTRuleType : uint8_t { + NONE = 0, ///< No DST rule (used to indicate no DST) MONTH_WEEK_DAY, ///< M format: Mm.w.d (e.g., M3.2.0 = 2nd Sunday of March) JULIAN_NO_LEAP, ///< J format: Jn (day 1-365, Feb 29 not counted) DAY_OF_YEAR, ///< Plain number: n (day 0-365, Feb 29 counted in leap years) @@ -24,13 +25,15 @@ struct DSTRule { uint8_t day_of_week; ///< Day 0-6, 0 = Sunday (for MONTH_WEEK_DAY) }; -/// Parsed POSIX timezone information +/// Parsed POSIX timezone information (packed for 32-bit: 32 bytes) struct ParsedTimezone { int32_t std_offset_seconds; ///< Standard time offset from UTC in seconds (positive = west) int32_t dst_offset_seconds; ///< DST offset from UTC in seconds DSTRule dst_start; ///< When DST starts DSTRule dst_end; ///< When DST ends - bool has_dst; ///< Whether this timezone has DST + + /// Check if this timezone has DST rules + bool has_dst() const { return this->dst_start.type != DSTRuleType::NONE; } }; /// Parse a POSIX TZ string into a ParsedTimezone struct. diff --git a/esphome/core/time.cpp b/esphome/core/time.cpp index b1db0814467..b2f1493e2cd 100644 --- a/esphome/core/time.cpp +++ b/esphome/core/time.cpp @@ -268,7 +268,7 @@ void ESPTime::recalc_timestamp_local() { // POSIX: local = utc - offset, so utc = local + offset const auto &tz = time::get_global_tz(); - if (!tz.has_dst) { + if (!tz.has_dst()) { // No DST - just apply standard offset this->timestamp += tz.std_offset_seconds; return;