[tz] Getting current tzdb version in use

Howard Hinnant howard.hinnant at gmail.com
Thu Jul 19 15:39:20 UTC 2018


On Jul 19, 2018, at 10:51 AM, Paul Eggert <eggert at cs.ucla.edu> wrote:
> 
> Martin Burnicki wrote:
>> So the*implementation*  of this feature in the lib would also be easier
>> if tzdb provided a standard way to get the version.
> 
> /usr/share/zoneinfo/tzdata.zi contains a "# version" line. Though this is reasonably recent in tzdb, and many distributions don't install that file, and it's not part of the stable API.
> 
> I have my doubts about the version info. Many distributions apply local changes to their tzdb data, and I expect that they're not updating the version line appropriately. So all you have is some sort of vague good-faith attempt at version info; it doesn't guarantee that you have a particular tzdb release. That is, the version info is not something that a portable program should rely on; all it's really good for is as a string that the program can report to the user so that the user can try to debug whatever goes wrong.

One of the big use cases I foresee is comparing your current version with the “remote” (or new) version.  A very-long-running application such as an airline reservation system can do this to see if it needs to update the tzdb.  For this use case, the only requirement on the version string is that it keep changing with each new version of the database.

    // a singly linked list of tzdb
    std::chrono::tzdb_list& get_tzdb_list();

    // the front of the list
    const std::chrono::tzdb& get_tzdb();

    // The latest tzdb version, which may have been updated since application start
    std::string remote_version();

    // Your application’s current version
    get_tzdb().version

    // Updates your application’s current tzdb if get_tzdb().version != remote_version()
    const std::chrono::tzdb& reload_tzdb();

https://en.cppreference.com/w/cpp/chrono/tzdb_functions

If every version == “unknown”, this strategy will spectacularly fail, and subsequently the std::lib vendor may as well.

Howard

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: Message signed with OpenPGP
URL: <http://mm.icann.org/pipermail/tz/attachments/20180719/b56a67dd/signature-0001.asc>


More information about the tz mailing list