fix(time): apply timezone before lcd startup
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user