Get the timezone posix string from GPS coordinates
The software of some microcontrollers follows the POSIX standard of local time setting. This means that you must set the environment variable “TZ” with setenv and then call tzset in time library.
tzposix.c is a CGI to convert geographic location (lat, long) into the necessary POSIX string for the TZ environment variable. It returns a json containing the timezone Olson and POSIX version given certain GPS coordinates. Once compiled and downloaded in the cgi-bin directory of your web server it is invoked as follows:
https://yourserver/cgi-bin/tzposix?lat=[float]&lon=[float]
https://sotech.es/cgi-bin/tzposix?lat=40.4165000&lon=-3.7025600
returns the following JSON:
{"olson": "Europe/Madrid", "posix": "CET-1CEST,M3.5.0,M10.5.0/3"}
Source code is inspired by the work of Bertold Van den Bergh. Contains instructions for the generation of the timezone geographic databases (timezone16.bin y timezone21.bin) en Database Generation.
Timezone Boundary Builder is the basis for generating the databases. You can also find software for several languages (C, Javascript, Python, PHP, etc).
File tzinfo.json contains the correspondence table between the Olson format and the POSIX format. Instructions for creating it are in tzinfo.
Each time the TimeZone DataBase is changed, files timezone16.bin o timezone21.bin as well as tzinfo.json must be updated. You can subscribe to the mailing list where updates are announced.