store UTC epoch time and convert to localtime when render (fixes bug as TZ not set)

This commit is contained in:
proddy
2026-04-19 15:12:22 +02:00
parent a1e0288e09
commit 6b68cb7c61
14 changed files with 53 additions and 39 deletions

View File

@@ -288,11 +288,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;
@@ -332,10 +332,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 = {};
@@ -355,7 +353,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
@@ -1240,11 +1238,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 **" : "");
}

View File

@@ -83,7 +83,7 @@ enum FUSE_VALUE : uint8_t { ALL = 0, MFG = 1, MODEL = 2, BOARD = 3, REV = 4, BAT
struct PartitionInfo {
std::string version;
size_t size;
std::string install_date; // optional, only available if NTP is connected
time_t install_date; // UTC epoch seconds; 0 if unknown. Format with localtime() at render time so it honors the current TZ.
};
class System {