From bec7d6d223c48be4e35e5ac90eb55fbf7fe09c12 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Thu, 29 Jan 2026 22:31:23 -0600 Subject: [PATCH] tweak --- esphome/components/time/posix_tz.cpp | 14 ++++++++------ tests/components/time/posix_tz_parser.cpp | 18 ++++++++++++++++++ 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/esphome/components/time/posix_tz.cpp b/esphome/components/time/posix_tz.cpp index 7a122b474a..f91c168811 100644 --- a/esphome/components/time/posix_tz.cpp +++ b/esphome/components/time/posix_tz.cpp @@ -370,18 +370,20 @@ bool parse_posix_tz(const char *tz_string, ParsedTimezone &result) { result.dst_offset_seconds = result.std_offset_seconds - 3600; } - // Parse DST rules if present + // Parse DST rules if present (POSIX requires both start and end if any rules specified) if (*p == ',') { p++; if (!internal::parse_dst_rule(p, result.dst_start)) { return false; } - if (*p == ',') { - p++; - if (!internal::parse_dst_rule(p, result.dst_end)) { - return false; - } + // Second rule is required per POSIX + if (*p != ',') { + return false; + } + p++; + if (!internal::parse_dst_rule(p, result.dst_end)) { + return false; } } diff --git a/tests/components/time/posix_tz_parser.cpp b/tests/components/time/posix_tz_parser.cpp index 38f8640ec9..7badaa37f0 100644 --- a/tests/components/time/posix_tz_parser.cpp +++ b/tests/components/time/posix_tz_parser.cpp @@ -361,6 +361,24 @@ TEST(PosixTzParser, MFormatInvalidDayOfWeek7) { EXPECT_FALSE(parse_posix_tz("EST5EDT,M3.2.7,M11.1.0", tz)); } +TEST(PosixTzParser, MissingEndRule) { + ParsedTimezone tz; + // POSIX requires both start and end rules if any rules are specified + EXPECT_FALSE(parse_posix_tz("EST5EDT,M3.2.0", tz)); +} + +TEST(PosixTzParser, MissingEndRuleJFormat) { + ParsedTimezone tz; + // POSIX requires both start and end rules if any rules are specified + EXPECT_FALSE(parse_posix_tz("EST5EDT,J60", tz)); +} + +TEST(PosixTzParser, MissingEndRulePlainDay) { + ParsedTimezone tz; + // POSIX requires both start and end rules if any rules are specified + EXPECT_FALSE(parse_posix_tz("EST5EDT,60", tz)); +} + // ============================================================================ // Large offset tests // ============================================================================