From aab35a2126ffe8fa46c90d008521389bb7313d58 Mon Sep 17 00:00:00 2001 From: Marius Vikhammer Date: Wed, 24 May 2023 16:13:34 +0800 Subject: [PATCH] core-system/newlib: updated docs to reflect that tzset() needs to be called before localtime/mktime() According to the posix standard localtime/mktime should use timezone information as though localtime/mktime() calls tzset(), but this is not the case in older versions of Newlib. Closes https://github.com/espressif/esp-idf/issues/11455 --- docs/en/api-reference/system/system_time.rst | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docs/en/api-reference/system/system_time.rst b/docs/en/api-reference/system/system_time.rst index 79cb561811..2fcf81e765 100644 --- a/docs/en/api-reference/system/system_time.rst +++ b/docs/en/api-reference/system/system_time.rst @@ -75,6 +75,9 @@ If you need to obtain time with one second resolution, use the following method: time(&now); // Set timezone to China Standard Time setenv("TZ", "CST-8", 1); + + /* According to the posix standard localtime/mktime should use timezone information as though localtime/mktime() calls tzset(), + but this is not the case in older versions of Newlib. We manually call tzset to ensure the timezone info is updated*/ tzset(); localtime_r(&now, &timeinfo);