mirror of
https://github.com/esphome/esphome.git
synced 2026-02-20 08:25:35 -07:00
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:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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],
|
||||
)
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user