From cfdb5a82e2d85e64953737c7d7b8c7e3fef50472 Mon Sep 17 00:00:00 2001 From: David Woodhouse Date: Thu, 11 Dec 2025 17:45:48 +0900 Subject: [PATCH] Replace __DATE__/__TIME__ with buildinfo functions - Add get_build_time_string() function to format build time consistently - Replace __DATE__ ", " __TIME__ in App.pre_setup() with buildinfo call - Eliminates dependency on compiler-provided date/time macros - Ensures consistent build time across all build information displays --- esphome/core/buildinfo.cpp | 8 ++++++++ esphome/core/buildinfo.h | 1 + esphome/core/config.py | 2 +- 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/esphome/core/buildinfo.cpp b/esphome/core/buildinfo.cpp index d17bf01124..4726f789a1 100644 --- a/esphome/core/buildinfo.cpp +++ b/esphome/core/buildinfo.cpp @@ -34,5 +34,13 @@ const char *get_config_hash() { time_t get_build_time() { return (time_t) build_time; } +const char *get_build_time_string() { + static char time_str[32]; + time_t bt = get_build_time(); + struct tm *tm_info = localtime(&bt); + strftime(time_str, sizeof(time_str), "%b %d %Y, %H:%M:%S", tm_info); + return time_str; +} + } // namespace buildinfo } // namespace esphome diff --git a/esphome/core/buildinfo.h b/esphome/core/buildinfo.h index cc4656f4dc..664b7985dd 100644 --- a/esphome/core/buildinfo.h +++ b/esphome/core/buildinfo.h @@ -13,6 +13,7 @@ namespace buildinfo { const char *get_config_hash(); time_t get_build_time(); +const char *get_build_time_string(); } // namespace buildinfo } // namespace esphome diff --git a/esphome/core/config.py b/esphome/core/config.py index 3adaf7eb9e..f7a5305144 100644 --- a/esphome/core/config.py +++ b/esphome/core/config.py @@ -501,7 +501,7 @@ async def to_code(config: ConfigType) -> None: config[CONF_NAME], config[CONF_FRIENDLY_NAME], config.get(CONF_COMMENT, ""), - cg.RawExpression('__DATE__ ", " __TIME__'), + cg.RawExpression("esphome::buildinfo::get_build_time_string()"), config[CONF_NAME_ADD_MAC_SUFFIX], ) )