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
This commit is contained in:
David Woodhouse
2025-12-11 17:45:48 +09:00
parent edc320fef8
commit cfdb5a82e2
3 changed files with 10 additions and 1 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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],
)
)