xref: /netbsd-src/lib/libc/time/tzfile.5 (revision dd3ee07da436799d8de85f3055253118b76bf345)
1.\"	$NetBSD: tzfile.5,v 1.31 2021/10/22 14:26:04 christos Exp $
2.\"
3.\" This file is in the public domain, so clarified as of
4.\" 1996-06-05 by Arthur David Olson (arthur_david_olson@nih.gov).
5.Dd October 22, 2021
6.Dt TZFILE 5
7.Os
8.Sh NAME
9.Nm tzfile
10.Nd time zone information
11.Sh DESCRIPTION
12The timezone information files used by
13.Xr tzset 3
14are typically found under a directory with a name like
15.Pa /usr/share/zoneinfo .
16These files use the format described in Internet
17.Rs
18.%R RFC 8536
19.Re
20Each file is a sequence of 8-bit bytes.
21In a file, a binary integer is represented by a sequence of one or
22more bytes in network order (bigendian, or high-order byte first),
23with all bits significant,
24a signed binary integer is represented using two's complement,
25and a boolean is represented by a one-byte binary integer that is
26either
27.Dv 0
28(false) or
29.Dv 1
30(true).
31.Bl -bullet
32.It
33The magic four-byte ASCII sequence begin with the magic characters
34.Dq TZif .
35identifies the file as a timezone information file.
36.It
37A byte identifying the version of the file's format
38(as of 2021, either an ASCII
39.Dv NUL ,
40or
41.Dq 3 ,
42or
43.Dq 4 ).
44.It
45Fifteen bytes containing zeros reserved for future use.
46.It
47Six four-byte integer values, in the following order:
48.Bl -inset
49.It Va tzh_ttisutcnt
50The number of UT/local indicators stored in the file.
51(UT is Universal Time.)
52.It Va tzh_ttisstdcnt
53The number of standard/wall indicators stored in the file.
54.It Va tzh_leapcnt
55The number of leap seconds for which data entries are stored in the file.
56.It Va tzh_timecnt
57The number of transition times for which data entries are stored
58in the file.
59.It Va tzh_typecnt
60The number of local time types for which data entries are stored
61in the file (must not be zero).
62.It Va tzh_charcnt
63The number of bytes of timezone abbreviation strings
64stored in the file.
65.El
66.It
67The above header is followed by the following fields, whose lengths
68depend on the contents of the header:
69.Bl -inset
70.It Va tzh_timecnt
71four-byte signed integer values sorted in ascending order.
72These values are written in
73These values are written in standard byte order.
74Each is used as a transition time (as returned by
75.Xr time 3 )
76at which the rules for computing local time change.
77.It Va tzh_timecnt
78one-byte unsigned integer values;
79each one but the last tells which of the different types of local time types
80described in the file is associated with the time period
81starting with the same-indexed transition time
82and continuing up to but not including the next transition time.
83(The last time type is present only for consistency checking with the
84POSIX-style TZ string described below.)
85These values serve as indices into the next field.
86.It Va tzh_typecnt
87.Va ttinfo
88entries, each defined as follows:
89.Bd -literal
90struct ttinfo {
91	int32_t		tt_uttoff;
92	unsigned char	tt_isdst;
93	unsigned char	tt_desigind;
94};
95.Ed
96.Pp
97Each structure is written as a four-byte signed integer value for
98.Va tt_gmtoff
99in a network byte order, followed by a one-byte value for
100.Va tt_isdst
101and a one-byte value for
102.Va tt_desigidx .
103In each structure,
104.Va tt_gmtoff
105gives the number of seconds to be added to UT,
106.Va tt_isdst
107tells whether
108.Va tm_isdst
109should be set by
110.Xr localtime 3
111and
112.Va tt_desigidx
113serves as an index into the array of timezone abbreviation bytes
114that follow the
115.Va ttinfo
116structure(s) in the file.
117entries in the file; if the designated string is
118.Dq \e*-00 ,
119the
120.Va ttinfo
121entry is a placeholder indicating that local time is unspecified.
122The
123.Va tt_utoff
124+value is never equal to \-2**31,
125to let 32-bit clients negate it without overflow.
126Also, in realistic applications
127.Va tt_utoff
128is in the range [\-89999, 93599]
129(i.e., more than \-25 hours and less than 26
130hours); this allows easy support by implementations that
131already support the POSIX-required range
132.Dv [ \-24:59:59 , 25:59:59 ] .
133.It Va tzh_charcnt
134bytes that represent time zone designations,
135which are null-terminated byte strings, each indexed by the
136.It Va tt_desigidx
137values mentioned above.
138The byte strings can overlap if one is a suffix of the other.
139The encoding of these strings is not specified.
140.IP *
141.It Va tzh_leapcnt
142pairs of four-byte values, written in network byte order;
143the first value of each pair gives the time
144(as returned by
145.Xr time 3 )
146at which a leap second occurs or at which the leap second table expires;
147the second is a signed integer specifying the correction, which is the
148.Em total
149number of leap seconds to be applied during the time period
150starting at the given time.
151The pairs of values are sorted in strictly ascending order by time.
152Each pair denotes one leap second, either positive or negative,
153except that if the last pair has the same correction as the previous one,
154the last pair denotes the leap second table's expiration time.
155Each leap second is at the end of a UTC calendar month.
156The first leap second has a nonnegative occurrence time,
157and is a positive leap second if and only if its correction is positive;
158the correction for each leap second after the first differs
159from the previous leap second by either
160.Dv 1
161for a positive leap second, or
162.Dv \-1
163for a negative leap second.
164If the leap second table is empty, the leap-second correction is zero
165for all timestamps;
166otherwise, for timestamps before the first occurrence time,
167the leap-second correction is zero if the first pair's correction is
168.Dv 1
169or
170.Dv \-1 ,
171and is unspecified otherwise (which can happen only in files
172truncated at the start).
173.It Va tzh_ttisstdcnt
174standard/wall indicators, each stored as a one-byte boolean;
175they tell whether the transition times associated with local time types
176were specified as standard time or local (wall clock) time.
177.It Va tzh_ttisutcnt
178UT/local indicators, each stored as a one-byte boolean;
179they tell whether the transition times associated with local time types
180were specified as UT or local time.
181If a UT/local indicator is set, the corresponding standard/wall indicator
182must also be set.
183.Pp
184The standard/wall and UT/local indicators were designed for
185transforming a TZif file's transition times into transitions appropriate
186for another time zone specified via a POSIX-style TZ string that lacks rules.
187For example, when
188.Dv TZ="EET\*-2EEST"
189and there is no TZif file
190.Dq EET\*-2EEST ,
191the idea was to adapt the transition times from a TZif file with the
192well-known name "posixrules" that is present only for this purpose and
193is a copy of the file
194.Dq Europe/Brussels ,
195a file with a different UT offset.
196POSIX does not specify this obsolete transformational behavior,
197the default rules are installation-dependent, and no implementation
198is known to support this feature for timestamps past
199.Dv 2037 ,
200so users desiring (say) Greek time should instead specify
201.Dv TZ="Europe/Athens"
202for better historical coverage, falling back on
203.Dv TZ="EET\*-2EEST,M3.5.0/3,M10.5.0/4"
204if POSIX conformance is required
205and older timestamps need not be handled accurately.
206.Pp
207The
208.Xr localtime 3
209function normally uses the first
210.Fa ttinfo
211structure in the file
212if either
213.Va tzh_timecnt
214is zero or the time argument is less than the first transition time recorded
215in the file.
216.El
217.El
218.Ss Version 2 format
219For version-2-format timezone files,
220the above header and data are followed by a second header and data,
221identical in format except that
222eight bytes are used for each transition time or leap second time.
223(Leap second counts remain four bytes.)
224After the second header and data comes a newline-enclosed,
225POSIX-TZ-environment-variable-style string for use in handling instants
226after the last transition time stored in the file
227or for all instants if the file has no transitions.
228The POSIX-style TZ string is empty (i.e., nothing between the newlines)
229if there is no POSIX-style representation for such instants.
230If nonempty, the POSIX-style TZ string must agree with the local time
231type after the last transition time if present in the eight-byte data;
232for example, given the string
233.Dq WET0WEST,M3.5.0,M10.5.0/3
234then if a last transition time is in July, the transition's local time
235type must specify a daylight-saving time abbreviated
236.Dq WEST
237that is one hour east of UT.
238Also, if there is at least one transition, time type 0 is associated
239with the time period from the indefinite past up to but not including
240the earliest transition time.
241.Ss Version 3 format
242For version-3-format timezone files, the POSIX-TZ-style string may
243use two minor extensions to the POSIX TZ format, as described in
244.Xr tzset 3 .
245First, the hours part of its transition times may be signed and range from
246\-167 through 167
247instead of the POSIX-required unsigned values
248from 0 through 24.
249Second, DST is in effect all year if it starts
250January 1 at 00:00 and ends December 31 at 24:00 plus the difference
251between daylight saving and standard time.
252.Ss Version 4 format
253For version-4-format TZif files,
254the first leap second record can have a correction that is neither
255.Dv +1
256nor
257.Dv \-1 ,
258to represent truncation of the TZif file at the start.
259Also, if two or more leap second transitions are present and the last
260entry's correction equals the previous one, the last entry
261denotes the expiration of the leap second table instead of a leap second;
262timestamps after this expiration are unreliable in that future
263releases will likely add leap second entries after the expiration, and
264the added leap seconds will change how post-expiration timestamps are treated.
265.Ss Interoperability considerations
266.Pp
267Version 1 files are considered a legacy format and
268should not be generated, as they do not support transition
269times after the year 2038.
270Readers that understand only Version 1 must ignore
271any data that extends beyond the calculated end of the version
2721 data block.
273.PP
274Other than version 1, writers should generate
275the lowest version number needed by a file's data.
276For example, a writer should generate a version 4 file
277only if its leap second table either expires or is truncated at the start.
278Likewise, a writer not generating a version 4 file
279should generate a version 3 file only if
280TZ string extensions are necessary to accurately
281model transition times.
282.Pp
283The sequence of time changes defined by the version 1
284header and data block should be a contiguous sub-sequence
285of the time changes defined by the version 2+ header and data
286block, and by the footer.
287This guideline helps obsolescent version 1 readers
288agree with current readers about timestamps within the
289contiguous sub-sequence.  It also lets writers not
290supporting obsolescent readers use a
291.Dv tzh_timecnt
292of zero
293in the version 1 data block to save space.
294.Pp
295When a TZif file contains a leap second table expiration
296time, TZif readers should either refuse to process
297post-expiration timestamps, or process them as if the expiration
298time did not exist (possibly with an error indication).
299.Pp
300Time zone designations should consist of at least three (3)
301and no more than six (6) ASCII characters from the set of
302alphanumerics,
303.Dq \&- ,
304and
305.Dq + .
306This is for compatibility with POSIX requirements for
307time zone abbreviations.
308.Pp
309When reading a version 2 or higher file, readers
310should ignore the version 1 header and data block except for
311the purpose of skipping over them.
312.Pp
313Readers should calculate the total lengths of the
314headers and data blocks and check that they all fit within
315the actual file size, as part of a validity check for the file.
316.Pp
317When a positive leap second occurs, readers should append an extra
318second to the local minute containing the second just before the leap
319second.  If this occurs when the UTC offset is not a multiple of 60
320seconds, the leap second occurs earlier than the last second of the
321local minute and the minute's remaining local seconds are numbered
322through 60 instead of the usual 59; the UTC offset is unaffected.
323.Ss Common interoperability issues
324This section documents common problems in reading or writing TZif files.
325Most of these are problems in generating TZif files for use by
326older readers.
327The goals of this section are:
328.Bl -bullet
329.It
330to help TZif writers output files that avoid common
331pitfalls in older or buggy TZif readers,
332.It
333to help TZif readers avoid common pitfalls when reading
334files generated by future TZif writers, and
335.It
336to help any future specification authors see what sort of
337problems arise when the TZif format is changed.
338.El
339.Pp
340+When new versions of the TZif format have been defined, a
341design goal has been that a reader can successfully use a TZif
342file even if the file is of a later TZif version than what the
343reader was designed for.
344When complete compatibility was not achieved, an attempt was
345made to limit glitches to rarely used timestamps and allow
346simple partial workarounds in writers designed to generate
347new-version data useful even for older-version readers.
348This section attempts to document these compatibility issues and
349workarounds, as well as to document other common bugs in
350readers.
351.Pp
352Interoperability problems with TZif include the following:
353.Bl -bullet
354.It
355Some readers examine only version 1 data.
356As a partial workaround, a writer can output as much version 1
357data as possible.
358However, a reader should ignore version 1 data, and should use
359version 2+ data even if the reader's native timestamps have only
36032 bits.
361.It
362Some readers designed for version 2 might mishandle
363timestamps after a version 3 or higher file's last transition, because
364they cannot parse extensions to POSIX in the TZ-like string.
365As a partial workaround, a writer can output more transitions
366than necessary, so that only far-future timestamps are
367mishandled by version 2 readers.
368.It
369Some readers designed for version 2 do not support
370permanent daylight saving time, e.g., a TZ string
371permanent daylight saving time with transitions after 24:00
372\(en e.g., a TZ string
373.Dq EST5EDT,0/0,J365/25
374denoting permanent Eastern Daylight Time
375(\-04).
376As a workaround, a writer can substitute standard time
377for two time zones east, e.g.,
378.Dq XXX3EDT4,0/0,J365/23
379for a time zone with a never-used standard time (XXX, \-03)
380and negative daylight saving time (EDT, \-04) all year.
381Alternatively,
382as a partial workaround a writer can substitute standard time
383for the next time zone east \(en e.g.,
384.Dq AST4
385for permanent
386Atlantic Standard Time (\-04).
387.It
388Some readers designed for version 2 or 3, and that require strict
389conformance to RFC 8536, reject version 4 files whose leap second
390tables are truncated at the start or that end in expiration times.
391.It
392Some readers ignore the footer, and instead predict future
393timestamps from the time type of the last transition.
394As a partial workaround, a writer can output more transitions
395than necessary.
396.It
397Some readers do not use time type 0 for timestamps before
398the first transition, in that they infer a time type using a
399heuristic that does not always select time type 0.
400As a partial workaround, a writer can output a dummy (no-op)
401first transition at an early time.
402.It
403Some readers mishandle timestamps before the first
404transition that has a timestamp not less than -2**31.
405Readers that support only 32-bit timestamps are likely to be
406more prone to this problem, for example, when they process
40764-bit transitions only some of which are representable in 32
408bits.
409As a partial workaround, a writer can output a dummy
410transition at timestamp \&-2**31.
411.It
412Some readers mishandle a transition if its timestamp has
413the minimum possible signed 64-bit value.
414Timestamps less than \&-2**59 are not recommended.
415.It
416Some readers mishandle POSIX-style TZ strings that
417contain
418.Dq <
419or
420.Dq > .
421As a partial workaround, a writer can avoid using
422.Dq <
423or
424.Dq >
425for time zone abbreviations containing only alphabetic
426characters.
427.Pp
428Many readers mishandle time zone abbreviations that contain
429non-ASCII characters.
430These characters are not recommended.
431.Pp
432Some readers may mishandle time zone abbreviations that
433contain fewer than 3 or more than 6 characters, or that
434contain ASCII characters other than alphanumerics,
435.Dq \&- .
436and
437.Dq + .
438These abbreviations are not recommended.
439.It
440Some readers mishandle TZif files that specify
441daylight-saving time UT offsets that are less than the UT
442offsets for the corresponding standard time.
443These readers do not support locations like Ireland, which
444uses the equivalent of the POSIX TZ string
445.Dq IST\&-1GMT0,M10.5.0,M3.5.0/1 ,
446observing standard time
447(IST, +01) in summer and daylight saving time (GMT, +00) in winter.
448As a partial workaround, a writer can output data for the
449equivalent of the POSIX TZ string
450.Dq GMT0IST,M3.5.0/1,M10.5.0 ,
451thus swapping standard and daylight saving time.
452Although this workaround misidentifies which part of the year
453uses daylight saving time, it records UT offsets and time zone
454abbreviations correctly.
455.It
456Some readers generate ambiguous timestamps for positive leap seconds
457that occur when the UTC offset is not a multiple of 60 seconds.
458For example, in a timezone with UTC offset +01:23:45 and with
459a positive leap second 78796801 (1972-06-30 23:59:60 UTC), some readers will
460map both 78796800 and 78796801 to 01:23:45 local time the next day
461instead of mapping the latter to 01:23:46, and they will map 78796815 to
46201:23:59 instead of to 01:23:60.
463This has not yet been a practical problem, since no civil authority
464has observed such UTC offsets since leap seconds were
465introduced in 1972.
466.El
467.Pp
468Some interoperability problems are reader bugs that
469are listed here mostly as warnings to developers of readers.
470.Bl -bullet
471.It
472Some readers do not support negative timestamps.
473Developers of distributed applications should keep this
474in mind if they need to deal with pre-1970 data.
475.It
476Some readers mishandle timestamps before the first
477transition that has a nonnegative timestamp.
478Readers that do not support negative timestamps are likely to
479be more prone to this problem.
480.It
481+Some readers mishandle time zone abbreviations like
482.Dq \&-08
483that contain
484.Dq + ,
485.Dq \&- ,
486or digits.
487.It
488Some readers mishandle UT offsets that are out of the
489traditional range of \*-12 through +12 hours, and so do not
490support locations like Kiritimati that are outside this
491range.
492.It
493Some readers mishandle UT offsets in the range [\*-3599, \*-1]
494seconds from UT, because they integer-divide the offset by
4953600 to get 0 and then display the hour part as
496.Dq +00 .
497.It
498Some readers mishandle UT offsets that are not a multiple
499of one hour, or of 15 minutes, or of 1 minute.
500Future changes to the format may append more data.
501.El
502.Sh SEE ALSO
503.Xr ctime 3 ,
504.Xr localtime 3 ,
505.Xr time 3 ,
506.Xr tzset 3 ,
507.Xr zdump 8 ,
508.Xr zic 8 .
509.Rs
510.%A Olson A, Eggert P, Murchison K.
511.%T The Time Zone Information Format (TZif).
512.%D Feb 2019.
513.%U https://www.rfc-editor.org/info/rfc8536
514.%U https://doi.org/10.17487/RFC8536
515.%R RFC 8536
516.Re
517.\" @(#)tzfile.5	8.3
518.\" This file is in the public domain, so clarified as of
519.\" 1996-06-05 by Arthur David Olson.
520