xref: /netbsd-src/lib/libc/time/tzfile.5 (revision a8c74629f602faa0ccf8a463757d7baf858bbf3a)
1.\"	$NetBSD: tzfile.5,v 1.30 2020/05/25 14:52:48 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 May 25, 2020
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 (as of 2017, either
38an ASCII
39.Dv NUL ,
40or
41.Dq 2 ,
42or
43.Dq 3 ).
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.
117The
118.Va tt_utoff
119+value is never equal to \-2**31,
120to let 32-bit clients negate it without overflow.
121Also, in realistic applications
122.Va tt_utoff
123is in the range [\-89999, 93599]
124(i.e., more than \-25 hours and less than 26
125hours); this allows easy support by implementations that
126already support the POSIX-required range
127.Dv [ \-24:59:59 , 25:59:59 ] .
128.It Va tzh_leapcnt
129pairs of four-byte values, written in network byte order;
130the first value of each pair gives the time
131(as returned by
132.Xr time 3 )
133at which a leap second occurs;
134the second is a signed integer specifying the
135.Em total
136number of leap seconds to be applied during the time period
137starting at the given time.
138The pairs of values are sorted in ascending order by time.
139Each transition is for one leap second, either positive or negative;
140transitions always separated by at least 28 days minus 1 second.
141.It Va tzh_ttisstdcnt
142standard/wall indicators, each stored as a one-byte boolean;
143they tell whether the transition times associated with local time types
144were specified as standard time or local (wall clock) time.
145.It Va tzh_ttisutcnt
146UT/local indicators, each stored as a one-byte boolean;
147they tell whether the transition times associated with local time types
148were specified as UT or local time.
149If a UT/local indicator is set, the corresponding standard/wall indicator
150must also be set.
151.Pp
152The standard/wall and UT/local indicators were designed for
153transforming a TZif file's transition times into transitions appropriate
154for another time zone specified via a POSIX-style TZ string that lacks rules.
155For example, when
156.Dv TZ="EET\*-2EEST"
157and there is no TZif file
158.Dq EET\*-2EEST ,
159the idea was to adapt the transition times from a TZif file with the
160well-known name "posixrules" that is present only for this purpose and
161is a copy of the file
162.Dq Europe/Brussels ,
163a file with a different UT offset.
164POSIX does not specify this obsolete transformational behavior,
165the default rules are installation-dependent, and no implementation
166is known to support this feature for timestamps past
167.Dv 2037 ,
168so users desiring (say) Greek time should instead specify
169.Dv TZ="Europe/Athens"
170for better historical coverage, falling back on
171.Dv TZ="EET\*-2EEST,M3.5.0/3,M10.5.0/4"
172if POSIX conformance is required
173and older timestamps need not be handled accurately.
174.Pp
175The
176.Xr localtime 3
177function normally uses the first
178.Fa ttinfo
179structure in the file
180if either
181.Va tzh_timecnt
182is zero or the time argument is less than the first transition time recorded
183in the file.
184.El
185.El
186.Ss Version 2 format
187For version-2-format timezone files,
188the above header and data are followed by a second header and data,
189identical in format except that
190eight bytes are used for each transition time or leap second time.
191(Leap second counts remain four bytes.)
192After the second header and data comes a newline-enclosed,
193POSIX-TZ-environment-variable-style string for use in handling instants
194after the last transition time stored in the file
195or for all instants if the file has no transitions.
196The POSIX-style TZ string is empty (i.e., nothing between the newlines)
197if there is no POSIX representation for such instants.
198If nonempty, the POSIX-style TZ string must agree with the local time
199type after the last transition time if present in the eight-byte data;
200for example, given the string
201.Dq WET0WEST,M3.5.0,M10.5.0/3
202then if a last transition time is in July, the transition's local time
203type must specify a daylight-saving time abbreviated
204.Dq WEST
205that is one hour east of UT.
206Also, if there is at least one transition, time type 0 is associated
207with the time period from the indefinite past up to but not including
208the earliest transition time.
209.Ss Version 3 format
210For version-3-format timezone files, the POSIX-TZ-style string may
211use two minor extensions to the POSIX TZ format, as described in
212.Xr tzset 3 .
213First, the hours part of its transition times may be signed and range from
214\-167 through 167
215instead of the POSIX-required unsigned values
216from 0 through 24.
217Second, DST is in effect all year if it starts
218January 1 at 00:00 and ends December 31 at 24:00 plus the difference
219between daylight saving and standard time.
220.Ss Interoperability considerations
221.Pp
222Version 1 files are considered a legacy format and
223should be avoided, as they do not support transition
224times after the year 2038.
225Readers that only understand Version 1 must ignore
226any data that extends beyond the calculated end of the version
2271 data block.
228.PP
229Writers should generate a version 3 file if
230TZ string extensions are necessary to accurately
231model transition times.
232Otherwise, version 2 files should be generated.
233.Pp
234The sequence of time changes defined by the version 1
235header and data block should be a contiguous subsequence
236of the time changes defined by the version 2+ header and data
237block, and by the footer.
238This guideline helps obsolescent version 1 readers
239agree with current readers about timestamps within the
240contiguous subsequence.  It also lets writers not
241supporting obsolescent readers use a
242.Dv tzh_timecnt
243of zero
244in the version 1 data block to save space.
245.Pp
246Time zone designations should consist of at least three (3)
247and no more than six (6) ASCII characters from the set of
248alphanumerics,
249.Dq \&- ,
250and
251.Dq + .
252This is for compatibility with POSIX requirements for
253time zone abbreviations.
254.Pp
255When reading a version 2 or 3 file, readers
256should ignore the version 1 header and data block except for
257the purpose of skipping over them.
258.Pp
259Readers should calculate the total lengths of the
260headers and data blocks and check that they all fit within
261the actual file size, as part of a validity check for the file.
262.Ss Common interoperability issues
263This section documents common problems in reading or writing TZif files.
264Most of these are problems in generating TZif files for use by
265older readers.
266The goals of this section are:
267.Bl -bullet
268.It
269to help TZif writers output files that avoid common
270pitfalls in older or buggy TZif readers,
271.It
272to help TZif readers avoid common pitfalls when reading
273files generated by future TZif writers, and
274.It
275to help any future specification authors see what sort of
276problems arise when the TZif format is changed.
277.El
278.Pp
279+When new versions of the TZif format have been defined, a
280design goal has been that a reader can successfully use a TZif
281file even if the file is of a later TZif version than what the
282reader was designed for.
283When complete compatibility was not achieved, an attempt was
284made to limit glitches to rarely-used timestamps, and to allow
285simple partial workarounds in writers designed to generate
286new-version data useful even for older-version readers.
287This section attempts to document these compatibility issues and
288workarounds, as well as to document other common bugs in
289readers.
290.Pp
291Interoperability problems with TZif include the following:
292.Bl -bullet
293.It
294Some readers examine only version 1 data.
295As a partial workaround, a writer can output as much version 1
296data as possible.
297However, a reader should ignore version 1 data, and should use
298version 2+ data even if the reader's native timestamps have only
29932 bits.
300.It
301Some readers designed for version 2 might mishandle
302timestamps after a version 3 file's last transition, because
303they cannot parse extensions to POSIX in the TZ-like string.
304As a partial workaround, a writer can output more transitions
305than necessary, so that only far-future timestamps are
306mishandled by version 2 readers.
307.It
308Some readers designed for version 2 do not support
309permanent daylight saving time, e.g., a TZ string
310.Dq EST5EDT,0/0,J365/25
311denoting permanent Eastern Daylight Time (\&-04).
312As a partial workaround, a writer can substitute standard time
313for the next time zone east, e.g.,
314.Dq AST4
315+for permanent Atlantic Standard Time (\&-04).
316.It
317Some readers ignore the footer, and instead predict future
318timestamps from the time type of the last transition.
319As a partial workaround, a writer can output more transitions
320than necessary.
321.It
322Some readers do not use time type 0 for timestamps before
323the first transition, in that they infer a time type using a
324heuristic that does not always select time type 0.
325As a partial workaround, a writer can output a dummy (no-op)
326first transition at an early time.
327.It
328Some readers mishandle timestamps before the first
329transition that has a timestamp not less than -2**31.
330Readers that support only 32-bit timestamps are likely to be
331more prone to this problem, for example, when they process
33264-bit transitions only some of which are representable in 32
333bits.
334As a partial workaround, a writer can output a dummy
335transition at timestamp \&-2**31.
336.It
337Some readers mishandle a transition if its timestamp has
338the minimum possible signed 64-bit value.
339Timestamps less than \&-2**59 are not recommended.
340.It
341Some readers mishandle POSIX-style TZ strings that
342contain
343.Dq <
344or
345.Dq > .
346As a partial workaround, a writer can avoid using
347.Dq <
348or
349.Dq >
350for time zone abbreviations containing only alphabetic
351characters.
352.Pp
353Many readers mishandle time zone abbreviations that contain
354non-ASCII characters.
355These characters are not recommended.
356.Pp
357Some readers may mishandle time zone abbreviations that
358contain fewer than 3 or more than 6 characters, or that
359contain ASCII characters other than alphanumerics,
360.Dq \&- .
361and
362.Dq + .
363These abbreviations are not recommended.
364.It
365Some readers mishandle TZif files that specify
366daylight-saving time UT offsets that are less than the UT
367offsets for the corresponding standard time.
368These readers do not support locations like Ireland, which
369uses the equivalent of the POSIX TZ string
370.Dq IST\&-1GMT0,M10.5.0,M3.5.0/1 ,
371observing standard time
372(IST, +01) in summer and daylight saving time (GMT, +00) in winter.
373As a partial workaround, a writer can output data for the
374equivalent of the POSIX TZ string
375.Dq GMT0IST,M3.5.0/1,M10.5.0 ,
376thus swapping standard and daylight saving time.
377Although this workaround misidentifies which part of the year
378uses daylight saving time, it records UT offsets and time zone
379abbreviations correctly.
380.El
381.Pp
382Some interoperability problems are reader bugs that
383are listed here mostly as warnings to developers of readers.
384.Bl -bullet
385.It
386Some readers do not support negative timestamps.
387Developers of distributed applications should keep this
388in mind if they need to deal with pre-1970 data.
389.It
390Some readers mishandle timestamps before the first
391transition that has a nonnegative timestamp.
392Readers that do not support negative timestamps are likely to
393be more prone to this problem.
394.It
395+Some readers mishandle time zone abbreviations like
396.Dq \&-08
397that contain
398.Dq + ,
399.Dq \&- ,
400or digits.
401.It
402Some readers mishandle UT offsets that are out of the
403traditional range of \*-12 through +12 hours, and so do not
404support locations like Kiritimati that are outside this
405range.
406.It
407Some readers mishandle UT offsets in the range [\*-3599, \*-1]
408seconds from UT, because they integer-divide the offset by
4093600 to get 0 and then display the hour part as
410.Dq +00 .
411.It
412Some readers mishandle UT offsets that are not a multiple
413of one hour, or of 15 minutes, or of 1 minute.
414Future changes to the format may append more data.
415.El
416.Sh SEE ALSO
417.Xr ctime 3 ,
418.Xr localtime 3 ,
419.Xr time 3 ,
420.Xr tzset 3 ,
421.Xr zdump 8 ,
422.Xr zic 8 .
423.Rs
424.%A Olson A, Eggert P, Murchison K.
425.%T The Time Zone Information Format (TZif).
426.%D Feb 2019.
427.%U https://www.rfc-editor.org/info/rfc8536
428.%U https://doi.org/10.17487/RFC8536
429.%R RFC 8536
430.Re
431.\" @(#)tzfile.5	8.3
432.\" This file is in the public domain, so clarified as of
433.\" 1996-06-05 by Arthur David Olson.
434