[resolved] what do you use for timezone management?

User avatar
mzimmers
Posts: 643
Joined: Wed Mar 07, 2018 11:54 pm
Location: USA

[resolved] what do you use for timezone management?

Postby mzimmers » Tue Jun 05, 2018 10:57 pm

Hi all -

Today I began working with maintaining wall time on the ESP32. Connecting to an NTP server was a breeze, but now I'm faced with the prospect of managing time zone settings. Various Google efforts haven't turned up much, so I figured I'd ask what other people use for this.

I'm specifically interested in two things:

1. is there an facility for easing the construction of strings like "PST8PDT,M3.2.0/2,M11.1.0" for time zone management?
2. does FreeRTOS have the ability to manage DST automatically? (If it doesn't, perhaps question 1 is moot.)

Thanks...
Last edited by mzimmers on Thu Jun 11, 2020 3:25 pm, edited 1 time in total.

markwj
Posts: 90
Joined: Tue Mar 08, 2016 5:03 am

Re: what do you use for timezone management?

Postby markwj » Wed Jun 06, 2018 1:41 am

We're having the same issue. Unable to find a simple library to convert something like USA/NewYork to posix timezone strings. It seems that bigger systems use the tzdata and full library, but that is too large for ESP32. Could probably parse the tzdata files to extract what we need, and wrap it in a library, but can't understand why this problem isn't solved (or the solution isn't easy to find).

ESP_igrr
Posts: 2071
Joined: Tue Dec 01, 2015 8:37 am

Re: what do you use for timezone management?

Postby ESP_igrr » Wed Jun 06, 2018 5:51 am

You can take the standard tzdata database, then use something like https://github.com/nayarsystems/posix_tz_db to convert timezone rules into glibc TZ format.
Depending on the product market, filter out the locations/rules which you don't need.
Load the remaining rules (i.e. "location","TZ rule" pairs) into the firmware, either embedding the file directly into the app binary, or into some file system partition.
Let the user choose the location in device configuration UI, if one exists. Save TZ for chosen location into NVS.
Load TZ from NVS on startup and call setenv/tzset to apply the rule.

> does FreeRTOS have the ability to manage DST automatically? (If it doesn't, perhaps question 1 is moot.)

FreeRTOS doesn't, but then FreeRTOS does not deal with time at all (aside from maintaining a 32-bit unsigned tick counter). TZ strings include information about DST rules, and newlib will apply DST correction according to these rules.

jdlambert
Posts: 1
Joined: Fri Mar 20, 2020 4:02 pm

Re: what do you use for timezone management?

Postby jdlambert » Fri Mar 20, 2020 4:51 pm

You can take the standard tzdata database, then use something like https://github.com/nayarsystems/posix_tz_db to convert timezone rules into glibc TZ format.
I've forked this repository and made a minimal embedded-friendly library based on it. You could find it at https://github.com/jdlambert/posix_tz_db/tree/embedded.

Who is online

Users browsing this forum: No registered users and 78 guests