RTC setenv TZ incorrect time

Posts: 14
Joined: Thu Mar 05, 2020 7:35 am

RTC setenv TZ incorrect time

Postby Ismael » Tue Jun 30, 2020 4:24 pm


I'm trying to update time zones dynamically via a custom protocol: Epotch time + zone.

From a server database, we convert user timezone in POSIX standard reference as it is mentioned in: https://github.com/nayarsystems/posix_t ... /zones.csv

As a example we are using our own timezone: Europe/Madrid so for this case, we can use a UTC value of 1593532800 and zone variable as "CET-1CEST,M3.5.0,M10.5.0/3"

That means (from https://www.epochconverter.com/ converter):
GMT: Tuesday, 30 June 2020 16:00:00
Your time zone: Tuesday, 30 of June of 2020 18:00:00 GMT+02:00 DST
The problem is when we try to update local time + time zone difference, the sequence we use is:

Code: Select all

time_t seconds = 1593532800;
struct tm epoch_time;

memset(&epoch_time, 0, sizeof(struct tm));
gmtime_r(&seconds, &epoch_time);

rtc_time_print_tm("Time write: ", &epoch_time);

// Set timezone
setenv("TZ", "CET-1CEST,M3.5.0,M10.5.0/3", 1);

// Set time (inside a custom function with this instructions)
struct timeval tv;
memset(&tv, 0, sizeof(struct timeval));
tv.tv_sec = mktime(time_now);
settimeofday(&tv, NULL);

Function 'rtc_time_print_tm' just call strftime and print its result.

To print system time we use:

Code: Select all

time_t now;
struct tm timeinfo;
memset(&now, 0, sizeof(time_t));
memset(&timeinfo, 0, sizeof(struct tm));


localtime_r(&now, &timeinfo);
return strftime(buf, buf_max, RTC_TIME_ASCII_FORMAT, &timeinfo);
After this code is executed, the time outputs is:

Code: Select all

I (18128) RTC: Time without time zone change: 30/06/2020 16:00:00
I (18128) RTC: Time with time zone change: 30/06/2020 17:00:00
The last date is not correct, it must be "30/06/2020 18:00:00"

Are we doing something wrong? is there any issue about setenv("TZ", timezone, 1)?

Thanks so much.

We have the Espressif development fixed in this commit:
commit 6f9a7264ce20c6132fbd8309112630d0eb490fe4 (HEAD)
Merge: cc34d5a5b 72fb22ed5
Author: Jiang Jiang Jian <jack@espressif.com>
Date: Fri Mar 6 11:34:11 2020 +0800

Who is online

Users browsing this forum: Bing [Bot] and 62 guests