From 19e9ab253e54c4bd0d6ebeb050ffc69ae162c821 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Fri, 30 Jan 2026 01:24:48 -0600 Subject: [PATCH] cleanup --- esphome/components/time/real_time_clock.cpp | 14 ++++++++++++++ esphome/components/time/real_time_clock.h | 14 +------------- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/esphome/components/time/real_time_clock.cpp b/esphome/components/time/real_time_clock.cpp index 439436420f..029c0c9995 100644 --- a/esphome/components/time/real_time_clock.cpp +++ b/esphome/components/time/real_time_clock.cpp @@ -23,6 +23,20 @@ static const char *const TAG = "time"; RealTimeClock::RealTimeClock() = default; +ESPTime __attribute__((noinline)) RealTimeClock::now() { +#ifdef USE_TIME_TIMEZONE + time_t epoch = this->timestamp_now(); + struct tm local_tm; + if (epoch_to_local_tm(epoch, get_global_tz(), &local_tm)) { + return ESPTime::from_c_tm(&local_tm, epoch); + } + // Fallback to UTC if parsing failed + return ESPTime::from_epoch_utc(epoch); +#else + return ESPTime::from_epoch_local(this->timestamp_now()); +#endif +} + void RealTimeClock::dump_config() { #ifdef USE_TIME_TIMEZONE const auto &tz = get_global_tz(); diff --git a/esphome/components/time/real_time_clock.h b/esphome/components/time/real_time_clock.h index 9312d075df..720fe593c8 100644 --- a/esphome/components/time/real_time_clock.h +++ b/esphome/components/time/real_time_clock.h @@ -47,19 +47,7 @@ class RealTimeClock : public PollingComponent { #endif /// Get the time in the currently defined timezone. - ESPTime now() { -#ifdef USE_TIME_TIMEZONE - time_t epoch = this->timestamp_now(); - struct tm local_tm; - if (epoch_to_local_tm(epoch, get_global_tz(), &local_tm)) { - return ESPTime::from_c_tm(&local_tm, epoch); - } - // Fallback to UTC if parsing failed - return ESPTime::from_epoch_utc(epoch); -#else - return ESPTime::from_epoch_local(this->timestamp_now()); -#endif - } + ESPTime now(); /// Get the time without any time zone or DST corrections. ESPTime utcnow() { return ESPTime::from_epoch_utc(this->timestamp_now()); }