From a5267e6bfe305a7f4f01998cbd3d5a6ff3c74ae9 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Thu, 15 Jan 2026 13:48:12 -1000 Subject: [PATCH] tweak --- esphome/components/time/real_time_clock.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/esphome/components/time/real_time_clock.cpp b/esphome/components/time/real_time_clock.cpp index 1d0695466b..de1ae21514 100644 --- a/esphome/components/time/real_time_clock.cpp +++ b/esphome/components/time/real_time_clock.cpp @@ -33,10 +33,12 @@ void RealTimeClock::synchronize_epoch_(uint32_t epoch) { ESP_LOGVV(TAG, "Got epoch %" PRIu32, epoch); // Skip if time is already synchronized to avoid unnecessary writes, log spam, // and prevent clock jumping backwards due to network latency - auto current = this->utcnow(); - if (current.is_valid()) { + constexpr time_t MIN_VALID_EPOCH = 1546300800; // January 1, 2019 + time_t current_time = this->timestamp_now(); + // Check if time is valid (year >= 2019) before comparing + if (current_time >= MIN_VALID_EPOCH) { // Unsigned subtraction handles wraparound correctly, then cast to signed - int32_t diff = static_cast(epoch - current.timestamp); + int32_t diff = static_cast(epoch - static_cast(current_time)); if (diff >= -1 && diff <= 1) { return; }