]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man5/tzfile.5
hypot.3: srcfix: add some notes about the underflow case
[thirdparty/man-pages.git] / man5 / tzfile.5
1 .\" %%%LICENSE_START(PUBLIC_DOMAIN)
2 .\" This file is in the public domain, so clarified as of
3 .\" 1996-06-05 by Arthur David Olson <arthur_david_olson@nih.gov>.
4 .\" %%%LICENSE_END
5 .\"
6 .TH TZFILE 5 2020-04-27 "" "Linux Programmer's Manual"
7 .SH NAME
8 tzfile \- timezone information
9 .SH DESCRIPTION
10 .ie '\(lq'' .ds lq \&"\"
11 .el .ds lq \(lq\"
12 .ie '\(rq'' .ds rq \&"\"
13 .el .ds rq \(rq\"
14 .de q
15 \\$3\*(lq\\$1\*(rq\\$2
16 ..
17 .ie \n(.g .ds - \f(CW-\fP
18 .el ds - \-
19 The timezone information files used by
20 .BR tzset (3)
21 are typically found under a directory with a name like
22 .IR /usr/share/zoneinfo .
23 These files use the format described in Internet RFC 8536.
24 Each file is a sequence of 8-bit bytes.
25 In a file, a binary integer is represented by a sequence of one or
26 more bytes in network order (bigendian, or high-order byte first),
27 with all bits significant,
28 a signed binary integer is represented using two's complement,
29 and a boolean is represented by a one-byte binary integer that is
30 either 0 (false) or 1 (true).
31 The format begins with a 44-byte header containing the following fields:
32 .IP * 2
33 The magic four-byte ASCII sequence
34 .q "TZif"
35 identifies the file as a timezone information file.
36 .IP *
37 A byte identifying the version of the file's format
38 (as of 2017, either an ASCII NUL, or
39 .q "2",
40 or
41 .q "3" ).
42 .IP *
43 Fifteen bytes containing zeros reserved for future use.
44 .IP *
45 Six four-byte integer values, in the following order:
46 .RS
47 .TP
48 .I tzh_ttisutcnt
49 The number of UT/local indicators stored in the file.
50 (UT is Universal Time.)
51 .TP
52 .I tzh_ttisstdcnt
53 The number of standard/wall indicators stored in the file.
54 .TP
55 .I tzh_leapcnt
56 The number of leap seconds for which data entries are stored in the file.
57 .TP
58 .I tzh_timecnt
59 The number of transition times for which data entries are stored
60 in the file.
61 .TP
62 .I tzh_typecnt
63 The number of local time types for which data entries are stored
64 in the file (must not be zero).
65 .TP
66 .I tzh_charcnt
67 The number of bytes of time zone abbreviation strings
68 stored in the file.
69 .RE
70 .PP
71 The above header is followed by the following fields, whose lengths
72 depend on the contents of the header:
73 .IP * 2
74 .I tzh_timecnt
75 four-byte signed integer values sorted in ascending order.
76 These values are written in network byte order.
77 Each is used as a transition time (as returned by
78 .BR time (2))
79 at which the rules for computing local time change.
80 .IP *
81 .I tzh_timecnt
82 one-byte unsigned integer values;
83 each one but the last tells which of the different types of local time types
84 described in the file is associated with the time period
85 starting with the same-indexed transition time
86 and continuing up to but not including the next transition time.
87 (The last time type is present only for consistency checking with the
88 POSIX-style TZ string described below.)
89 These values serve as indices into the next field.
90 .IP *
91 .I tzh_typecnt
92 .I ttinfo
93 entries, each defined as follows:
94 .in +.5i
95 .sp
96 .nf
97 .ta .5i +\w'unsigned char\0\0'u
98 struct ttinfo {
99 int32_t tt_utoff;
100 unsigned char tt_isdst;
101 unsigned char tt_desigidx;
102 };
103 .in -.5i
104 .fi
105 .sp
106 Each structure is written as a four-byte signed integer value for
107 .IR tt_utoff ,
108 in network byte order, followed by a one-byte boolean for
109 .I tt_isdst
110 and a one-byte value for
111 .IR tt_desigidx .
112 In each structure,
113 .I tt_utoff
114 gives the number of seconds to be added to UT,
115 .I tt_isdst
116 tells whether
117 .I tm_isdst
118 should be set by
119 .BR localtime (3)
120 and
121 .I tt_desigidx
122 serves as an index into the array of time zone abbreviation bytes
123 that follow the
124 .I ttinfo
125 structure(s) in the file.
126 The
127 .I tt_utoff
128 value is never equal to \-2**31, to let 32-bit clients negate it without
129 overflow.
130 Also, in realistic applications
131 .I tt_utoff
132 is in the range [\-89999, 93599] (i.e., more than \-25 hours and less
133 than 26 hours); this allows easy support by implementations that
134 already support the POSIX-required range [\-24:59:59, 25:59:59].
135 .IP *
136 .I tzh_leapcnt
137 pairs of four-byte values, written in network byte order;
138 the first value of each pair gives the nonnegative time
139 (as returned by
140 .BR time (2))
141 at which a leap second occurs;
142 the second is a signed integer specifying the
143 .I total
144 number of leap seconds to be applied during the time period
145 starting at the given time.
146 The pairs of values are sorted in ascending order by time.
147 Each transition is for one leap second, either positive or negative;
148 transitions always separated by at least 28 days minus 1 second.
149 .IP *
150 .I tzh_ttisstdcnt
151 standard/wall indicators, each stored as a one-byte boolean;
152 they tell whether the transition times associated with local time types
153 were specified as standard time or local (wall clock) time.
154 .IP *
155 .I tzh_ttisutcnt
156 UT/local indicators, each stored as a one-byte boolean;
157 they tell whether the transition times associated with local time types
158 were specified as UT or local time.
159 If a UT/local indicator is set, the corresponding standard/wall indicator
160 must also be set.
161 .PP
162 The standard/wall and UT/local indicators were designed for
163 transforming a TZif file's transition times into transitions appropriate
164 for another time zone specified via a POSIX-style TZ string that lacks rules.
165 For example, when TZ="EET\*-2EEST" and there is no TZif file "EET\*-2EEST",
166 the idea was to adapt the transition times from a TZif file with the
167 well-known name "posixrules" that is present only for this purpose and
168 is a copy of the file "Europe/Brussels", a file with a different UT offset.
169 POSIX does not specify this obsolete transformational behavior,
170 the default rules are installation-dependent, and no implementation
171 is known to support this feature for timestamps past 2037,
172 so users desiring (say) Greek time should instead specify
173 TZ="Europe/Athens" for better historical coverage, falling back on
174 TZ="EET\*-2EEST,M3.5.0/3,M10.5.0/4" if POSIX conformance is required
175 and older timestamps need not be handled accurately.
176 .PP
177 The
178 .BR localtime (3)
179 function
180 normally uses the first
181 .I ttinfo
182 structure in the file
183 if either
184 .I tzh_timecnt
185 is zero or the time argument is less than the first transition time recorded
186 in the file.
187 .SS Version 2 format
188 For version-2-format timezone files,
189 the above header and data are followed by a second header and data,
190 identical in format except that
191 eight bytes are used for each transition time or leap second time.
192 (Leap second counts remain four bytes.)
193 After the second header and data comes a newline-enclosed,
194 POSIX-TZ-environment-variable-style string for use in handling instants
195 after the last transition time stored in the file
196 or for all instants if the file has no transitions.
197 The POSIX-style TZ string is empty (i.e., nothing between the newlines)
198 if there is no POSIX representation for such instants.
199 If nonempty, the POSIX-style TZ string must agree with the local time
200 type after the last transition time if present in the eight-byte data;
201 for example, given the string
202 .q "WET0WEST,M3.5.0,M10.5.0/3"
203 then if a last transition time is in July, the transition's local time
204 type must specify a daylight-saving time abbreviated
205 .q "WEST"
206 that is one hour east of UT.
207 Also, if there is at least one transition, time type 0 is associated
208 with the time period from the indefinite past up to but not including
209 the earliest transition time.
210 .SS Version 3 format
211 For version-3-format timezone files, the POSIX-TZ-style string may
212 use two minor extensions to the POSIX TZ format, as described in
213 .BR newtzset (3).
214 First, the hours part of its transition times may be signed and range from
215 \-167 through 167 instead of the POSIX-required unsigned values
216 from 0 through 24.
217 Second, DST is in effect all year if it starts
218 January 1 at 00:00 and ends December 31 at 24:00 plus the difference
219 between daylight saving and standard time.
220 .SS Interoperability considerations
221 Future changes to the format may append more data.
222 .PP
223 Version 1 files are considered a legacy format and
224 should be avoided, as they do not support transition
225 times after the year 2038.
226 Readers that only understand Version 1 must ignore
227 any data that extends beyond the calculated end of the version
228 1 data block.
229 .PP
230 Writers should generate a version 3 file if
231 TZ string extensions are necessary to accurately
232 model transition times.
233 Otherwise, version 2 files should be generated.
234 .PP
235 The sequence of time changes defined by the version 1
236 header and data block should be a contiguous subsequence
237 of the time changes defined by the version 2+ header and data
238 block, and by the footer.
239 This guideline helps obsolescent version 1 readers
240 agree with current readers about timestamps within the
241 contiguous subsequence. It also lets writers not
242 supporting obsolescent readers use a
243 .I tzh_timecnt
244 of zero
245 in the version 1 data block to save space.
246 .PP
247 Time zone designations should consist of at least three (3)
248 and no more than six (6) ASCII characters from the set of
249 alphanumerics,
250 .q "\*-",
251 and
252 .q "+".
253 This is for compatibility with POSIX requirements for
254 time zone abbreviations.
255 .PP
256 When reading a version 2 or 3 file, readers
257 should ignore the version 1 header and data block except for
258 the purpose of skipping over them.
259 .PP
260 Readers should calculate the total lengths of the
261 headers and data blocks and check that they all fit within
262 the actual file size, as part of a validity check for the file.
263 .SS Common interoperability issues
264 This section documents common problems in reading or writing TZif files.
265 Most of these are problems in generating TZif files for use by
266 older readers.
267 The goals of this section are:
268 .IP * 2
269 to help TZif writers output files that avoid common
270 pitfalls in older or buggy TZif readers,
271 .IP *
272 to help TZif readers avoid common pitfalls when reading
273 files generated by future TZif writers, and
274 .IP *
275 to help any future specification authors see what sort of
276 problems arise when the TZif format is changed.
277 .PP
278 When new versions of the TZif format have been defined, a
279 design goal has been that a reader can successfully use a TZif
280 file even if the file is of a later TZif version than what the
281 reader was designed for.
282 When complete compatibility was not achieved, an attempt was
283 made to limit glitches to rarely-used timestamps, and to allow
284 simple partial workarounds in writers designed to generate
285 new-version data useful even for older-version readers.
286 This section attempts to document these compatibility issues and
287 workarounds, as well as to document other common bugs in
288 readers.
289 .PP
290 Interoperability problems with TZif include the following:
291 .IP * 2
292 Some readers examine only version 1 data.
293 As a partial workaround, a writer can output as much version 1
294 data as possible.
295 However, a reader should ignore version 1 data, and should use
296 version 2+ data even if the reader's native timestamps have only
297 32 bits.
298 .IP *
299 Some readers designed for version 2 might mishandle
300 timestamps after a version 3 file's last transition, because
301 they cannot parse extensions to POSIX in the TZ-like string.
302 As a partial workaround, a writer can output more transitions
303 than necessary, so that only far-future timestamps are
304 mishandled by version 2 readers.
305 .IP *
306 Some readers designed for version 2 do not support
307 permanent daylight saving time, e.g., a TZ string
308 .q "EST5EDT,0/0,J365/25"
309 denoting permanent Eastern Daylight Time (\-04).
310 As a partial workaround, a writer can substitute standard time
311 for the next time zone east, e.g.,
312 .q "AST4"
313 for permanent Atlantic Standard Time (\-04).
314 .IP *
315 Some readers ignore the footer, and instead predict future
316 timestamps from the time type of the last transition.
317 As a partial workaround, a writer can output more transitions
318 than necessary.
319 .IP *
320 Some readers do not use time type 0 for timestamps before
321 the first transition, in that they infer a time type using a
322 heuristic that does not always select time type 0.
323 As a partial workaround, a writer can output a dummy (no-op)
324 first transition at an early time.
325 .IP *
326 Some readers mishandle timestamps before the first
327 transition that has a timestamp not less than \-2**31.
328 Readers that support only 32-bit timestamps are likely to be
329 more prone to this problem, for example, when they process
330 64-bit transitions only some of which are representable in 32
331 bits.
332 As a partial workaround, a writer can output a dummy
333 transition at timestamp \-2**31.
334 .IP *
335 Some readers mishandle a transition if its timestamp has
336 the minimum possible signed 64-bit value.
337 Timestamps less than \-2**59 are not recommended.
338 .IP *
339 Some readers mishandle POSIX-style TZ strings that
340 contain
341 .q "<"
342 or
343 .q ">".
344 As a partial workaround, a writer can avoid using
345 .q "<"
346 or
347 .q ">"
348 for time zone abbreviations containing only alphabetic
349 characters.
350 .IP *
351 Many readers mishandle time zone abbreviations that contain
352 non-ASCII characters.
353 These characters are not recommended.
354 .IP *
355 Some readers may mishandle time zone abbreviations that
356 contain fewer than 3 or more than 6 characters, or that
357 contain ASCII characters other than alphanumerics,
358 .q "\*-",
359 and
360 .q "+".
361 These abbreviations are not recommended.
362 .IP *
363 Some readers mishandle TZif files that specify
364 daylight-saving time UT offsets that are less than the UT
365 offsets for the corresponding standard time.
366 These readers do not support locations like Ireland, which
367 uses the equivalent of the POSIX TZ string
368 .q "IST\*-1GMT0,M10.5.0,M3.5.0/1",
369 observing standard time
370 (IST, +01) in summer and daylight saving time (GMT, +00) in winter.
371 As a partial workaround, a writer can output data for the
372 equivalent of the POSIX TZ string
373 .q "GMT0IST,M3.5.0/1,M10.5.0",
374 thus swapping standard and daylight saving time.
375 Although this workaround misidentifies which part of the year
376 uses daylight saving time, it records UT offsets and time zone
377 abbreviations correctly.
378 .PP
379 Some interoperability problems are reader bugs that
380 are listed here mostly as warnings to developers of readers.
381 .IP * 2
382 Some readers do not support negative timestamps.
383 Developers of distributed applications should keep this
384 in mind if they need to deal with pre-1970 data.
385 .IP *
386 Some readers mishandle timestamps before the first
387 transition that has a nonnegative timestamp.
388 Readers that do not support negative timestamps are likely to
389 be more prone to this problem.
390 .IP *
391 Some readers mishandle time zone abbreviations like
392 .q "\*-08"
393 that contain
394 .q "+",
395 .q "\*-",
396 or digits.
397 .IP *
398 Some readers mishandle UT offsets that are out of the
399 traditional range of \-12 through +12 hours, and so do not
400 support locations like Kiritimati that are outside this
401 range.
402 .IP *
403 Some readers mishandle UT offsets in the range [\-3599, \-1]
404 seconds from UT, because they integer-divide the offset by
405 3600 to get 0 and then display the hour part as
406 .q "+00".
407 .IP *
408 Some readers mishandle UT offsets that are not a multiple
409 of one hour, or of 15 minutes, or of 1 minute.
410 .SH SEE ALSO
411 .BR time (2),
412 .BR localtime (3),
413 .BR tzset (3),
414 .BR tzselect (8),
415 .BR zdump (8),
416 .BR zic (8).
417 .PP
418 Olson A, Eggert P, Murchison K. The Time Zone Information Format (TZif).
419 2019 Feb.
420 .UR https://\:www.rfc-editor.org/\:info/\:rfc8536
421 Internet RFC 8536
422 .UE
423 .UR https://\:doi.org/\:10.17487/\:RFC8536
424 doi:10.17487/RFC8536
425 .UE .
426 .\" This file is in the public domain, so clarified as of
427 .\" 1996-06-05 by Arthur David Olson.