theory.html 59 KB

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