Getting POSIX TZ strings from Olson tzdata
Problem at hand: we are having IOT device which does not have the IANA/Olson tzdata package but we would like users to be able to select their time zones from the list, but not enter the TZ string in form of PST8PDT...
After a lot of searching, I could not discover the way of obtaining any sort of the TZ string database which would work for most of the cases. The closest I got was the momentjs JSON data generated from the old good Olson tzdata but, alas, it was still missing the simple TZ strings.
Now it was pretty much evident that solution should still somehow include the Olson database but I did not know how.
Final step had come up when I actually have taken a look at the tzinfo file format and discovered that in the current version (v2), the TZ string lies right in the end of each file, conveniently separated by the new line symbols at start and in the end!
So the final solution for now is:
After a lot of searching, I could not discover the way of obtaining any sort of the TZ string database which would work for most of the cases. The closest I got was the momentjs JSON data generated from the old good Olson tzdata but, alas, it was still missing the simple TZ strings.
Now it was pretty much evident that solution should still somehow include the Olson database but I did not know how.
Final step had come up when I actually have taken a look at the tzinfo file format and discovered that in the current version (v2), the TZ string lies right in the end of each file, conveniently separated by the new line symbols at start and in the end!
So the final solution for now is:
- download latest tzdata
- build it with zone info compiler (or just zic)
- process these files remembering path ("tz name")
- for each file, get the last line - it will be the TZ string
- put the final result in json
The source code (in Python) of the utility doing all that is already on GitHub, as usual.
Solved!
Update: implemented simple typeahead-based timezone selector - see below:
Update: implemented simple typeahead-based timezone selector - see below:
Comments
Post a Comment