Search code examples
cparsingtimezoneposixvalidation

Is there a function to parse a POSIX timezone and validate it?


I have timezones in the format of

NZST-12.00:00NZDT-13:00:00,M10.1.0,M3.3.0

or

CET-1CEST,M3.5.0,M10.5.0/3

is there a function or library to parse and validate them in C?


Solution

  • Yes, because code like the C library does so. So, there are at least three open sources for such code:

    1. GNU C Library
    2. *BSD C Library
    3. Olson Time Zone Database

    Nowadays, the Olson code can be found at IANA under https://www.iana.org/time-zones as tzcode2017a.tar.gz and as tzdata2017a.tar.gz for the data (or via FTP at ftp://ftp.iana.org/tz/releases/tzcode2017a.tar.gz — and the data as ftp://ftp.iana.org/tz/releases/tzdata2017a.tar.gz).

    Once upon a long time ago, the code used to be at ftp://elsie.nci.nih.gov/pub — for example, in the file tzcode2011h.tar.gz (the time zone information is in tzdata2011h.tar.gz). These old releases are available from IANA too if desired.

    The version number in the file names changes periodically; the prefix stays the same, but the year (2011 vs 2017) and the release (h vs a — and there were many releases in each year in between 2011 and 2017) within the year varies over time.