POSIX timezone line file

We have an embedded Linux system in which the user can set the time zone from the tzfile system list (so that the names of countries / places, GMT + -n, UTC) or the time zone / $ TZ can be directly set to POSIX (EG CET-01:00:00CEST-02:00:00,M3.5.0/02:00:00,M10.5.0/03:00:00 or EST5EDT ) by a remote server (which does not know the name of the time zones).

Regardless of which object binds the last time zone (whether human or remote server), we need to report the local time zone to the remote server in POSIX format, preferably with a minimum false / fudging.

Before folding up my sleeves, putting on my pointy hat and starting with how I manually looked at the tzfile format, I thought it was worth asking if there is already an existing function / library or an example of this?

I made my way through the standard libraries and see nothing that does this on purpose.

+5
source share
1 answer

In the "tzfile" section, you refer to the IANA tz database time zones - as a rule, computer time zones are set these days. For example, America/Los_Angeles or Europe/London .

These time zones are much richer than possible with the POSIX time zones - because they contain the history of time in this place. POSIX timelines can only store current time zone rules, so they cannot accurately represent time in the real world, where time zone rules often change.

See also the section on POSIX time zones in the time zone wiki .

However, if you should use POSIX time zones, you can look at the date_time module in Boost . Boost has its own IANA time zone data file . This is described in the "Time Zone Database" section of the documents . After loading the zone, you can use to_posix_string to get the value you are looking for.

For instance:

 tz_database tz_db; tz_db.load_from_file("./date_time_zonespec.csv"); time_zone_ptr nyc = tz_db.time_zone_from_region("America/New_York"); nyc->to_posix_string(); // "EST-05EDT+01,M4.1.0/02:00,M10.5.0/02:00" 

Keep in mind that the IANA time zone database is updated about a dozen or so once a year, and it seems that Boost has not updated its csv file since April 2011. I'm not sure what their process is for saving the file - but I would have guessed that it was broken.

+5
source

Source: https://habr.com/ru/post/1208683/


All Articles