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:

  1. download latest tzdata
  2. build it with zone info compiler (or just zic)
  3. process these files remembering path ("tz name")
  4. for each file, get the last line - it will be the TZ string
  5. 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:

See the Pen Angular.js - Typeahead by Pavel Gurenko (@pgurenko) on CodePen.

Comments

Popular posts from this blog

DXGI fast screen capture

Kubuntu 16.04 and Dell Inspiron 7559

Visual Studio Code: Fixing Python Intellisense