tzfile.5 18 KB

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