[tz] Proper (stable) way to list installed time zones?

Paul Eggert eggert at cs.ucla.edu
Thu May 14 02:13:37 UTC 2020


On 5/13/20 11:19 AM, Paul Ganssle wrote:

> The problem I'm running into is that tzcode installs `posix/` and
> `right/` folders, so for each entry in zoneinfo, I get three entries:
> "Africa/Abidjan", "posix/Africa/Abidjan" and "right/Africa/Abidjan". I'm
> also seeing a `posixrules` zone in the zoneinfo root.

The posix/* entries are duplicates are the main ones, and the right/* entries
are with leap seconds (which aren't normally used). The posixrules is for when
one uses a nonconforming TZ string like TZ='EST5EDT'.
> 1. Is there a better source for the list of installed time zones
> (leaving aside `tzdata.zi`, which I don't think I can count on to exist
> in all environments).

That depends on what you want the list for. If you want every value V such that
TZ='V' works via reading files, you've got the right list. If you want every
value V such that TZ='V' works, then you have just a subset since POSIX-style Vs
are not taken from files.

If you want a shorter list (which makes sense), you can omit the posix/* and
right/* and posixrules entries.

> 2. Is there any stable and standard way to distinguish between proper
> zones and other things that are also zone files like posixrules and
> right/ and posix/?

Depends on what you mean by 'proper'. :-)

'make zonenames' should be equivalent to looking in tzdata.zi, because that's
what 'make zonenames' does. And that should be equivalent to the "shorter list"
mentioned above.

> The closest I can find is `zone1970.tab` and
> `zone.tab` (which I think is not even always included), and that appears
> to be only a subset of the output of `make zonenames`.

Yup. The method I'd suggest is tzdata.zi if available, or the "shorter list"
mentioned above, whichever's faster. This is because zone1970.tab and zone.tab
don't list some of the duplicates, and some users like the duplicates.

If you also want the leap-second entries, you'll need the right/* entries though.


More information about the tz mailing list