theory.html 61 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <title>Theory and pragmatics of the tz code and data</title>
  5. <meta charset="UTF-8">
  6. <style>
  7. pre {margin-left: 2em; white-space: pre-wrap;}
  8. </style>
  9. </head>
  10. <body>
  11. <h1>Theory and pragmatics of the <code><abbr>tz</abbr></code> code and data</h1>
  12. <h3>Outline</h3>
  13. <nav>
  14. <ul>
  15. <li><a href="#scope">Scope of the <code><abbr>tz</abbr></code>
  16. database</a></li>
  17. <li><a href="#naming">Timezone identifiers</a></li>
  18. <li><a href="#abbreviations">Time zone abbreviations</a></li>
  19. <li><a href="#accuracy">Accuracy of the <code><abbr>tz</abbr></code>
  20. database</a></li>
  21. <li><a href="#functions">Time and date functions</a></li>
  22. <li><a href="#stability">Interface stability</a></li>
  23. <li><a href="#leapsec">Leap seconds</a></li>
  24. <li><a href="#calendar">Calendrical issues</a></li>
  25. <li><a href="#planets">Time and time zones off earth</a></li>
  26. </ul>
  27. </nav>
  28. <section>
  29. <h2 id="scope">Scope of the <code><abbr>tz</abbr></code> database</h2>
  30. <p>
  31. The <a
  32. href="https://www.iana.org/time-zones"><code><abbr>tz</abbr></code>
  33. database</a> attempts to record the history and predicted future of
  34. civil time scales.
  35. It organizes <a href="tz-link.html">time zone and daylight saving time
  36. data</a> by partitioning the world into <a
  37. href="https://en.wikipedia.org/wiki/List_of_tz_database_time_zones"><dfn>timezones</dfn></a>
  38. whose clocks all agree about timestamps that occur after the <a
  39. href="https://en.wikipedia.org/wiki/Unix_time">POSIX Epoch</a>
  40. (1970-01-01 00:00:00 <a
  41. href="https://en.wikipedia.org/wiki/Coordinated_Universal_Time"><abbr
  42. title="Coordinated Universal Time">UTC</abbr></a>).
  43. Although 1970 is a somewhat-arbitrary cutoff, there are significant
  44. challenges to moving the cutoff earlier even by a decade or two, due
  45. to the wide variety of local practices before computer timekeeping
  46. became prevalent.
  47. Most timezones correspond to a notable location and the database
  48. records all known clock transitions for that location;
  49. some timezones correspond instead to a fixed <abbr>UTC</abbr> offset.
  50. </p>
  51. <p>
  52. Each timezone typically corresponds to a geographical region that is
  53. smaller than a traditional time zone, because clocks in a timezone
  54. all agree after 1970 whereas a traditional time zone merely
  55. specifies current standard time. For example, applications that deal
  56. with current and future timestamps in the traditional North
  57. American mountain time zone can choose from the timezones
  58. <code>America/Denver</code> which observes US-style daylight saving
  59. time (<abbr>DST</abbr>),
  60. and <code>America/Phoenix</code> which does not observe <abbr>DST</abbr>.
  61. Applications that also deal with past timestamps in the mountain time
  62. zone can choose from over a dozen timezones, such as
  63. <code>America/Boise</code>, <code>America/Edmonton</code>, and
  64. <code>America/Hermosillo</code>, each of which currently uses mountain
  65. time but differs from other timezones for some timestamps after 1970.
  66. </p>
  67. <p>
  68. Clock transitions before 1970 are recorded for location-based timezones,
  69. because most systems support timestamps before 1970 and could
  70. misbehave if data entries were omitted for pre-1970 transitions.
  71. However, the database is not designed for and does not suffice for
  72. applications requiring accurate handling of all past times everywhere,
  73. as it would take far too much effort and guesswork to record all
  74. details of pre-1970 civil timekeeping.
  75. Although some information outside the scope of the database is
  76. collected in a file <code>backzone</code> that is distributed along
  77. with the database proper, this file is less reliable and does not
  78. necessarily follow database guidelines.
  79. </p>
  80. <p>
  81. As described below, reference source code for using the
  82. <code><abbr>tz</abbr></code> database is also available.
  83. The <code><abbr>tz</abbr></code> code is upwards compatible with <a
  84. href="https://en.wikipedia.org/wiki/POSIX">POSIX</a>, an international
  85. standard for <a
  86. href="https://en.wikipedia.org/wiki/Unix">UNIX</a>-like systems.
  87. As of this writing, the current edition of POSIX is: <a
  88. href="https://pubs.opengroup.org/onlinepubs/9699919799/"> The Open
  89. Group Base Specifications Issue 7</a>, IEEE Std 1003.1-2017, 2018
  90. Edition.
  91. Because the database's scope encompasses real-world changes to civil
  92. timekeeping, its model for describing time is more complex than the
  93. standard and daylight saving times supported by POSIX.
  94. A <code><abbr>tz</abbr></code> timezone corresponds to a ruleset that can
  95. have more than two changes per year, these changes need not merely
  96. flip back and forth between two alternatives, and the rules themselves
  97. can change at times.
  98. Whether and when a timezone changes its clock,
  99. and even the timezone's notional base offset from <abbr>UTC</abbr>,
  100. are variable.
  101. It does not always make sense to talk about a timezone's
  102. "base offset", which is not necessarily a single number.
  103. </p>
  104. </section>
  105. <section>
  106. <h2 id="naming">Timezone identifiers</h2>
  107. <p>
  108. Each timezone has a name that uniquely identifies the timezone.
  109. Inexperienced users are not expected to select these names unaided.
  110. Distributors should provide documentation and/or a simple selection
  111. interface that explains each name via a map or via descriptive text like
  112. "Czech Republic" instead of the timezone name "<code>Europe/Prague</code>".
  113. If geolocation information is available, a selection interface can
  114. locate the user on a timezone map or prioritize names that are
  115. geographically close. For an example selection interface, see the
  116. <code>tzselect</code> program in the <code><abbr>tz</abbr></code> code.
  117. The <a href="https://cldr.unicode.org">Unicode Common Locale Data
  118. Repository</a> contains data that may be useful for other selection
  119. interfaces; it maps timezone names like <code>Europe/Prague</code> to
  120. locale-dependent strings like "Prague", "Praha", "Прага", and "布拉格".
  121. </p>
  122. <p>
  123. The naming conventions attempt to strike a balance
  124. among the following goals:
  125. </p>
  126. <ul>
  127. <li>
  128. Uniquely identify every timezone where clocks have agreed since 1970.
  129. This is essential for the intended use: static clocks keeping local
  130. civil time.
  131. </li>
  132. <li>
  133. Indicate to experts where the timezone's clocks typically are.
  134. </li>
  135. <li>
  136. Be robust in the presence of political changes.
  137. For example, names are typically not tied to countries, to avoid
  138. incompatibilities when countries change their name (e.g.,
  139. Swaziland&rarr;Eswatini) or when locations change countries (e.g., Hong
  140. Kong from UK colony to China).
  141. There is no requirement that every country or national
  142. capital must have a timezone name.
  143. </li>
  144. <li>
  145. Be portable to a wide variety of implementations.
  146. </li>
  147. <li>
  148. Use a consistent naming conventions over the entire world.
  149. </li>
  150. </ul>
  151. <p>
  152. Names normally have the form
  153. <var>AREA</var><code>/</code><var>LOCATION</var>, where
  154. <var>AREA</var> is a continent or ocean, and
  155. <var>LOCATION</var> is a specific location within the area.
  156. North and South America share the same area, '<code>America</code>'.
  157. Typical names are '<code>Africa/Cairo</code>',
  158. '<code>America/New_York</code>', and '<code>Pacific/Honolulu</code>'.
  159. Some names are further qualified to help avoid confusion; for example,
  160. '<code>America/Indiana/Petersburg</code>' distinguishes Petersburg,
  161. Indiana from other Petersburgs in America.
  162. </p>
  163. <p>
  164. Here are the general guidelines used for
  165. choosing timezone names,
  166. in decreasing order of importance:
  167. </p>
  168. <ul>
  169. <li>
  170. Use only valid POSIX file name components (i.e., the parts of
  171. names other than '<code>/</code>').
  172. Do not use the file name components '<code>.</code>' and
  173. '<code>..</code>'.
  174. Within a file name component, use only <a
  175. href="https://en.wikipedia.org/wiki/ASCII">ASCII</a> letters,
  176. '<code>.</code>', '<code>-</code>' and '<code>_</code>'.
  177. Do not use digits, as that might create an ambiguity with <a
  178. href="https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap08.html#tag_08_03">POSIX
  179. <code>TZ</code> strings</a>.
  180. A file name component must not exceed 14 characters or start with
  181. '<code>-</code>'.
  182. E.g., prefer <code>America/Noronha</code> to
  183. <code>America/Fernando_de_Noronha</code>.
  184. Exceptions: see the discussion of legacy names below.
  185. </li>
  186. <li>
  187. A name must not be empty, or contain '<code>//</code>', or
  188. start or end with '<code>/</code>'.
  189. </li>
  190. <li>
  191. Do not use names that differ only in case.
  192. Although the reference implementation is case-sensitive, some
  193. other implementations are not, and they would mishandle names
  194. differing only in case.
  195. </li>
  196. <li>
  197. If one name <var>A</var> is an initial prefix of another
  198. name <var>AB</var> (ignoring case), then <var>B</var> must not
  199. start with '<code>/</code>', as a regular file cannot have the
  200. same name as a directory in POSIX.
  201. For example, <code>America/New_York</code> precludes
  202. <code>America/New_York/Bronx</code>.
  203. </li>
  204. <li>
  205. Uninhabited regions like the North Pole and Bouvet Island
  206. do not need locations, since local time is not defined there.
  207. </li>
  208. <li>
  209. If all the clocks in a timezone have agreed since 1970,
  210. do not bother to include more than one timezone
  211. even if some of the clocks disagreed before 1970.
  212. Otherwise these tables would become annoyingly large.
  213. </li>
  214. <li>
  215. If boundaries between regions are fluid, such as during a war or
  216. insurrection, do not bother to create a new timezone merely
  217. because of yet another boundary change. This helps prevent table
  218. bloat and simplifies maintenance.
  219. </li>
  220. <li>
  221. If a name is ambiguous, use a less ambiguous alternative;
  222. e.g., many cities are named San José and Georgetown, so
  223. prefer <code>America/Costa_Rica</code> to
  224. <code>America/San_Jose</code> and <code>America/Guyana</code>
  225. to <code>America/Georgetown</code>.
  226. </li>
  227. <li>
  228. Keep locations compact.
  229. Use cities or small islands, not countries or regions, so that any
  230. future changes do not split individual locations into different
  231. timezones.
  232. E.g., prefer <code>Europe/Paris</code> to <code>Europe/France</code>,
  233. since
  234. <a href="https://en.wikipedia.org/wiki/Time_in_France#History">France
  235. has had multiple time zones</a>.
  236. </li>
  237. <li>
  238. Use mainstream English spelling, e.g., prefer
  239. <code>Europe/Rome</code> to <code>Europa/Roma</code>, and
  240. prefer <code>Europe/Athens</code> to the Greek
  241. <code>Ευρώπη/Αθήνα</code> or the Romanized
  242. <code>Evrópi/Athína</code>.
  243. The POSIX file name restrictions encourage this guideline.
  244. </li>
  245. <li>
  246. Use the most populous among locations in a region,
  247. e.g., prefer <code>Asia/Shanghai</code> to
  248. <code>Asia/Beijing</code>.
  249. Among locations with similar populations, pick the best-known
  250. location, e.g., prefer <code>Europe/Rome</code> to
  251. <code>Europe/Milan</code>.
  252. </li>
  253. <li>
  254. Use the singular form, e.g., prefer <code>Atlantic/Canary</code> to
  255. <code>Atlantic/Canaries</code>.
  256. </li>
  257. <li>
  258. Omit common suffixes like '<code>_Islands</code>' and
  259. '<code>_City</code>', unless that would lead to ambiguity.
  260. E.g., prefer <code>America/Cayman</code> to
  261. <code>America/Cayman_Islands</code> and
  262. <code>America/Guatemala</code> to
  263. <code>America/Guatemala_City</code>, but prefer
  264. <code>America/Mexico_City</code> to
  265. <code>America/Mexico</code>
  266. because <a href="https://en.wikipedia.org/wiki/Time_in_Mexico">the
  267. country of Mexico has several time zones</a>.
  268. </li>
  269. <li>
  270. Use '<code>_</code>' to represent a space.
  271. </li>
  272. <li>
  273. Omit '<code>.</code>' from abbreviations in names.
  274. E.g., prefer <code>Atlantic/St_Helena</code> to
  275. <code>Atlantic/St._Helena</code>.
  276. </li>
  277. <li>
  278. Do not change established names if they only marginally violate
  279. the above guidelines.
  280. For example, do not change the existing name <code>Europe/Rome</code> to
  281. <code>Europe/Milan</code> merely because Milan's population has grown
  282. to be somewhat greater than Rome's.
  283. </li>
  284. <li>
  285. If a name is changed, put its old spelling in the
  286. '<code>backward</code>' file as a link to the new spelling.
  287. This means old spellings will continue to work.
  288. Ordinarily a name change should occur only in the rare case when
  289. a location's consensus English-language spelling changes; for example,
  290. in 2008 <code>Asia/Calcutta</code> was renamed to <code>Asia/Kolkata</code>
  291. due to long-time widespread use of the new city name instead of the old.
  292. </li>
  293. </ul>
  294. <p>
  295. Guidelines have evolved with time, and names following old versions of
  296. these guidelines might not follow the current version. When guidelines
  297. have changed, old names continue to be supported. Guideline changes
  298. have included the following:
  299. </p>
  300. <ul>
  301. <li>
  302. Older versions of this package used a different naming scheme.
  303. See the file '<code>backward</code>' for most of these older names
  304. (e.g., '<code>US/Eastern</code>' instead of '<code>America/New_York</code>').
  305. The other old-fashioned names still supported are
  306. '<code>WET</code>', '<code>CET</code>', '<code>MET</code>', and
  307. '<code>EET</code>' (see the file '<code>europe</code>').
  308. </li>
  309. <li>
  310. Older versions of this package defined legacy names that are
  311. incompatible with the first guideline of location names, but which are
  312. still supported.
  313. These legacy names are mostly defined in the file
  314. '<code>etcetera</code>'.
  315. Also, the file '<code>backward</code>' defines the legacy names
  316. '<code>Etc/GMT0</code>', '<code>Etc/GMT-0</code>', '<code>Etc/GMT+0</code>',
  317. '<code>GMT0</code>', '<code>GMT-0</code>' and '<code>GMT+0</code>',
  318. and the file '<code>northamerica</code>' defines the legacy names
  319. '<code>EST5EDT</code>', '<code>CST6CDT</code>',
  320. '<code>MST7MDT</code>', and '<code>PST8PDT</code>'.
  321. </li>
  322. <li>
  323. Older versions of these guidelines said that
  324. there should typically be at least one name for each <a
  325. href="https://en.wikipedia.org/wiki/ISO_3166-1"><abbr
  326. title="International Organization for Standardization">ISO</abbr>
  327. 3166-1</a> officially assigned two-letter code for an inhabited
  328. country or territory.
  329. This old guideline has been dropped, as it was not needed to handle
  330. timestamps correctly and it increased maintenance burden.
  331. </li>
  332. </ul>
  333. <p>
  334. The file <code>zone1970.tab</code> lists geographical locations used
  335. to name timezones.
  336. It is intended to be an exhaustive list of names for geographic
  337. regions as described above; this is a subset of the timezones in the data.
  338. Although a <code>zone1970.tab</code> location's
  339. <a href="https://en.wikipedia.org/wiki/Longitude">longitude</a>
  340. corresponds to
  341. its <a href="https://en.wikipedia.org/wiki/Local_mean_time">local mean
  342. time (<abbr>LMT</abbr>)</a> offset with one hour for every 15&deg;
  343. east longitude, this relationship is not exact.
  344. The backward-compatibility file <code>zone.tab</code> is similar
  345. but conforms to the older-version guidelines related to <abbr>ISO</abbr> 3166-1;
  346. it lists only one country code per entry and unlike <code>zone1970.tab</code>
  347. it can list names defined in <code>backward</code>.
  348. </p>
  349. <p>
  350. The database defines each timezone name to be a zone, or a link to a zone.
  351. The source file <code>backward</code> defines links for backward
  352. compatibility; it does not define zones.
  353. Although <code>backward</code> was originally designed to be optional,
  354. nowadays distributions typically use it
  355. and no great weight should be attached to whether a link
  356. is defined in <code>backward</code> or in some other file.
  357. The source file <code>etcetera</code> defines names that may be useful
  358. on platforms that do not support POSIX-style <code>TZ</code> strings;
  359. no other source file other than <code>backward</code>
  360. contains links to its zones.
  361. One of <code>etcetera</code>'s names is <code>Etc/UTC</code>,
  362. used by functions like <code>gmtime</code> to obtain leap
  363. second information on platforms that support leap seconds.
  364. Another <code>etcetera</code> name, <code>GMT</code>,
  365. is used by older code releases.
  366. </p>
  367. </section>
  368. <section>
  369. <h2 id="abbreviations">Time zone abbreviations</h2>
  370. <p>
  371. When this package is installed, it generates time zone abbreviations
  372. like '<code>EST</code>' to be compatible with human tradition and POSIX.
  373. Here are the general guidelines used for choosing time zone abbreviations,
  374. in decreasing order of importance:
  375. </p>
  376. <ul>
  377. <li>
  378. Use three to six characters that are ASCII alphanumerics or
  379. '<code>+</code>' or '<code>-</code>'.
  380. Previous editions of this database also used characters like
  381. space and '<code>?</code>', but these characters have a
  382. special meaning to the
  383. <a href="https://en.wikipedia.org/wiki/Unix_shell">UNIX shell</a>
  384. and cause commands like
  385. '<code><a href="https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#set">set</a>
  386. `<a href="https://pubs.opengroup.org/onlinepubs/9699919799/utilities/date.html">date</a>`</code>'
  387. to have unexpected effects.
  388. Previous editions of this guideline required upper-case letters, but the
  389. Congressman who introduced
  390. <a href="https://en.wikipedia.org/wiki/Chamorro_Time_Zone">Chamorro
  391. Standard Time</a> preferred "ChST", so lower-case letters are now
  392. allowed.
  393. Also, POSIX from 2001 on relaxed the rule to allow '<code>-</code>',
  394. '<code>+</code>', and alphanumeric characters from the portable
  395. character set in the current locale.
  396. In practice ASCII alphanumerics and '<code>+</code>' and
  397. '<code>-</code>' are safe in all locales.
  398. <p>
  399. In other words, in the C locale the POSIX extended regular
  400. expression <code>[-+[:alnum:]]{3,6}</code> should match the
  401. abbreviation.
  402. This guarantees that all abbreviations could have been specified by a
  403. POSIX <code>TZ</code> string.
  404. </p>
  405. </li>
  406. <li>
  407. Use abbreviations that are in common use among English-speakers,
  408. e.g., 'EST' for Eastern Standard Time in North America.
  409. We assume that applications translate them to other languages
  410. as part of the normal localization process; for example,
  411. a French application might translate 'EST' to 'HNE'.
  412. <p>
  413. <small>These abbreviations (for standard/daylight/etc. time) are:
  414. ACST/ACDT Australian Central,
  415. AST/ADT/APT/AWT/ADDT Atlantic,
  416. AEST/AEDT Australian Eastern,
  417. AHST/AHDT Alaska-Hawaii,
  418. AKST/AKDT Alaska,
  419. AWST/AWDT Australian Western,
  420. BST/BDT Bering,
  421. CAT/CAST Central Africa,
  422. CET/CEST/CEMT Central European,
  423. ChST Chamorro,
  424. CST/CDT/CWT/CPT Central [North America],
  425. CST/CDT China,
  426. GMT/BST/IST/BDST Greenwich,
  427. EAT East Africa,
  428. EST/EDT/EWT/EPT Eastern [North America],
  429. EET/EEST Eastern European,
  430. GST/GDT Guam,
  431. HST/HDT/HWT/HPT Hawaii,
  432. HKT/HKST/HKWT Hong Kong,
  433. IST India,
  434. IST/GMT Irish,
  435. IST/IDT/IDDT Israel,
  436. JST/JDT Japan,
  437. KST/KDT Korea,
  438. MET/MEST Middle European (a backward-compatibility alias for
  439. Central European),
  440. MSK/MSD Moscow,
  441. MST/MDT/MWT/MPT Mountain,
  442. NST/NDT/NWT/NPT/NDDT Newfoundland,
  443. NST/NDT/NWT/NPT Nome,
  444. NZMT/NZST New Zealand through 1945,
  445. NZST/NZDT New Zealand 1946&ndash;present,
  446. PKT/PKST Pakistan,
  447. PST/PDT/PWT/PPT Pacific,
  448. PST/PDT Philippine,
  449. SAST South Africa,
  450. SST Samoa,
  451. UTC Universal,
  452. WAT/WAST West Africa,
  453. WET/WEST/WEMT Western European,
  454. WIB Waktu Indonesia Barat,
  455. WIT Waktu Indonesia Timur,
  456. WITA Waktu Indonesia Tengah,
  457. YST/YDT/YWT/YPT/YDDT Yukon</small>.
  458. </p>
  459. </li>
  460. <li>
  461. <p>
  462. For times taken from a city's longitude, use the
  463. traditional <var>x</var>MT notation.
  464. The only abbreviation like this in current use is '<abbr>GMT</abbr>'.
  465. The others are for timestamps before 1960,
  466. except that Monrovia Mean Time persisted until 1972.
  467. Typically, numeric abbreviations (e.g., '<code>-</code>004430' for
  468. MMT) would cause trouble here, as the numeric strings would exceed
  469. the POSIX length limit.
  470. </p>
  471. <p>
  472. <small>These abbreviations are:
  473. AMT Asunción, Athens;
  474. BMT Baghdad, Bangkok, Batavia, Bermuda, Bern, Bogotá,
  475. Brussels, Bucharest;
  476. CMT Calamarca, Caracas, Chisinau, Colón, Córdoba;
  477. DMT Dublin/Dunsink;
  478. EMT Easter;
  479. FFMT Fort-de-France;
  480. FMT Funchal;
  481. GMT Greenwich;
  482. HMT Havana, Helsinki, Horta, Howrah;
  483. IMT Irkutsk, Istanbul;
  484. JMT Jerusalem;
  485. KMT Kaunas, Kyiv, Kingston;
  486. LMT Lima, Lisbon, local;
  487. MMT Macassar, Madras, Malé, Managua, Minsk, Monrovia, Montevideo,
  488. Moratuwa, Moscow;
  489. PLMT Phù Liễn;
  490. PMT Paramaribo, Paris, Perm, Pontianak, Prague;
  491. PMMT Port Moresby;
  492. PPMT Port-au-Prince;
  493. QMT Quito;
  494. RMT Rangoon, Riga, Rome;
  495. SDMT Santo Domingo;
  496. SJMT San José;
  497. SMT Santiago, Simferopol, Singapore, Stanley;
  498. TBMT Tbilisi;
  499. TMT Tallinn, Tehran;
  500. WMT Warsaw.</small>
  501. </p>
  502. <p>
  503. <small>A few abbreviations also follow the pattern that
  504. <abbr>GMT</abbr>/<abbr>BST</abbr> established for time in the UK.
  505. They are:
  506. BMT/BST for Bermuda 1890&ndash;1930,
  507. CMT/BST for Calamarca Mean Time and Bolivian Summer Time
  508. 1890&ndash;1932,
  509. DMT/IST for Dublin/Dunsink Mean Time and Irish Summer Time
  510. 1880&ndash;1916,
  511. MMT/MST/MDST for Moscow 1880&ndash;1919, and
  512. RMT/LST for Riga Mean Time and Latvian Summer time 1880&ndash;1926.
  513. </small>
  514. </p>
  515. </li>
  516. <li>
  517. Use '<abbr>LMT</abbr>' for local mean time of locations before the
  518. introduction of standard time; see "<a href="#scope">Scope of the
  519. <code><abbr>tz</abbr></code> database</a>".
  520. </li>
  521. <li>
  522. If there is no common English abbreviation, use numeric offsets like
  523. <code>-</code>05 and <code>+</code>0530 that are generated
  524. by <code>zic</code>'s <code>%z</code> notation.
  525. </li>
  526. <li>
  527. Use current abbreviations for older timestamps to avoid confusion.
  528. For example, in 1910 a common English abbreviation for time
  529. in central Europe was 'MEZ' (short for both "Middle European
  530. Zone" and for "Mitteleuropäische Zeit" in German).
  531. Nowadays 'CET' ("Central European Time") is more common in
  532. English, and the database uses 'CET' even for circa-1910
  533. timestamps as this is less confusing for modern users and avoids
  534. the need for determining when 'CET' supplanted 'MEZ' in common
  535. usage.
  536. </li>
  537. <li>
  538. Use a consistent style in a timezone's history.
  539. For example, if a history tends to use numeric
  540. abbreviations and a particular entry could go either way, use a
  541. numeric abbreviation.
  542. </li>
  543. <li>
  544. Use
  545. <a href="https://en.wikipedia.org/wiki/Universal_Time">Universal Time</a>
  546. (<abbr>UT</abbr>) (with time zone abbreviation '<code>-</code>00') for
  547. locations while uninhabited.
  548. The leading '<code>-</code>' is a flag that the <abbr>UT</abbr> offset is in
  549. some sense undefined; this notation is derived
  550. from <a href="https://datatracker.ietf.org/doc/html/rfc3339">Internet
  551. <abbr title="Request For Comments">RFC</abbr> 3339</a>.
  552. </li>
  553. </ul>
  554. <p>
  555. Application writers should note that these abbreviations are ambiguous
  556. in practice: e.g., 'CST' means one thing in China and something else
  557. in North America, and 'IST' can refer to time in India, Ireland or
  558. Israel.
  559. To avoid ambiguity, use numeric <abbr>UT</abbr> offsets like
  560. '<code>-</code>0600' instead of time zone abbreviations like 'CST'.
  561. </p>
  562. </section>
  563. <section>
  564. <h2 id="accuracy">Accuracy of the <code><abbr>tz</abbr></code> database</h2>
  565. <p>
  566. The <code><abbr>tz</abbr></code> database is not authoritative, and it
  567. surely has errors.
  568. Corrections are welcome and encouraged; see the file <code>CONTRIBUTING</code>.
  569. Users requiring authoritative data should consult national standards
  570. bodies and the references cited in the database's comments.
  571. </p>
  572. <p>
  573. Errors in the <code><abbr>tz</abbr></code> database arise from many sources:
  574. </p>
  575. <ul>
  576. <li>
  577. The <code><abbr>tz</abbr></code> database predicts future
  578. timestamps, and current predictions
  579. will be incorrect after future governments change the rules.
  580. For example, if today someone schedules a meeting for 13:00 next
  581. October 1, Casablanca time, and tomorrow Morocco changes its
  582. daylight saving rules, software can mess up after the rule change
  583. if it blithely relies on conversions made before the change.
  584. </li>
  585. <li>
  586. The pre-1970 entries in this database cover only a tiny sliver of how
  587. clocks actually behaved; the vast majority of the necessary
  588. information was lost or never recorded.
  589. Thousands more timezones would be needed if
  590. the <code><abbr>tz</abbr></code> database's scope were extended to
  591. cover even just the known or guessed history of standard time; for
  592. example, the current single entry for France would need to split
  593. into dozens of entries, perhaps hundreds.
  594. And in most of the world even this approach would be misleading
  595. due to widespread disagreement or indifference about what times
  596. should be observed.
  597. In her 2015 book
  598. <cite><a
  599. href="https://www.hup.harvard.edu/catalog.php?isbn=9780674286146">The
  600. Global Transformation of Time, 1870&ndash;1950</a></cite>,
  601. Vanessa Ogle writes
  602. "Outside of Europe and North America there was no system of time
  603. zones at all, often not even a stable landscape of mean times,
  604. prior to the middle decades of the twentieth century".
  605. See: Timothy Shenk, <a
  606. href="https://www.dissentmagazine.org/blog/booked-a-global-history-of-time-vanessa-ogle">Booked:
  607. A Global History of Time</a>. <cite>Dissent</cite> 2015-12-17.
  608. </li>
  609. <li>
  610. Most of the pre-1970 data entries come from unreliable sources, often
  611. astrology books that lack citations and whose compilers evidently
  612. invented entries when the true facts were unknown, without
  613. reporting which entries were known and which were invented.
  614. These books often contradict each other or give implausible entries,
  615. and on the rare occasions when they are checked they are
  616. typically found to be incorrect.
  617. </li>
  618. <li>
  619. For the UK the <code><abbr>tz</abbr></code> database relies on
  620. years of first-class work done by
  621. Joseph Myers and others; see
  622. "<a href="https://www.polyomino.org.uk/british-time/">History of
  623. legal time in Britain</a>".
  624. Other countries are not done nearly as well.
  625. </li>
  626. <li>
  627. Sometimes, different people in the same city maintain clocks
  628. that differ significantly.
  629. Historically, railway time was used by railroad companies (which
  630. did not always
  631. agree with each other), church-clock time was used for birth
  632. certificates, etc.
  633. More recently, competing political groups might disagree about
  634. clock settings. Often this is merely common practice, but
  635. sometimes it is set by law.
  636. For example, from 1891 to 1911 the <abbr>UT</abbr> offset in France
  637. was legally <abbr>UT</abbr> +00:09:21 outside train stations and
  638. <abbr>UT</abbr> +00:04:21 inside. Other examples include
  639. Chillicothe in 1920, Palm Springs in 1946/7, and Jerusalem and
  640. Ürümqi to this day.
  641. </li>
  642. <li>
  643. Although a named location in the <code><abbr>tz</abbr></code>
  644. database stands for the containing region, its pre-1970 data
  645. entries are often accurate for only a small subset of that region.
  646. For example, <code>Europe/London</code> stands for the United
  647. Kingdom, but its pre-1847 times are valid only for locations that
  648. have London's exact meridian, and its 1847 transition
  649. to <abbr>GMT</abbr> is known to be valid only for the L&amp;NW and
  650. the Caledonian railways.
  651. </li>
  652. <li>
  653. The <code><abbr>tz</abbr></code> database does not record the
  654. earliest time for which a timezone's
  655. data entries are thereafter valid for every location in the region.
  656. For example, <code>Europe/London</code> is valid for all locations
  657. in its region after <abbr>GMT</abbr> was made the standard time,
  658. but the date of standardization (1880-08-02) is not in the
  659. <code><abbr>tz</abbr></code> database, other than in commentary.
  660. For many timezones the earliest time of
  661. validity is unknown.
  662. </li>
  663. <li>
  664. The <code><abbr>tz</abbr></code> database does not record a
  665. region's boundaries, and in many cases the boundaries are not known.
  666. For example, the timezone
  667. <code>America/Kentucky/Louisville</code> represents a region
  668. around the city of Louisville, the boundaries of which are
  669. unclear.
  670. </li>
  671. <li>
  672. Changes that are modeled as instantaneous transitions in the
  673. <code><abbr>tz</abbr></code>
  674. database were often spread out over hours, days, or even decades.
  675. </li>
  676. <li>
  677. Even if the time is specified by law, locations sometimes
  678. deliberately flout the law.
  679. </li>
  680. <li>
  681. Early timekeeping practices, even assuming perfect clocks, were
  682. often not specified to the accuracy that the
  683. <code><abbr>tz</abbr></code> database requires.
  684. </li>
  685. <li>
  686. The <code><abbr>tz</abbr></code> database cannot represent stopped clocks.
  687. However, on 1911-03-11 at 00:00, some public-facing French clocks
  688. were changed by stopping them for a few minutes to effect a transition.
  689. The <code><abbr>tz</abbr></code> database models this via a
  690. backward transition; the relevant French legislation does not
  691. specify exactly how the transition was to occur.
  692. </li>
  693. <li>
  694. Sometimes historical timekeeping was specified more precisely
  695. than what the <code><abbr>tz</abbr></code> code can handle.
  696. For example, from 1880 to 1916 clocks in Ireland observed Dublin Mean
  697. Time (estimated to be <abbr>UT</abbr>
  698. &minus;00:25:21.1); although the <code><abbr>tz</abbr></code>
  699. source data can represent the .1 second, TZif files and the code cannot.
  700. In practice these old specifications were rarely if ever
  701. implemented to subsecond precision.
  702. </li>
  703. <li>
  704. Even when all the timestamp transitions recorded by the
  705. <code><abbr>tz</abbr></code> database are correct, the
  706. <code><abbr>tz</abbr></code> rules that generate them may not
  707. faithfully reflect the historical rules.
  708. For example, from 1922 until World War II the UK moved clocks
  709. forward the day following the third Saturday in April unless that
  710. was Easter, in which case it moved clocks forward the previous
  711. Sunday.
  712. Because the <code><abbr>tz</abbr></code> database has no
  713. way to specify Easter, these exceptional years are entered as
  714. separate <code><abbr>tz</abbr> Rule</code> lines, even though the
  715. legal rules did not change.
  716. When transitions are known but the historical rules behind them are not,
  717. the database contains <code>Zone</code> and <code>Rule</code>
  718. entries that are intended to represent only the generated
  719. transitions, not any underlying historical rules; however, this
  720. intent is recorded at best only in commentary.
  721. </li>
  722. <li>
  723. The <code><abbr>tz</abbr></code> database models time
  724. using the <a
  725. href="https://en.wikipedia.org/wiki/Proleptic_Gregorian_calendar">proleptic
  726. Gregorian calendar</a> with days containing 24 equal-length hours
  727. numbered 00 through 23, except when clock transitions occur.
  728. Pre-standard time is modeled as local mean time.
  729. However, historically many people used other calendars and other timescales.
  730. For example, the Roman Empire used
  731. the <a href="https://en.wikipedia.org/wiki/Julian_calendar">Julian
  732. calendar</a>,
  733. and <a href="https://en.wikipedia.org/wiki/Roman_timekeeping">Roman
  734. timekeeping</a> had twelve varying-length daytime hours with a
  735. non-hour-based system at night.
  736. And even today, some local practices diverge from the Gregorian
  737. calendar with 24-hour days. These divergences range from
  738. relatively minor, such as Japanese bars giving times like "24:30" for the
  739. wee hours of the morning, to more-significant differences such as <a
  740. href="https://www.pri.org/stories/2015-01-30/if-you-have-meeting-ethiopia-you-better-double-check-time">the
  741. east African practice of starting the day at dawn</a>, renumbering
  742. the Western 06:00 to be 12:00. These practices are largely outside
  743. the scope of the <code><abbr>tz</abbr></code> code and data, which
  744. provide only limited support for date and time localization
  745. such as that required by POSIX.
  746. If <abbr>DST</abbr> is not used a different time zone
  747. can often do the trick; for example, in Kenya a <code>TZ</code> setting
  748. like <code>&lt;-03&gt;3</code> or <code>America/Cayenne</code> starts
  749. the day six hours later than <code>Africa/Nairobi</code> does.
  750. </li>
  751. <li>
  752. Early clocks were less reliable, and data entries do not represent
  753. clock error.
  754. </li>
  755. <li>
  756. The <code><abbr>tz</abbr></code> database assumes Universal Time
  757. (<abbr>UT</abbr>) as an origin, even though <abbr>UT</abbr> is not
  758. standardized for older timestamps.
  759. In the <code><abbr>tz</abbr></code> database commentary,
  760. <abbr>UT</abbr> denotes a family of time standards that includes
  761. Coordinated Universal Time (<abbr>UTC</abbr>) along with other
  762. variants such as <abbr>UT1</abbr> and <abbr>GMT</abbr>,
  763. with days starting at midnight.
  764. Although <abbr>UT</abbr> equals <abbr>UTC</abbr> for modern
  765. timestamps, <abbr>UTC</abbr> was not defined until 1960, so
  766. commentary uses the more general abbreviation <abbr>UT</abbr> for
  767. timestamps that might predate 1960.
  768. Since <abbr>UT</abbr>, <abbr>UT1</abbr>, etc. disagree slightly,
  769. and since pre-1972 <abbr>UTC</abbr> seconds varied in length,
  770. interpretation of older timestamps can be problematic when
  771. subsecond accuracy is needed.
  772. </li>
  773. <li>
  774. Civil time was not based on atomic time before 1972, and we do not
  775. know the history of
  776. <a href="https://en.wikipedia.org/wiki/Earth's_rotation">earth's
  777. rotation</a> accurately enough to map <a
  778. href="https://en.wikipedia.org/wiki/International_System_of_Units"><abbr
  779. title="International System of Units">SI</abbr></a> seconds to
  780. historical <a href="https://en.wikipedia.org/wiki/Solar_time">solar time</a>
  781. to more than about one-hour accuracy.
  782. See: Stephenson FR, Morrison LV, Hohenkerk CY.
  783. <a href="https://dx.doi.org/10.1098/rspa.2016.0404">Measurement of
  784. the Earth's rotation: 720 BC to AD 2015</a>.
  785. <cite>Proc Royal Soc A</cite>. 2016;472:20160404.
  786. Also see: Espenak F. <a
  787. href="https://eclipse.gsfc.nasa.gov/SEhelp/uncertainty2004.html">Uncertainty
  788. in Delta T (ΔT)</a>.
  789. </li>
  790. <li>
  791. The relationship between POSIX time (that is, <abbr>UTC</abbr> but
  792. ignoring <a href="https://en.wikipedia.org/wiki/Leap_second">leap
  793. seconds</a>) and <abbr>UTC</abbr> is not agreed upon.
  794. This affects time stamps during the leap second era (1972&ndash;2035).
  795. Although the POSIX
  796. clock officially stops during an inserted leap second, at least one
  797. proposed standard has it jumping back a second instead; and in
  798. practice POSIX clocks more typically either progress glacially during
  799. a leap second, or are slightly slowed while near a leap second.
  800. </li>
  801. <li>
  802. The <code><abbr>tz</abbr></code> database does not represent how
  803. uncertain its information is.
  804. Ideally it would contain information about when data entries are
  805. incomplete or dicey.
  806. Partial temporal knowledge is a field of active research, though,
  807. and it is not clear how to apply it here.
  808. </li>
  809. </ul>
  810. <p>
  811. In short, many, perhaps most, of the <code><abbr>tz</abbr></code>
  812. database's pre-1970 and future timestamps are either wrong or
  813. misleading.
  814. Any attempt to pass the
  815. <code><abbr>tz</abbr></code> database off as the definition of time
  816. should be unacceptable to anybody who cares about the facts.
  817. In particular, the <code><abbr>tz</abbr></code> database's
  818. <abbr>LMT</abbr> offsets should not be considered meaningful, and
  819. should not prompt creation of timezones
  820. merely because two locations
  821. differ in <abbr>LMT</abbr> or transitioned to standard time at
  822. different dates.
  823. </p>
  824. </section>
  825. <section>
  826. <h2 id="functions">Time and date functions</h2>
  827. <p>
  828. The <code><abbr>tz</abbr></code> code contains time and date functions
  829. that are upwards compatible with those of POSIX.
  830. Code compatible with this package is already
  831. <a href="tz-link.html#tzdb">part of many platforms</a>, where the
  832. primary use of this package is to update obsolete time-related files.
  833. To do this, you may need to compile the time zone compiler
  834. '<code>zic</code>' supplied with this package instead of using the
  835. system '<code>zic</code>', since the format of <code>zic</code>'s
  836. input is occasionally extended, and a platform may still be shipping
  837. an older <code>zic</code>.
  838. </p>
  839. <h3 id="POSIX">POSIX properties and limitations</h3>
  840. <ul>
  841. <li>
  842. <p>
  843. In POSIX, time display in a process is controlled by the
  844. environment variable <code>TZ</code>.
  845. Unfortunately, the POSIX
  846. <code>TZ</code> string takes a form that is hard to describe and
  847. is error-prone in practice.
  848. Also, POSIX <code>TZ</code> strings cannot deal with daylight
  849. saving time rules not based on the Gregorian calendar (as in
  850. Morocco), or with situations where more than two time zone
  851. abbreviations or <abbr>UT</abbr> offsets are used in an area.
  852. </p>
  853. <p>
  854. The POSIX <code>TZ</code> string takes the following form:
  855. </p>
  856. <p>
  857. <var>stdoffset</var>[<var>dst</var>[<var>offset</var>][<code>,</code><var>date</var>[<code>/</code><var>time</var>]<code>,</code><var>date</var>[<code>/</code><var>time</var>]]]
  858. </p>
  859. <p>
  860. where:
  861. </p>
  862. <dl>
  863. <dt><var>std</var> and <var>dst</var></dt><dd>
  864. are 3 or more characters specifying the standard
  865. and daylight saving time (<abbr>DST</abbr>) zone abbreviations.
  866. Starting with POSIX.1-2001, <var>std</var> and <var>dst</var>
  867. may also be in a quoted form like '<code>&lt;+09&gt;</code>';
  868. this allows "<code>+</code>" and "<code>-</code>" in the names.
  869. </dd>
  870. <dt><var>offset</var></dt><dd>
  871. is of the form
  872. '<code>[&plusmn;]<var>hh</var>:[<var>mm</var>[:<var>ss</var>]]</code>'
  873. and specifies the offset west of <abbr>UT</abbr>.
  874. '<var>hh</var>' may be a single digit;
  875. 0&le;<var>hh</var>&le;24.
  876. The default <abbr>DST</abbr> offset is one hour ahead of
  877. standard time.
  878. </dd>
  879. <dt><var>date</var>[<code>/</code><var>time</var>]<code>,</code><var>date</var>[<code>/</code><var>time</var>]</dt><dd>
  880. specifies the beginning and end of <abbr>DST</abbr>.
  881. If this is absent, the system supplies its own ruleset
  882. for <abbr>DST</abbr>, typically current <abbr>US</abbr>
  883. <abbr>DST</abbr> rules.
  884. </dd>
  885. <dt><var>time</var></dt><dd>
  886. takes the form
  887. '<var>hh</var><code>:</code>[<var>mm</var>[<code>:</code><var>ss</var>]]'
  888. and defaults to 02:00.
  889. This is the same format as the offset, except that a
  890. leading '<code>+</code>' or '<code>-</code>' is not allowed.
  891. </dd>
  892. <dt><var>date</var></dt><dd>
  893. takes one of the following forms:
  894. <dl>
  895. <dt>J<var>n</var> (1&le;<var>n</var>&le;365)</dt><dd>
  896. origin-1 day number not counting February 29
  897. </dd>
  898. <dt><var>n</var> (0&le;<var>n</var>&le;365)</dt><dd>
  899. origin-0 day number counting February 29 if present
  900. </dd>
  901. <dt><code>M</code><var>m</var><code>.</code><var>n</var><code>.</code><var>d</var>
  902. (0[Sunday]&le;<var>d</var>&le;6[Saturday], 1&le;<var>n</var>&le;5,
  903. 1&le;<var>m</var>&le;12)</dt><dd>
  904. for the <var>d</var>th day of week <var>n</var> of
  905. month <var>m</var> of the year, where week 1 is the first
  906. week in which day <var>d</var> appears, and
  907. '<code>5</code>' stands for the last week in which
  908. day <var>d</var> appears (which may be either the 4th or
  909. 5th week).
  910. Typically, this is the only useful form; the <var>n</var>
  911. and <code>J</code><var>n</var> forms are rarely used.
  912. </dd>
  913. </dl>
  914. </dd>
  915. </dl>
  916. <p>
  917. Here is an example POSIX <code>TZ</code> string for New
  918. Zealand after 2007.
  919. It says that standard time (<abbr>NZST</abbr>) is 12 hours ahead
  920. of <abbr>UT</abbr>, and that daylight saving time
  921. (<abbr>NZDT</abbr>) is observed from September's last Sunday at
  922. 02:00 until April's first Sunday at 03:00:
  923. </p>
  924. <pre><code>TZ='NZST-12NZDT,M9.5.0,M4.1.0/3'</code></pre>
  925. <p>
  926. This POSIX <code>TZ</code> string is hard to remember, and
  927. mishandles some timestamps before 2008.
  928. With this package you can use this instead:
  929. </p>
  930. <pre><code>TZ='Pacific/Auckland'</code></pre>
  931. </li>
  932. <li>
  933. POSIX does not define the <abbr>DST</abbr> transitions
  934. for <code>TZ</code> values like
  935. "<code>EST5EDT</code>".
  936. Traditionally the current <abbr>US</abbr> <abbr>DST</abbr> rules
  937. were used to interpret such values, but this meant that the
  938. <abbr>US</abbr> <abbr>DST</abbr> rules were compiled into each
  939. time conversion package, and when
  940. <abbr>US</abbr> time conversion rules changed (as in the United
  941. States in 1987 and again in 2007), all packages that
  942. interpreted <code>TZ</code> values had to be updated
  943. to ensure proper results.
  944. </li>
  945. <li>
  946. The <code>TZ</code> environment variable is process-global, which
  947. makes it hard to write efficient, thread-safe applications that
  948. need access to multiple timezones.
  949. </li>
  950. <li>
  951. In POSIX, there is no tamper-proof way for a process to learn the
  952. system's best idea of local (wall clock) time.
  953. This is important for applications that an administrator wants
  954. used only at certain times &ndash; without regard to whether the
  955. user has fiddled the
  956. <code>TZ</code> environment variable.
  957. While an administrator can "do everything in <abbr>UT</abbr>" to
  958. get around the problem, doing so is inconvenient and precludes
  959. handling daylight saving time shifts &ndash; as might be required to
  960. limit phone calls to off-peak hours.
  961. </li>
  962. <li>
  963. POSIX provides no convenient and efficient way to determine
  964. the <abbr>UT</abbr> offset and time zone abbreviation of arbitrary
  965. timestamps, particularly for timezones
  966. that do not fit into the POSIX model.
  967. </li>
  968. <li>
  969. POSIX requires that <code>time_t</code> clock counts exclude leap
  970. seconds.
  971. </li>
  972. <li>
  973. The <code><abbr>tz</abbr></code> code attempts to support all the
  974. <code>time_t</code> implementations allowed by POSIX.
  975. The <code>time_t</code> type represents a nonnegative count of seconds
  976. since 1970-01-01 00:00:00 <abbr>UTC</abbr>, ignoring leap seconds.
  977. In practice, <code>time_t</code> is usually a signed 64- or 32-bit
  978. integer; 32-bit signed <code>time_t</code> values stop working after
  979. 2038-01-19 03:14:07 <abbr>UTC</abbr>, so new implementations these
  980. days typically use a signed 64-bit integer.
  981. Unsigned 32-bit integers are used on one or two platforms, and 36-bit
  982. and 40-bit integers are also used occasionally.
  983. Although earlier POSIX versions allowed <code>time_t</code> to be a
  984. floating-point type, this was not supported by any practical system,
  985. and POSIX.1-2013 and the <code><abbr>tz</abbr></code> code both
  986. require <code>time_t</code> to be an integer type.
  987. </li>
  988. </ul>
  989. <h3 id="POSIX-extensions">Extensions to POSIX in the
  990. <code><abbr>tz</abbr></code> code</h3>
  991. <ul>
  992. <li>
  993. <p>
  994. The <code>TZ</code> environment variable is used in generating
  995. the name of a file from which time-related information is read
  996. (or is interpreted à la POSIX); <code>TZ</code> is no longer
  997. constrained to be a string containing abbreviations
  998. and numeric data as described <a href="#POSIX">above</a>.
  999. The file's format is <dfn><abbr>TZif</abbr></dfn>,
  1000. a timezone information format that contains binary data; see
  1001. <a href="https://datatracker.ietf.org/doc/html/8536">Internet
  1002. <abbr>RFC</abbr> 8536</a>.
  1003. The daylight saving time rules to be used for a
  1004. particular timezone are encoded in the
  1005. <abbr>TZif</abbr> file; the format of the file allows <abbr>US</abbr>,
  1006. Australian, and other rules to be encoded, and
  1007. allows for situations where more than two time zone
  1008. abbreviations are used.
  1009. </p>
  1010. <p>
  1011. It was recognized that allowing the <code>TZ</code> environment
  1012. variable to take on values such as '<code>America/New_York</code>'
  1013. might cause "old" programs (that expect <code>TZ</code> to have a
  1014. certain form) to operate incorrectly; consideration was given to using
  1015. some other environment variable (for example, <code>TIMEZONE</code>)
  1016. to hold the string used to generate the <abbr>TZif</abbr> file's name.
  1017. In the end, however, it was decided to continue using
  1018. <code>TZ</code>: it is widely used for time zone purposes;
  1019. separately maintaining both <code>TZ</code>
  1020. and <code>TIMEZONE</code> seemed a nuisance; and systems where
  1021. "new" forms of <code>TZ</code> might cause problems can simply
  1022. use legacy <code>TZ</code> values such as "<code>EST5EDT</code>" which
  1023. can be used by "new" programs as well as by "old" programs that
  1024. assume pre-POSIX <code>TZ</code> values.
  1025. </p>
  1026. </li>
  1027. <li>
  1028. The code supports platforms with a <abbr>UT</abbr> offset member
  1029. in <code>struct tm</code>, e.g., <code>tm_gmtoff</code>,
  1030. or with a time zone abbreviation member in
  1031. <code>struct tm</code>, e.g., <code>tm_zone</code>. As noted
  1032. in <a href="https://austingroupbugs.net/view.php?id=1533">Austin
  1033. Group defect 1533</a>, a future version of POSIX is planned to
  1034. require <code>tm_gmtoff</code> and <code>tm_zone</code>.
  1035. </li>
  1036. <li>
  1037. Functions <code>tzalloc</code>, <code>tzfree</code>,
  1038. <code>localtime_rz</code>, and <code>mktime_z</code> for
  1039. more-efficient thread-safe applications that need to use multiple
  1040. timezones.
  1041. The <code>tzalloc</code> and <code>tzfree</code> functions
  1042. allocate and free objects of type <code>timezone_t</code>,
  1043. and <code>localtime_rz</code> and <code>mktime_z</code> are
  1044. like <code>localtime_r</code> and <code>mktime</code> with an
  1045. extra <code>timezone_t</code> argument.
  1046. The functions were inspired by <a href="https://netbsd.org/">NetBSD</a>.
  1047. </li>
  1048. <li>
  1049. Negative <code>time_t</code> values are supported, on systems
  1050. where <code>time_t</code> is signed.
  1051. </li>
  1052. <li>
  1053. These functions can account for leap seconds;
  1054. see <a href="#leapsec">Leap seconds</a> below.
  1055. </li>
  1056. </ul>
  1057. <h3 id="vestigial">POSIX features no longer needed</h3>
  1058. <p>
  1059. POSIX and <a href="https://en.wikipedia.org/wiki/ISO_C"><abbr>ISO</abbr> C</a>
  1060. define some <a href="https://en.wikipedia.org/wiki/API"><abbr
  1061. title="application programming interface">API</abbr>s</a> that are vestigial:
  1062. they are not needed, and are relics of a too-simple model that does
  1063. not suffice to handle many real-world timestamps.
  1064. Although the <code><abbr>tz</abbr></code> code supports these
  1065. vestigial <abbr>API</abbr>s for backwards compatibility, they should
  1066. be avoided in portable applications.
  1067. The vestigial <abbr>API</abbr>s are:
  1068. </p>
  1069. <ul>
  1070. <li>
  1071. The POSIX <code>tzname</code> variable does not suffice and is no
  1072. longer needed.
  1073. To get a timestamp's time zone abbreviation, consult
  1074. the <code>tm_zone</code> member if available; otherwise,
  1075. use <code>strftime</code>'s <code>"%Z"</code> conversion
  1076. specification.
  1077. </li>
  1078. <li>
  1079. The POSIX <code>daylight</code> and <code>timezone</code>
  1080. variables do not suffice and are no longer needed.
  1081. To get a timestamp's <abbr>UT</abbr> offset, consult
  1082. the <code>tm_gmtoff</code> member if available; otherwise,
  1083. subtract values returned by <code>localtime</code>
  1084. and <code>gmtime</code> using the rules of the Gregorian calendar,
  1085. or use <code>strftime</code>'s <code>"%z"</code> conversion
  1086. specification if a string like <code>"+0900"</code> suffices.
  1087. </li>
  1088. <li>
  1089. The <code>tm_isdst</code> member is almost never needed and most of
  1090. its uses should be discouraged in favor of the abovementioned
  1091. <abbr>API</abbr>s.
  1092. Although it can still be used in arguments to
  1093. <code>mktime</code> to disambiguate timestamps near
  1094. a <abbr>DST</abbr> transition when the clock jumps back on
  1095. platforms lacking <code>tm_gmtoff</code>, this
  1096. disambiguation does not work when standard time itself jumps back,
  1097. which can occur when a location changes to a time zone with a
  1098. lesser <abbr>UT</abbr> offset.
  1099. </li>
  1100. </ul>
  1101. <h3 id="other-portability">Other portability notes</h3>
  1102. <ul>
  1103. <li>
  1104. The <a href="https://en.wikipedia.org/wiki/Version_7_Unix">7th Edition
  1105. UNIX</a> <code>timezone</code> function is not present in this
  1106. package; it is impossible to reliably map <code>timezone</code>'s
  1107. arguments (a "minutes west of <abbr>GMT</abbr>" value and a
  1108. "daylight saving time in effect" flag) to a time zone
  1109. abbreviation, and we refuse to guess.
  1110. Programs that in the past used the <code>timezone</code> function
  1111. may now examine <code>localtime(&amp;clock)-&gt;tm_zone</code>
  1112. (if <code>TM_ZONE</code> is defined) or
  1113. <code>tzname[localtime(&amp;clock)-&gt;tm_isdst]</code>
  1114. (if <code>HAVE_TZNAME</code> is nonzero) to learn the correct time
  1115. zone abbreviation to use.
  1116. </li>
  1117. <li>
  1118. The <a
  1119. href="https://en.wikipedia.org/wiki/History_of_the_Berkeley_Software_Distribution#4.2BSD"><abbr>4.2BSD</abbr></a>
  1120. <code>gettimeofday</code> function is not
  1121. used in this package.
  1122. This formerly let users obtain the current <abbr>UTC</abbr> offset
  1123. and <abbr>DST</abbr> flag, but this functionality was removed in
  1124. later versions of <abbr>BSD</abbr>.
  1125. </li>
  1126. <li>
  1127. In <abbr>SVR2</abbr>, time conversion fails for near-minimum or
  1128. near-maximum <code>time_t</code> values when doing conversions
  1129. for places that do not use <abbr>UT</abbr>.
  1130. This package takes care to do these conversions correctly.
  1131. A comment in the source code tells how to get compatibly wrong
  1132. results.
  1133. </li>
  1134. <li>
  1135. The functions that are conditionally compiled
  1136. if <code>STD_INSPIRED</code> is nonzero should, at this point, be
  1137. looked on primarily as food for thought.
  1138. They are not in any sense "standard compatible" &ndash; some are
  1139. not, in fact, specified in <em>any</em> standard.
  1140. They do, however, represent responses of various authors to
  1141. standardization proposals.
  1142. </li>
  1143. <li>
  1144. Other time conversion proposals, in particular those supported by the
  1145. <a href="https://howardhinnant.github.io/date/tz.html">Time Zone
  1146. Database Parser</a>, offer a wider selection of functions
  1147. that provide capabilities beyond those provided here.
  1148. The absence of such functions from this package is not meant to
  1149. discourage the development, standardization, or use of such
  1150. functions.
  1151. Rather, their absence reflects the decision to make this package
  1152. contain valid extensions to POSIX, to ensure its broad
  1153. acceptability.
  1154. If more powerful time conversion functions can be standardized, so
  1155. much the better.
  1156. </li>
  1157. </ul>
  1158. </section>
  1159. <section>
  1160. <h2 id="stability">Interface stability</h2>
  1161. <p>
  1162. The <code><abbr>tz</abbr></code> code and data supply the following interfaces:
  1163. </p>
  1164. <ul>
  1165. <li>
  1166. A set of timezone names as per
  1167. "<a href="#naming">Timezone identifiers</a>" above.
  1168. </li>
  1169. <li>
  1170. Library functions described in "<a href="#functions">Time and date
  1171. functions</a>" above.
  1172. </li>
  1173. <li>
  1174. The programs <code>tzselect</code>, <code>zdump</code>,
  1175. and <code>zic</code>, documented in their man pages.
  1176. </li>
  1177. <li>
  1178. The format of <code>zic</code> input files, documented in
  1179. the <code>zic</code> man page.
  1180. </li>
  1181. <li>
  1182. The format of <code>zic</code> output files, documented in
  1183. the <code>tzfile</code> man page.
  1184. </li>
  1185. <li>
  1186. The format of zone table files, documented in <code>zone1970.tab</code>.
  1187. </li>
  1188. <li>
  1189. The format of the country code file, documented in <code>iso3166.tab</code>.
  1190. </li>
  1191. <li>
  1192. The version number of the code and data, as the first line of
  1193. the text file '<code>version</code>' in each release.
  1194. </li>
  1195. </ul>
  1196. <p>
  1197. Interface changes in a release attempt to preserve compatibility with
  1198. recent releases.
  1199. For example, <code><abbr>tz</abbr></code> data files typically do not
  1200. rely on recently added <code>zic</code> features, so that users can
  1201. run older <code>zic</code> versions to process newer data files.
  1202. <a href="tz-link.html#download">Downloading
  1203. the <code><abbr>tz</abbr></code> database</a> describes how releases
  1204. are tagged and distributed.
  1205. </p>
  1206. <p>
  1207. Interfaces not listed above are less stable.
  1208. For example, users should not rely on particular <abbr>UT</abbr>
  1209. offsets or abbreviations for timestamps, as data entries are often
  1210. based on guesswork and these guesses may be corrected or improved.
  1211. </p>
  1212. <p>
  1213. Timezone boundaries are not part of the stable interface.
  1214. For example, even though the <samp>Asia/Bangkok</samp> timezone
  1215. currently includes Chang Mai, Hanoi, and Phnom Penh, this is not part
  1216. of the stable interface and the timezone can split at any time.
  1217. If a calendar application records a future event in some location other
  1218. than Bangkok by putting "<samp>Asia/Bangkok</samp>" in the event's record,
  1219. the application should be robust in the presence of timezone splits
  1220. between now and the future time.
  1221. </p>
  1222. </section>
  1223. <section>
  1224. <h2 id="leapsec">Leap seconds</h2>
  1225. <p>
  1226. Leap seconds were introduced in 1972 to accommodate the
  1227. difference between atomic time and the less regular rotation of the earth.
  1228. Unfortunately they caused so many problems with civil
  1229. timekeeping that they
  1230. are <a href="https://www.bipm.org/en/cgpm-2022/resolution-4">planned
  1231. to be discontinued by 2035</a>, with some as-yet-undetermined
  1232. mechanism replacing them, perhaps after the year 2135.
  1233. Despite their impending obsolescence, a record of leap seconds is still
  1234. needed to resolve timestamps from 1972 through 2035.
  1235. </p>
  1236. <p>
  1237. The <code><abbr>tz</abbr></code> code and data can account for leap seconds,
  1238. thanks to code contributed by Bradley White.
  1239. However, the leap second support of this package is rarely used directly
  1240. because POSIX requires leap seconds to be excluded and many
  1241. software packages would mishandle leap seconds if they were present.
  1242. Instead, leap seconds are more commonly handled by occasionally adjusting
  1243. the operating system kernel clock as described in
  1244. <a href="tz-link.html#precision">Precision timekeeping</a>,
  1245. and this package by default installs a <samp>leapseconds</samp> file
  1246. commonly used by
  1247. <a href="https://www.ntp.org"><abbr title="Network Time Protocol">NTP</abbr></a>
  1248. software that adjusts the kernel clock.
  1249. However, kernel-clock twiddling approximates UTC only roughly,
  1250. and systems needing more precise UTC can use this package's leap
  1251. second support directly.
  1252. </p>
  1253. <p>
  1254. The directly supported mechanism assumes that <code>time_t</code>
  1255. counts of seconds since the POSIX epoch normally include leap seconds,
  1256. as opposed to POSIX <code>time_t</code> counts which exclude leap seconds.
  1257. This modified timescale is converted to <abbr>UTC</abbr>
  1258. at the same point that time zone and <abbr>DST</abbr>
  1259. adjustments are applied &ndash;
  1260. namely, at calls to <code>localtime</code> and analogous functions &ndash;
  1261. and the process is driven by leap second information
  1262. stored in alternate versions of the <abbr>TZif</abbr> files.
  1263. Because a leap second adjustment may be needed even
  1264. if no time zone correction is desired,
  1265. calls to <code>gmtime</code>-like functions
  1266. also need to consult a <abbr>TZif</abbr> file,
  1267. conventionally named <samp><abbr>Etc/UTC</abbr></samp>
  1268. (<samp><abbr>GMT</abbr></samp> in previous versions),
  1269. to see whether leap second corrections are needed.
  1270. To convert an application's <code>time_t</code> timestamps to or from
  1271. POSIX <code>time_t</code> timestamps (for use when, say,
  1272. embedding or interpreting timestamps in portable
  1273. <a href="https://en.wikipedia.org/wiki/Tar_(computing)"><code>tar</code></a>
  1274. files),
  1275. the application can call the utility functions
  1276. <code>time2posix</code> and <code>posix2time</code>
  1277. included with this package.
  1278. </p>
  1279. <p>
  1280. If the POSIX-compatible <abbr>TZif</abbr> file set is installed
  1281. in a directory whose basename is <samp>zoneinfo</samp>, the
  1282. leap-second-aware file set is by default installed in a separate
  1283. directory <samp>zoneinfo-leaps</samp>.
  1284. Although each process can have its own time zone by setting
  1285. its <code>TZ</code> environment variable, there is no support for some
  1286. processes being leap-second aware while other processes are
  1287. POSIX-compatible; the leap-second choice is system-wide.
  1288. So if you configure your kernel to count leap seconds, you should also
  1289. discard <samp>zoneinfo</samp> and rename <samp>zoneinfo-leaps</samp>
  1290. to <samp>zoneinfo</samp>.
  1291. Alternatively, you can install just one set of <abbr>TZif</abbr> files
  1292. in the first place; see the <code>REDO</code> variable in this package's
  1293. <a href="https://en.wikipedia.org/wiki/Makefile">makefile</a>.
  1294. </p>
  1295. </section>
  1296. <section>
  1297. <h2 id="calendar">Calendrical issues</h2>
  1298. <p>
  1299. Calendrical issues are a bit out of scope for a time zone database,
  1300. but they indicate the sort of problems that we would run into if we
  1301. extended the time zone database further into the past.
  1302. An excellent resource in this area is Edward M. Reingold
  1303. and Nachum Dershowitz, <cite><a
  1304. href="https://www.cambridge.org/fr/academic/subjects/computer-science/computing-general-interest/calendrical-calculations-ultimate-edition-4th-edition">Calendrical
  1305. Calculations: The Ultimate Edition</a></cite>, Cambridge University Press (2018).
  1306. Other information and sources are given in the file '<code>calendars</code>'
  1307. in the <code><abbr>tz</abbr></code> distribution.
  1308. They sometimes disagree.
  1309. </p>
  1310. </section>
  1311. <section>
  1312. <h2 id="planets">Time and time zones off Earth</h2>
  1313. <p>
  1314. The European Space Agency is <a
  1315. href='https://www.esa.int/Applications/Navigation/Telling_time_on_the_Moon'>considering</a>
  1316. the establishment of a reference timescale for the Moon, which has
  1317. days roughly equivalent to 29.5 Earth days, and where relativistic
  1318. effects cause clocks to tick slightly faster than on Earth.
  1319. </p>
  1320. <p>
  1321. Some people's work schedules have used
  1322. <a href="https://en.wikipedia.org/wiki/Timekeeping_on_Mars">Mars time</a>.
  1323. Jet Propulsion Laboratory (JPL) coordinators kept Mars time on
  1324. and off during the
  1325. <a href="https://en.wikipedia.org/wiki/Mars_Pathfinder">Mars
  1326. Pathfinder</a> mission (1997).
  1327. Some of their family members also adapted to Mars time.
  1328. Dozens of special Mars watches were built for JPL workers who kept
  1329. Mars time during the
  1330. <a href="https://en.wikipedia.org/wiki/Mars_Exploration_Rover">Mars
  1331. Exploration Rovers (MER)</a> mission (2004&ndash;2018).
  1332. These timepieces looked like normal Seikos and Citizens but were adjusted
  1333. to use Mars seconds rather than terrestrial seconds, although
  1334. unfortunately the adjusted watches were unreliable and appear to have
  1335. had only limited use.
  1336. </p>
  1337. <p>
  1338. A Mars solar day is called a "sol" and has a mean period equal to
  1339. about 24 hours 39 minutes 35.244 seconds in terrestrial time.
  1340. It is divided into a conventional 24-hour clock, so each Mars second
  1341. equals about 1.02749125 terrestrial seconds.
  1342. (One MER worker noted, "If I am working Mars hours, and Mars hours are
  1343. 2.5% more than Earth hours, shouldn't I get an extra 2.5% pay raise?")
  1344. </p>
  1345. <p>
  1346. The <a href="https://en.wikipedia.org/wiki/Prime_meridian">prime
  1347. meridian</a> of Mars goes through the center of the crater
  1348. <a href="https://en.wikipedia.org/wiki/Airy-0">Airy-0</a>, named in
  1349. honor of the British astronomer who built the Greenwich telescope that
  1350. defines Earth's prime meridian.
  1351. Mean solar time on the Mars prime meridian is
  1352. called Mars Coordinated Time (<abbr>MTC</abbr>).
  1353. </p>
  1354. <p>
  1355. Each landed mission on Mars has adopted a different reference for
  1356. solar timekeeping, so there is no real standard for Mars time zones.
  1357. For example, the MER mission defined two time zones "Local
  1358. Solar Time A" and "Local Solar Time B" for its two missions, each zone
  1359. designed so that its time equals local true solar time at
  1360. approximately the middle of the nominal mission.
  1361. The A and B zones differ enough so that an MER worker assigned to
  1362. the A zone might suffer "Mars lag" when switching to work in the B zone.
  1363. Such a "time zone" is not particularly suited for any application
  1364. other than the mission itself.
  1365. </p>
  1366. <p>
  1367. Many calendars have been proposed for Mars, but none have achieved
  1368. wide acceptance.
  1369. Astronomers often use Mars Sol Date (<abbr>MSD</abbr>) which is a
  1370. sequential count of Mars solar days elapsed since about 1873-12-29
  1371. 12:00 <abbr>GMT</abbr>.
  1372. </p>
  1373. <p>
  1374. In our solar system, Mars is the planet with time and calendar most
  1375. like Earth's.
  1376. On other planets, Sun-based time and calendars would work quite
  1377. differently.
  1378. For example, although Mercury's
  1379. <a href="https://en.wikipedia.org/wiki/Rotation_period">sidereal
  1380. rotation period</a> is 58.646 Earth days, Mercury revolves around the
  1381. Sun so rapidly that an observer on Mercury's equator would see a
  1382. sunrise only every 175.97 Earth days, i.e., a Mercury year is 0.5 of a
  1383. Mercury day.
  1384. Venus is more complicated, partly because its rotation is slightly
  1385. <a href="https://en.wikipedia.org/wiki/Retrograde_motion">retrograde</a>:
  1386. its year is 1.92 of its days.
  1387. Gas giants like Jupiter are trickier still, as their polar and
  1388. equatorial regions rotate at different rates, so that the length of a
  1389. day depends on latitude.
  1390. This effect is most pronounced on Neptune, where the day is about 12
  1391. hours at the poles and 18 hours at the equator.
  1392. </p>
  1393. <p>
  1394. Although the <code><abbr>tz</abbr></code> database does not support
  1395. time on other planets, it is documented here in the hopes that support
  1396. will be added eventually.
  1397. </p>
  1398. <p>
  1399. Sources for time on other planets:
  1400. </p>
  1401. <ul>
  1402. <li>
  1403. Michael Allison and Robert Schmunk,
  1404. "<a href="https://www.giss.nasa.gov/tools/mars24/help/notes.html">Technical
  1405. Notes on Mars Solar Time as Adopted by the Mars24 Sunclock</a>"
  1406. (2020-03-08).
  1407. </li>
  1408. <li>
  1409. Zara Mirmalek,
  1410. <em><a href="https://mitpress.mit.edu/books/making-time-mars">Making
  1411. Time on Mars</a></em>, MIT Press (March 2020), ISBN 978-0262043854.
  1412. </li>
  1413. <li>
  1414. Jia-Rui Chong,
  1415. "<a href="https://www.latimes.com/archives/la-xpm-2004-jan-14-sci-marstime14-story.html">Workdays
  1416. Fit for a Martian</a>", <cite>Los Angeles Times</cite>
  1417. (2004-01-14), pp A1, A20&ndash;A21.
  1418. </li>
  1419. <li>
  1420. Tom Chmielewski,
  1421. "<a href="https://www.theatlantic.com/technology/archive/2015/02/jet-lag-is-worse-on-mars/386033/">Jet
  1422. Lag Is Worse on Mars</a>", <cite>The Atlantic</cite> (2015-02-26)
  1423. </li>
  1424. <li>
  1425. Matt Williams,
  1426. "<a href="https://www.universetoday.com/37481/days-of-the-planets/">How
  1427. long is a day on the other planets of the solar system?</a>"
  1428. (2016-01-20).
  1429. </li>
  1430. </ul>
  1431. </section>
  1432. <footer>
  1433. <hr>
  1434. This file is in the public domain, so clarified as of 2009-05-17 by
  1435. Arthur David Olson.
  1436. </footer>
  1437. </body>
  1438. </html>