Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Timezone file to POSIX timezone string

Tags:

c

timezone

linux

We have an embedded Linux system where the user can set a timezone from the system's tzfile list (so names of countries/places, GMT+-n, UTC) or the timezone / $TZ can be directly set in POSIX format (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 timezone names).

Whichever entity set the timezone last (be it human or remote server) we need to report the local timezone setting back to the remote server in POSIX format, preferably with minimal lying / fudging.

Before I roll up my sleeves, don my pointy hat, and start down the road of parsing the tzfile format by hand I thought it worth asking if there is a pre-existing function / library or example of doing this?

I've trawled through the standard libraries and can't see anything that does this specifically.

like image 204
John U Avatar asked Dec 09 '14 19:12

John U


1 Answers

The tzfile ends with the timezone POSIX format. I don't know if there's a standard library function for it, but all you have to look for is a newline followed by a string and another newline at the end of the file. The string in between is the timezone in POSIX format.

like image 159
Emanuel P Avatar answered Sep 20 '22 14:09

Emanuel P