From 960c80b202293c6b36377afffc872b35fae6fd82 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sat, 25 Oct 2025 11:21:22 -0700 Subject: [PATCH] [core] Simplify ESPTime::strftime() and save 20 bytes flash --- esphome/core/time.h | 26 ++++---------------------- 1 file changed, 4 insertions(+), 22 deletions(-) diff --git a/esphome/core/time.h b/esphome/core/time.h index 0d47ce820b..13a0127156 100644 --- a/esphome/core/time.h +++ b/esphome/core/time.h @@ -44,32 +44,14 @@ struct ESPTime { size_t strftime(char *buffer, size_t buffer_len, const char *format); /** Convert this ESPTime struct to a string as specified by the format argument. - * @see https://www.gnu.org/software/libc/manual/html_node/Formatting-Calendar-Time.html#index-strftime + * @see https://en.cppreference.com/w/c/chrono/strftime * - * @warning This method uses dynamically allocated strings which can cause heap fragmentation with some - * microcontrollers. - * - * @warning This method can return "ERROR" when the underlying strftime() call fails, e.g. when the - * format string contains unsupported specifiers or when the format string doesn't produce any - * output. + * @warning This method can return "ERROR" when the underlying strftime() call fails or when the + * output exceeds 128 bytes. */ std::string strftime(const std::string &format); - /** Convert this ESPTime struct to a string as specified by the format argument. - * @see https://www.gnu.org/software/libc/manual/html_node/Formatting-Calendar-Time.html#index-strftime - * - * This overload is optimized for string literals and avoids std::string parameter overhead. - * - * @param format The format string (null-terminated C string) - * @param format_len Optional length of the format string. If 0 (default), strlen() will be called. - * - * @warning This method uses dynamically allocated strings which can cause heap fragmentation with some - * microcontrollers. - * - * @warning This method can return "ERROR" when the underlying strftime() call fails, e.g. when the - * format string contains unsupported specifiers or when the format string doesn't produce any - * output. - */ + /// @copydoc strftime(const std::string &format) std::string strftime(const char *format, size_t format_len = 0); /// Check if this ESPTime is valid (all fields in range and year is greater than 2018)