From 899f2bbac530d93aa8c2ecc213bcdd70f27e0798 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Thu, 29 Jan 2026 23:34:49 -0600 Subject: [PATCH] aioesphomeapi and esphome both always have M format, it was overkill --- esphome/components/time/posix_tz.cpp | 35 --------------------- esphome/components/time/posix_tz.h | 10 ------ esphome/components/time/real_time_clock.cpp | 9 +++--- 3 files changed, 5 insertions(+), 49 deletions(-) diff --git a/esphome/components/time/posix_tz.cpp b/esphome/components/time/posix_tz.cpp index ab1d07811b..d400cce454 100644 --- a/esphome/components/time/posix_tz.cpp +++ b/esphome/components/time/posix_tz.cpp @@ -342,41 +342,6 @@ bool __attribute__((noinline)) is_in_dst(time_t utc_epoch, const ParsedTimezone } } -size_t format_dst_rule(const DSTRule &rule, std::span buf) { - // Format rule part - int pos = 0; - switch (rule.type) { - case DSTRuleType::MONTH_WEEK_DAY: - pos = snprintf(buf.data(), buf.size(), "M%d.%d.%d", rule.month, rule.week, rule.day_of_week); - break; - case DSTRuleType::JULIAN_NO_LEAP: - pos = snprintf(buf.data(), buf.size(), "J%d", rule.day); - break; - case DSTRuleType::DAY_OF_YEAR: - pos = snprintf(buf.data(), buf.size(), "%d", rule.day); - break; - } - - // Format time part - int32_t time_secs = rule.time_seconds; - char sign = time_secs < 0 ? '-' : '/'; - if (time_secs < 0) - time_secs = -time_secs; - int hours = time_secs / 3600; - int mins = (time_secs % 3600) / 60; - int secs = time_secs % 60; - - if (secs != 0) { - pos += snprintf(buf.data() + pos, buf.size() - pos, "%c%d:%02d:%02d", sign, hours, mins, secs); - } else if (mins != 0) { - pos += snprintf(buf.data() + pos, buf.size() - pos, "%c%d:%02d", sign, hours, mins); - } else { - pos += snprintf(buf.data() + pos, buf.size() - pos, "%c%d", sign, hours); - } - - return static_cast(pos); -} - } // namespace internal bool parse_posix_tz(const char *tz_string, ParsedTimezone &result) { diff --git a/esphome/components/time/posix_tz.h b/esphome/components/time/posix_tz.h index e994d53fda..ea9864b304 100644 --- a/esphome/components/time/posix_tz.h +++ b/esphome/components/time/posix_tz.h @@ -2,7 +2,6 @@ #include #include -#include namespace esphome::time { @@ -113,15 +112,6 @@ time_t calculate_dst_transition(int year, const DSTRule &rule, int32_t base_offs /// @return true if DST is in effect at the given time bool is_in_dst(time_t utc_epoch, const ParsedTimezone &tz); -/// Buffer size for format_dst_rule output -static constexpr size_t DST_RULE_BUF_SIZE = 24; - -/// Format a DST rule for logging/display -/// @param rule The DST rule to format -/// @param buf Output buffer -/// @return Number of characters written (excluding null terminator) -size_t format_dst_rule(const DSTRule &rule, std::span buf); - } // namespace internal } // namespace esphome::time diff --git a/esphome/components/time/real_time_clock.cpp b/esphome/components/time/real_time_clock.cpp index 025d613a0d..9dc00abfa5 100644 --- a/esphome/components/time/real_time_clock.cpp +++ b/esphome/components/time/real_time_clock.cpp @@ -30,10 +30,11 @@ void RealTimeClock::dump_config() { ESP_LOGCONFIG(TAG, "Timezone: UTC%+d:%02d", std_hours, std_mins); if (this->parsed_tz_.has_dst) { int dst_hours = -this->parsed_tz_.dst_offset_seconds / 3600; - char start_buf[internal::DST_RULE_BUF_SIZE], end_buf[internal::DST_RULE_BUF_SIZE]; - internal::format_dst_rule(this->parsed_tz_.dst_start, start_buf); - internal::format_dst_rule(this->parsed_tz_.dst_end, end_buf); - ESP_LOGCONFIG(TAG, " DST: UTC%+d, %s - %s", dst_hours, start_buf, end_buf); + ESP_LOGCONFIG(TAG, " DST: UTC%+d, M%d.%d.%d/%" PRId32 " - M%d.%d.%d/%" PRId32, dst_hours, + this->parsed_tz_.dst_start.month, this->parsed_tz_.dst_start.week, + this->parsed_tz_.dst_start.day_of_week, this->parsed_tz_.dst_start.time_seconds / 3600, + this->parsed_tz_.dst_end.month, this->parsed_tz_.dst_end.week, this->parsed_tz_.dst_end.day_of_week, + this->parsed_tz_.dst_end.time_seconds / 3600); } #endif auto time = this->now();