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