Search code examples
c++boostposixboost-date-time

Converting from Olson time zone to Posix time zone


Is there a way in C/C++ to convert from Olson time zone format to POSIX time zone format.

Example: for Auckland
Olson time zone format: TZ="Pacific/Auckland"
Posix time zone format: TZ="NZST-12:00:00NZDT-13:00:00,M10.1.0,M3.3.0"

Solution

  • In general it is not possible because the POSIX time zone format only allows for zero or two UTC offset changes per year, and does not allow for different rules for different years. The IANA (Olson) data base is more flexible than that.

    If you allow for multiple Posix time zones and a start/end for when that Posix time zone is valid, it is almost possible, but not easy.

    I've been working on a tool to do this, and needed to make an extension to the Posix time zone format to allow for "permanent DST". This is done by allowing the string to begin with an offset, making the initial standard abbreviation optional, and allowing the rule set (everything beginning with ,) also be optional. Example:

    "EST5" yields a constant offset of -5h with 0h save and "EST abbreviation.
    "5EDT" yields a constant offset of -4h with 1h save and "EDT" abbreviation.
    

    Even with these extensions, I'm not positive it is possible to capture a complete IANA time zone with Posix time zones. This tool is still under development.

    Here is what I current have for Pacific/Auckland (it is unchecked):

    Pacific/Auckland
    *
    LMT-11:39:04
    1868-11-01 12:20:56
    NZMT-11:30
    1927-11-05 14:30:00
    NZMT-11:30NZST,M11.1.0,M3.1.0
    1928-10-13 14:30:00
    NZMT-11:30NZST-12,M10.2.0,M3.3.0
    1933-10-07 14:30:00
    NZMT-11:30NZST-12,M10.2.0,M4.5.0
    1934-09-29 14:30:00
    NZMT-11:30NZST-12,M9.5.0,M4.5.0
    1940-09-28 14:30:00
    -11:30NZST-12
    1945-12-31 12:00:00
    NZST-12
    1974-11-02 14:00:00
    NZST-12NZDT,M11.1.0,M2.5.0/3
    1975-10-25 14:00:00
    NZST-12NZDT,M10.5.0,M3.1.0/3
    1989-10-07 14:00:00
    NZST-12NZDT,M10.2.0,M3.3.0/3
    1990-10-06 14:00:00
    NZST-12NZDT,M10.1.0,M3.3.0/3
    2007-09-29 14:00:00
    NZST-12NZDT,M9.5.0,M4.1.0/3
    *
    

    The time stamps are implicitly UTC. The first * indicates the beginning of time, and the last * indicates the end of time. Those are open to interpretation of the client reading this transformed database.