fix firmware install date (was using UTC as TZ not initialised)

This commit is contained in:
proddy
2026-04-19 14:17:31 +02:00
parent 51cea8e757
commit b0db054e11
3 changed files with 32 additions and 18 deletions

View File

@@ -407,11 +407,11 @@ void System::get_partition_info() {
partition_info_.clear(); // clear existing data
#ifdef EMSESP_STANDALONE
// dummy data for standalone mode - version, size, install_date
partition_info_["app0"] = {EMSESP_APP_VERSION, 0, ""};
partition_info_["app1"] = {"", 0, ""};
partition_info_["factory"] = {"", 0, ""};
partition_info_["boot"] = {"", 0, ""};
// dummy data for standalone mode - version, size, install_date in UTC epoch
partition_info_["app0"] = {EMSESP_APP_VERSION, 0, 0};
partition_info_["app1"] = {"", 0, 0};
partition_info_["factory"] = {"", 0, 0};
partition_info_["boot"] = {"", 0, 0};
#else
auto current_partition = (const char *)esp_ota_get_running_partition()->label;
@@ -451,10 +451,8 @@ void System::get_partition_info() {
p_info.version = EMSESP::nvs_.getString(part->label, "").c_str();
char c[20];
snprintf(c, sizeof(c), "d_%s", (const char *)part->label);
time_t d = EMSESP::nvs_.getULong(c, 0);
char time_string[25];
strftime(time_string, sizeof(time_string), "%FT%T", localtime(&d));
p_info.install_date = d > 1500000000L ? time_string : "";
time_t d = EMSESP::nvs_.getULong(c, 0);
p_info.install_date = d > 1500000000L ? d : 0; // store UTC epoch; formatted to local time at render
if (!p_info.version.empty()) {
esp_image_metadata_t meta = {};
@@ -474,7 +472,7 @@ void System::get_partition_info() {
#endif
}
// set NTP install time/date for the current partition
// set install time/date for the current partition, in UTC
// assumes NTP is connected and working
void System::set_partition_install_date() {
#ifndef EMSESP_STANDALONE
@@ -1337,11 +1335,18 @@ void System::show_system(uuid::console::Shell & shell) {
if (partition.second.version.empty()) {
continue; // no version, empty string
}
std::string installed;
if (partition.second.install_date > 0) {
char time_string[25];
time_t d = partition.second.install_date;
strftime(time_string, sizeof(time_string), "%FT%T", localtime(&d));
installed = std::string(", installed on ") + time_string;
}
shell.printfln(" %s: v%s (%d KB%s) %s",
partition.first.c_str(),
partition.second.version.c_str(),
partition.second.size,
partition.second.install_date.empty() ? "" : (std::string(", installed on ") + partition.second.install_date).c_str(),
installed.c_str(),
(strcmp(esp_ota_get_running_partition()->label, partition.first.c_str()) == 0) ? "** active **" : "");
}