fix(time): apply timezone before lcd startup

This commit is contained in:
chenjintao
2026-08-25 09:55:39 +08:00
parent ceb0780425
commit f33ad70c16
7 changed files with 57 additions and 5 deletions
@@ -23,11 +23,27 @@ static const char *TAG = "platform_time";
static bool s_sntp_started;
static portMUX_TYPE s_time_lock = portMUX_INITIALIZER_UNLOCKED;
esp_err_t platform_time_set_timezone(const char *posix_tz)
{
if (posix_tz == NULL || posix_tz[0] == '\0') {
return ESP_ERR_INVALID_ARG;
}
if (setenv("TZ", posix_tz, 1) != 0) {
ESP_LOGE(TAG, "Set time zone failed (tz=%s)", posix_tz);
return ESP_FAIL;
}
tzset();
ESP_LOGI(TAG, "Local time zone applied (tz=%s)", posix_tz);
return ESP_OK;
}
esp_err_t platform_time_sync_start(const char *sntp_server, const char *posix_tz)
{
if (posix_tz != NULL && posix_tz[0] != '\0') {
setenv("TZ", posix_tz, 1);
tzset();
esp_err_t timezone_err = platform_time_set_timezone(posix_tz);
if (timezone_err != ESP_OK) {
return timezone_err;
}
}
portENTER_CRITICAL(&s_time_lock);