From 77ebfc86875957eece4929e4a6007cc17b0c7ea3 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Thu, 29 Jan 2026 23:34:59 -0600 Subject: [PATCH] aioesphomeapi and esphome both always have M format, it was overkill --- esphome/components/time/real_time_clock.cpp | 1 + tests/components/time/posix_tz_parser.cpp | 84 --------------------- 2 files changed, 1 insertion(+), 84 deletions(-) diff --git a/esphome/components/time/real_time_clock.cpp b/esphome/components/time/real_time_clock.cpp index 9dc00abfa5..09b242d040 100644 --- a/esphome/components/time/real_time_clock.cpp +++ b/esphome/components/time/real_time_clock.cpp @@ -30,6 +30,7 @@ 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; + // Always use M format - tzdata and aioesphomeapi only generate M format rules 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, diff --git a/tests/components/time/posix_tz_parser.cpp b/tests/components/time/posix_tz_parser.cpp index 5311edbf27..1a84a39835 100644 --- a/tests/components/time/posix_tz_parser.cpp +++ b/tests/components/time/posix_tz_parser.cpp @@ -831,90 +831,6 @@ INSTANTIATE_TEST_SUITE_P(AustraliaSydney, LibcVerificationTest, std::make_tuple("AEST-10AEDT,M10.1.0,M4.1.0/3", 1720000000), std::make_tuple("AEST-10AEDT,M10.1.0,M4.1.0/3", 1735689600))); -// ============================================================================ -// format_dst_rule tests -// ============================================================================ - -TEST(PosixTzParser, FormatDstRuleMonthWeekDay) { - DSTRule rule{}; - rule.type = DSTRuleType::MONTH_WEEK_DAY; - rule.month = 3; - rule.week = 2; - rule.day_of_week = 0; - rule.time_seconds = 2 * 3600; // 2:00 - - char buf[internal::DST_RULE_BUF_SIZE]; - size_t len = internal::format_dst_rule(rule, buf); - EXPECT_STREQ(buf, "M3.2.0/2"); - EXPECT_EQ(len, 8u); -} - -TEST(PosixTzParser, FormatDstRuleJulian) { - DSTRule rule{}; - rule.type = DSTRuleType::JULIAN_NO_LEAP; - rule.day = 60; - rule.time_seconds = 2 * 3600; - - char buf[internal::DST_RULE_BUF_SIZE]; - size_t len = internal::format_dst_rule(rule, buf); - EXPECT_STREQ(buf, "J60/2"); - EXPECT_EQ(len, 5u); -} - -TEST(PosixTzParser, FormatDstRuleDayOfYear) { - DSTRule rule{}; - rule.type = DSTRuleType::DAY_OF_YEAR; - rule.day = 300; - rule.time_seconds = 2 * 3600; - - char buf[internal::DST_RULE_BUF_SIZE]; - size_t len = internal::format_dst_rule(rule, buf); - EXPECT_STREQ(buf, "300/2"); - EXPECT_EQ(len, 5u); -} - -TEST(PosixTzParser, FormatDstRuleWithMinutes) { - DSTRule rule{}; - rule.type = DSTRuleType::MONTH_WEEK_DAY; - rule.month = 11; - rule.week = 1; - rule.day_of_week = 0; - rule.time_seconds = 2 * 3600 + 30 * 60; // 2:30 - - char buf[internal::DST_RULE_BUF_SIZE]; - size_t len = internal::format_dst_rule(rule, buf); - EXPECT_STREQ(buf, "M11.1.0/2:30"); - EXPECT_EQ(len, 12u); -} - -TEST(PosixTzParser, FormatDstRuleWithSeconds) { - DSTRule rule{}; - rule.type = DSTRuleType::MONTH_WEEK_DAY; - rule.month = 3; - rule.week = 5; - rule.day_of_week = 0; - rule.time_seconds = 2 * 3600 + 30 * 60 + 45; // 2:30:45 - - char buf[internal::DST_RULE_BUF_SIZE]; - size_t len = internal::format_dst_rule(rule, buf); - EXPECT_STREQ(buf, "M3.5.0/2:30:45"); - EXPECT_EQ(len, 14u); -} - -TEST(PosixTzParser, FormatDstRuleNegativeTime) { - DSTRule rule{}; - rule.type = DSTRuleType::MONTH_WEEK_DAY; - rule.month = 3; - rule.week = 2; - rule.day_of_week = 0; - rule.time_seconds = -1 * 3600; // -1:00 (11 PM previous day) - - char buf[internal::DST_RULE_BUF_SIZE]; - size_t len = internal::format_dst_rule(rule, buf); - EXPECT_STREQ(buf, "M3.2.0-1"); - EXPECT_EQ(len, 8u); -} - // ============================================================================ // DST boundary edge cases // ============================================================================