tzfile - timezone information
The timezone information files used by tzset(3) are
typically found under a directory with a name like
/usr/share/zoneinfo
. These files use the format described in
Internet RFC 8536. Each file is a sequence of 8-bit bytes. In a file, a
binary integer is represented by a sequence of one or more bytes in
network order (bigendian, or high-order byte first), with all bits
significant, a signed binary integer is represented using two's
complement, and a boolean is represented by a one-byte binary integer
that is either 0 (false) or 1 (true). The format begins with a 44-byte
header containing the following fields:
The magic four-byte ASCII sequence “TZif” identifies the file as a timezone information file.
A byte identifying the version of the file's format (as of 2021, either an ASCII NUL, “2”, “3”, or “4”).
Fifteen bytes containing zeros reserved for future use.
Six four-byte integer values, in the following order:
- tzh_ttisutcnt
The number of UT/local indicators stored in the file. (UT is Universal Time.)
- tzh_ttisstdcnt
The number of standard/wall indicators stored in the file.
- tzh_leapcnt
The number of leap seconds for which data entries are stored in the file.
- tzh_timecnt
The number of transition times for which data entries are stored in the file.
- tzh_typecnt
The number of local time types for which data entries are stored in the file (must not be zero).
- tzh_charcnt
The number of bytes of time zone abbreviation strings stored in the file.
The above header is followed by the following fields, whose lengths depend on the contents of the header:
tzh_timecnt four-byte signed integer values sorted in ascending order. These values are written in network byte order. Each is used as a transition time (as returned by time(2)) at which the rules for computing local time change.
tzh_timecnt one-byte unsigned integer values; each one but the last tells which of the different types of local time types described in the file is associated with the time period starting with the same-indexed transition time and continuing up to but not including the next transition time. (The last time type is present only for consistency checking with the POSIX.1-2017-style TZ string described below.) These values serve as indices into the next field.
tzh_typecnt ttinfo entries, each defined as follows:
struct ttinfo { int32_t tt_utoff; unsigned char tt_isdst; unsigned char tt_desigidx; };
Each structure is written as a four-byte signed integer value for tt_utoff, in network byte order, followed by a one-byte boolean for tt_isdst and a one-byte value for tt_desigidx. In each structure, tt_utoff gives the number of seconds to be added to UT, tt_isdst tells whether tm_isdst should be set by localtime(3) and tt_desigidx serves as an index into the array of time zone abbreviation bytes that follow the ttinfo entries in the file; if the designated string is "00", the ttinfo entry is a placeholder indicating that local time is unspecified. The tt_utoff value is never equal to -2**31, to let 32-bit clients negate it without overflow. Also, in realistic applications tt_utoff is in the range [-89999, 93599] (i.e., more than -25 hours and less than 26 hours); this allows easy support by implementations that already support the POSIX-required range [-24:59:59, 25:59:59].
tzh_charcnt bytes that represent time zone designations, which are null-terminated byte strings, each indexed by the tt_desigidx values mentioned above. The byte strings can overlap if one is a suffix of the other. The encoding of these strings is not specified.
tzh_leapcnt pairs of four-byte values, written in network byte order; the first value of each pair gives the nonnegative time (as returned by time(2)) at which a leap second occurs or at which the leap second table expires; the second is a signed integer specifying the correction, which is the
total
number of leap seconds to be applied during the time period starting at the given time. The pairs of values are sorted in strictly ascending order by time. Each pair denotes one leap second, either positive or negative, except that if the last pair has the same correction as the previous one, the last pair denotes the leap second table's expiration time. Each leap second is at the end of a UTC calendar month. The first leap second has a nonnegative occurrence time, and is a positive leap second if and only if its correction is positive; the correction for each leap second after the first differs from the previous leap second by either 1 for a positive leap second, or -1 for a negative leap second. If the leap second table is empty, the leap-second correction is zero for all timestamps; otherwise, for timestamps before the first occurrence time, the leap-second correction is zero if the first pair's correction is 1 or -1, and is unspecified otherwise (which can happen only in files truncated at the start).tzh_ttisstdcnt standard/wall indicators, each stored as a one-byte boolean; they tell whether the transition times associated with local time types were specified as standard time or local (wall clock) time.
tzh_ttisutcnt UT/local indicators, each stored as a one-byte boolean; they tell whether the transition times associated with local time types were specified as UT or local time. If a UT/local indicator is set, the corresponding standard/wall indicator must also be set.
The standard/wall and UT/local indicators were designed for transforming a TZif file's transition times into transitions appropriate for another time zone specified via a POSIX.1-2017-style TZ string that lacks rules. For example, when TZ="EET2EEST" and there is no TZif file "EET2EEST", the idea was to adapt the transition times from a TZif file with the well-known name "posixrules" that is present only for this purpose and is a copy of the file "Europe/Brussels", a file with a different UT offset. POSIX does not specify this obsolete transformational behavior, the default rules are installation-dependent, and no implementation is known to support this feature for timestamps past 2037, so users desiring (say) Greek time should instead specify TZ="Europe/Athens" for better historical coverage, falling back on TZ="EET2EEST,M3.5.0/3,M10.5.0/4" if POSIX conformance is required and older timestamps need not be handled accurately.
The localtime(3) function normally uses the first ttinfo structure in the file if either tzh_timecnt is zero or the time argument is less than the first transition time recorded in the file.
time(2), localtime(3), tzset(3), tzselect(8), zdump(8), zic(8).
Olson A, Eggert P, Murchison K. The Time Zone Information Format (TZif). 2019 Feb. https://datatracker.ietf.org/doc/html/rfc8536">Internet RFC 8536 https://doi.org/10.17487/RFC8536">doi:10.17487/RFC8536.