Page 1 of 1

getLocalTime(&local); Definitions of time zones

Posted: Thu Apr 05, 2018 11:33 am
by rin67630
Hi

I have a sample ESP32 sketch (Arduino ISP) using

Code: Select all

GetLocalTime(&local);
It uses a definition string for timezones for which I cound not find any documentation:

#define TZ_INFO "MST7MDT6,M3.2.0/02:00:00,M11.1.0/02:00:00" // Americas/Denver

I googled my fingers wound, without success.

What is the valid string for Western Europe?

Thank you

Re: getLocalTime(&local); Definitions of time zones

Posted: Thu Apr 05, 2018 2:31 pm
by rin67630
I finally found it:
W. Europe Standard Time: "WEST-1DWEST-2,M3.5.0/02:00:00,M10.5.0/03:00:00"

https://www.di-mgt.com.au/wclock/tz-syntax.txt
[img]
https://www.cjoint.com/doc/18_04/HDfoEL ... String.jpg
[/img]

Re: getLocalTime(&local); Definitions of time zones

Posted: Thu Apr 05, 2018 3:56 pm
by WiFive

Re: getLocalTime(&local); Definitions of time zones

Posted: Thu Apr 05, 2018 8:04 pm
by rin67630
Exactly that was not useful to find the solution.
It was not a matter of defining the time zones, but which syntax to use.

Re: getLocalTime(&local); Definitions of time zones

Posted: Thu Apr 05, 2018 9:41 pm
by meowsqueak
rin67630 wrote:
Exactly that was not useful to find the solution.
It was not a matter of defining the time zones, but which syntax to use.
I had the same problem - usually with most environments I'd use TZ="Pacific/Auckland" or sometimes ":Pacific/Auckland", which is what most timezone searches would reveal. But neither of those work here. Somewhere, after an hour of digging, I found I had to use "NZST-12NZDT,M9.5.0,M4.1.0/3". Not exactly obvious but at least it's explicit about daylight savings.

Also, to use UTC, you need to use "UTC0", or gmtime/gmtime_r().

Note that there's a fairly well known memory leak in setenv() which means that if you change timezones repeatedly, which you might do for an application that handles multiple time zones, you'll eventually run out of memory. I'm not sure if the environment is shared between tasks - if not, it might be better to have separate tasks for each timezone. If it is shared, then I'm not sure what the best way to deal with this is. In my case I worked out the difference between the two timezones and used that to calculate the second time.

Re: getLocalTime(&local); Definitions of time zones

Posted: Fri May 22, 2020 8:16 am
by waterfox
Are there any updates to this?
I've also searched how to set up the tz variable. But I only found a few examples.

Is there any possible to set the time with the IANA time zone database?

Re: getLocalTime(&local); Definitions of time zones

Posted: Fri May 22, 2020 9:44 am
by markkuk
The official reference for the TZ setting syntax is in the Single Unix Specification (a.k.a. POSIX) standard: https://pubs.opengroup.org/onlinepubs/9 ... tml#tag_08. See also the GNU libc documentation: https://www.gnu.org/software/libc/manua ... iable.html

Re: getLocalTime(&local); Definitions of time zones

Posted: Tue Jun 09, 2020 5:26 am
by Monteggiack
markkuk wrote: ↑
Fri May 22, 2020 9:44 am
The official reference for the TZ setting syntax is in the Single Unix Specification (a.k.a. POSIX) standard: https://pubs.opengroup.org/onlinepubs/9 ... tml#tag_08. See also the GNU libc documentation: https://www.gnu.org/software/libc/manua ... iable.html
Love it thank for the valuable information…