From bf8f3d7076416fe128f853a8632c96cca84b29d4 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Thu, 15 Jan 2026 13:21:59 -1000 Subject: [PATCH] better handle 2038 --- esphome/components/time/real_time_clock.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/esphome/components/time/real_time_clock.cpp b/esphome/components/time/real_time_clock.cpp index cec9711dfb..1d0695466b 100644 --- a/esphome/components/time/real_time_clock.cpp +++ b/esphome/components/time/real_time_clock.cpp @@ -35,7 +35,8 @@ void RealTimeClock::synchronize_epoch_(uint32_t epoch) { // and prevent clock jumping backwards due to network latency auto current = this->utcnow(); if (current.is_valid()) { - int32_t diff = static_cast(epoch) - static_cast(current.timestamp); + // Unsigned subtraction handles wraparound correctly, then cast to signed + int32_t diff = static_cast(epoch - current.timestamp); if (diff >= -1 && diff <= 1) { return; }