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

Brian Inglis Brian.Inglis at SystematicSw.ab.ca
Fri May 15 22:25:25 UTC 2020


On 2020-05-15 13:52, Paul Eggert wrote:
> On 5/15/20 7:39 AM, Paul Ganssle wrote:
>> I'd say one
>> could easily want:
>>
>> 1. Every valid value for key that doesn't raise an error when you call
>> ZoneInfo(key)
> 
> Does ZoneInfo operate by looking for an actual file, or by setting TZ='key' and
> seeing whether that works? If the latter, there are many keys that are not
> listed anywhere because they're specified by POSIX. A simple example is
> TZ='MST7' which is a valid POSIX key and which is commonly used, but for which
> there is no file or tzdata.zi entry. I looked at PEP 615 and didn't see any
> mention of the issue of POSIX-specified TZ settings.
> 
>> I'm still mildly uncertain as to whether it's possible that tzdata.zi
>> might have more zones than are actually installed (for example if a
>> distro doesn't install anything in backward or antarctica for some reason).
> 
> In the reference implementation, the zones are installed from tzdata.zi so the
> lists should be identical there.
> 
>> Is it always the case that the right/ and posix/ trees are identical to
>> the primary tree?
> 
> Yes, in the reference implementation.

For every zone in the sources, try the following from your tzdata directory:

$ awk '
/^Zone/	{ print $2, "Zone", FILENAME }
/^Link/	{ print $3, "Link", FILENAME, $2 }
/^[^#]/ && FILENAME ~ /zone[^.]*\.tab/	{ print $3, "Tab", FILENAME, $1, $2 }
'	africa antarctica asia australasia backward backzone etcetera	\
	europe factory northamerica pacificnew solar8[7-9] systemv 	\
	usno1988 usno1989 usno1989a usno199[578] zone.tab zone1970.tab 	| \
sort -dfuk1,1

you can drop the sort -u or the sort command to see the selected data, or drop
the extra fields to just get the zone names - 586 unique entries total possible.

If I missed some selection source or criterion please post on the list.

-- 
Take care. Thanks, Brian Inglis, Calgary, Alberta, Canada

This email may be disturbing to some readers as it contains
too much technical detail. Reader discretion is advised.
[Data in IEC units and prefixes, physical quantities in SI.]


More information about the tz mailing list