Theory revision 1.8
1#	$NetBSD: Theory,v 1.8 2004/05/27 20:39:49 kleink Exp $
2@(#)Theory	7.15
3
4
5----- Outline -----
6
7	Time and date functions
8	Names of time zone regions
9	Time zone abbreviations
10	Calendrical issues
11	Time and time zones on Mars
12
13
14----- Time and date functions -----
15
16These time and date functions are upwards compatible with POSIX.1,
17an international standard for UNIX-like systems.
18As of this writing, the current edition of POSIX.1 is:
19
20  Information technology --Portable Operating System Interface (POSIX (R))
21  -- Part 1: System Application Program Interface (API) [C Language]
22  ISO/IEC 9945-1:1996
23  ANSI/IEEE Std 1003.1, 1996 Edition
24  1996-07-12
25
26POSIX.1 has the following properties and limitations.
27
28*	In POSIX.1, time display in a process is controlled by the
29	environment variable TZ.  Unfortunately, the POSIX.1 TZ string takes
30	a form that is hard to describe and is error-prone in practice.
31	Also, POSIX.1 TZ strings can't deal with other (for example, Israeli)
32	daylight saving time rules, or situations where more than two
33	time zone abbreviations are used in an area.
34
35	The POSIX.1 TZ string takes the following form:
36
37		stdoffset[dst[offset],date[/time],date[/time]]
38
39	where:
40
41	std and dst
42		are 3 or more characters specifying the standard
43		and daylight saving time (DST) zone names.
44	offset
45		is of the form `[-]hh:[mm[:ss]]' and specifies the
46		offset west of UTC.  The default DST offset is one hour
47		ahead of standard time.
48	date[/time],date[/time]
49		specifies the beginning and end of DST.  If this is absent,
50		the system supplies its own rules for DST, and these can
51		differ from year to year; typically US DST rules are used.
52	time
53		takes the form `hh:[mm[:ss]]' and defaults to 02:00.
54	date
55		takes one of the following forms:
56		Jn (1<=n<=365)
57			origin-1 day number not counting February 29
58		n (0<=n<=365)
59			origin-0 day number counting February 29 if present
60		Mm.n.d (0[Sunday]<=d<=6[Saturday], 1<=n<=5, 1<=m<=12)
61			for the dth day of week n of month m of the year,
62			where week 1 is the first week in which day d appears,
63			and `5' stands for the last week in which day d appears
64			(which may be either the 4th or 5th week).
65
66*	In POSIX.1, when a TZ value like "EST5EDT" is parsed,
67	typically the current US DST rules are used,
68	but this means that the US DST rules are compiled into each program
69	that does time conversion.  This means that when US time conversion
70	rules change (as in the United States in 1987), all programs that
71	do time conversion must be recompiled to ensure proper results.
72
73*	In POSIX.1, there's no tamper-proof way for a process to learn the
74	system's best idea of local wall clock.  (This is important for
75	applications that an administrator wants used only at certain times--
76	without regard to whether the user has fiddled the "TZ" environment
77	variable.  While an administrator can "do everything in UTC" to get
78	around the problem, doing so is inconvenient and precludes handling
79	daylight saving time shifts--as might be required to limit phone
80	calls to off-peak hours.)
81
82*	POSIX.1 requires that systems ignore leap seconds.
83
84These are the extensions that have been made to the POSIX.1 functions:
85
86*	The "TZ" environment variable is used in generating the name of a file
87	from which time zone information is read (or is interpreted a la
88	POSIX); "TZ" is no longer constrained to be a three-letter time zone
89	name followed by a number of hours and an optional three-letter
90	daylight time zone name.  The daylight saving time rules to be used
91	for a particular time zone are encoded in the time zone file;
92	the format of the file allows U.S., Australian, and other rules to be
93	encoded, and allows for situations where more than two time zone
94	abbreviations are used.
95
96	It was recognized that allowing the "TZ" environment variable to
97	take on values such as "America/New_York" might cause "old" programs
98	(that expect "TZ" to have a certain form) to operate incorrectly;
99	consideration was given to using some other environment variable
100	(for example, "TIMEZONE") to hold the string used to generate the
101	time zone information file name.  In the end, however, it was decided
102	to continue using "TZ":  it is widely used for time zone purposes;
103	separately maintaining both "TZ" and "TIMEZONE" seemed a nuisance;
104	and systems where "new" forms of "TZ" might cause problems can simply
105	use TZ values such as "EST5EDT" which can be used both by
106	"new" programs (a la POSIX) and "old" programs (as zone names and
107	offsets).
108
109*	To handle places where more than two time zone abbreviations are used,
110	the functions "localtime" and "gmtime" set tzname[tmp->tm_isdst]
111	(where "tmp" is the value the function returns) to the time zone
112	abbreviation to be used.  This differs from POSIX.1, where the elements
113	of tzname are only changed as a result of calls to tzset.
114
115*	Since the "TZ" environment variable can now be used to control time
116	conversion, the "daylight" and "timezone" variables are no longer
117	needed.  (These variables are defined and set by "tzset"; however, their
118	values will not be used by "localtime.")
119
120*	The "localtime" function has been set up to deliver correct results
121	for near-minimum or near-maximum time_t values.  (A comment in the
122	source code tells how to get compatibly wrong results).
123
124*	A function "tzsetwall" has been added to arrange for the system's
125	best approximation to local wall clock time to be delivered by
126	subsequent calls to "localtime."  Source code for portable
127	applications that "must" run on local wall clock time should call
128	"tzsetwall();" if such code is moved to "old" systems that don't
129	provide tzsetwall, you won't be able to generate an executable program.
130	(These time zone functions also arrange for local wall clock time to be
131	used if tzset is called--directly or indirectly--and there's no "TZ"
132	environment variable; portable applications should not, however, rely
133	on this behavior since it's not the way SVR2 systems behave.)
134
135*	These functions can account for leap seconds, thanks to Bradley White
136	(bww@k.cs.cmu.edu).
137
138Points of interest to folks with other systems:
139
140*	This package is already part of many POSIX-compliant hosts,
141	including BSD, HP, Linux, Network Appliance, SCO, SGI, and Sun.
142	On such hosts, the primary use of this package
143	is to update obsolete time zone rule tables.
144	To do this, you may need to compile the time zone compiler
145	`zic' supplied with this package instead of using the system `zic',
146	since the format of zic's input changed slightly in late 1994,
147	and many vendors still do not support the new input format.
148
149*	The UNIX Version 7 "timezone" function is not present in this package;
150	it's impossible to reliably map timezone's arguments (a "minutes west
151	of GMT" value and a "daylight saving time in effect" flag) to a
152	time zone abbreviation, and we refuse to guess.
153	Programs that in the past used the timezone function may now examine
154	tzname[localtime(&clock)->tm_isdst] to learn the correct time
155	zone abbreviation to use.  Alternatively, use
156	localtime(&clock)->tm_zone if this has been enabled.
157
158*	The 4.2BSD gettimeofday function is not used in this package.
159	This formerly let users obtain the current UTC offset and DST flag,
160	but this functionality was removed in later versions of BSD.
161
162*	In SVR2, time conversion fails for near-minimum or near-maximum
163	time_t values when doing conversions for places that don't use UTC.
164	This package takes care to do these conversions correctly.
165
166The functions that are conditionally compiled if STD_INSPIRED is defined
167should, at this point, be looked on primarily as food for thought.  They are
168not in any sense "standard compatible"--some are not, in fact, specified in
169*any* standard.  They do, however, represent responses of various authors to
170standardization proposals.
171
172Other time conversion proposals, in particular the one developed by folks at
173Hewlett Packard, offer a wider selection of functions that provide capabilities
174beyond those provided here.  The absence of such functions from this package
175is not meant to discourage the development, standardization, or use of such
176functions.  Rather, their absence reflects the decision to make this package
177contain valid extensions to POSIX.1, to ensure its broad
178acceptability.  If more powerful time conversion functions can be standardized,
179so much the better.
180
181
182----- Names of time zone rule files -----
183
184The time zone rule file naming conventions attempt to strike a balance
185among the following goals:
186
187 * Uniquely identify every national region where clocks have all
188   agreed since 1970.  This is essential for the intended use: static
189   clocks keeping local civil time.
190
191 * Indicate to humans as to where that region is.  This simplifes use.
192
193 * Be robust in the presence of political changes.  This reduces the
194   number of updates and backward-compatibility hacks.  For example,
195   names of countries are ordinarily not used, to avoid
196   incompatibilities when countries change their name
197   (e.g. Zaire->Congo) or when locations change countries
198   (e.g. Hong Kong from UK colony to China).
199
200 * Be portable to a wide variety of implementations.
201   This promotes use of the technology.
202
203 * Use a consistent naming convention over the entire world.
204   This simplifies both use and maintenance.
205
206This naming convention is not intended for use by inexperienced users
207to select TZ values by themselves (though they can of course examine
208and reuse existing settings).  Distributors should provide
209documentation and/or a simple selection interface that explains the
210names; see the 'tzselect' program supplied with this distribution for
211one example.
212
213Names normally have the form AREA/LOCATION, where AREA is the name
214of a continent or ocean, and LOCATION is the name of a specific
215location within that region.  North and South America share the same
216area, `America'.  Typical names are `Africa/Cairo', `America/New_York',
217and `Pacific/Honolulu'.
218
219Here are the general rules used for choosing location names,
220in decreasing order of importance:
221
222	Use only valid POSIX file name components (i.e., the parts of
223		names other than `/').  Within a file name component,
224		use only ASCII letters, `.', `-' and `_'.  Do not use
225		digits, as that might create an ambiguity with POSIX
226		TZ strings.  A file name component must not exceed 14
227		characters or start with `-'.  E.g., prefer `Brunei'
228		to `Bandar_Seri_Begawan'.
229	Include at least one location per time zone rule set per country.
230		One such location is enough.  Use ISO 3166 (see the file
231		iso3166.tab) to help decide whether something is a country.
232	If all the clocks in a country's region have agreed since 1970,
233		don't bother to include more than one location
234		even if subregions' clocks disagreed before 1970.
235		Otherwise these tables would become annoyingly large.
236	If a name is ambiguous, use a less ambiguous alternative;
237		e.g. many cities are named San Jose and Georgetown, so
238		prefer `Costa_Rica' to `San_Jose' and `Guyana' to `Georgetown'.
239	Keep locations compact.  Use cities or small islands, not countries
240		or regions, so that any future time zone changes do not split
241		locations into different time zones.  E.g. prefer `Paris'
242		to `France', since France has had multiple time zones.
243	Use mainstream English spelling, e.g. prefer `Rome' to `Roma', and
244		prefer `Athens' to the true name (which uses Greek letters).
245		The POSIX file name restrictions encourage this rule.
246	Use the most populous among locations in a country's time zone,
247		e.g. prefer `Shanghai' to `Beijing'.  Among locations with
248		similar populations, pick the best-known location,
249		e.g. prefer `Rome' to `Milan'.
250	Use the singular form, e.g. prefer `Canary' to `Canaries'.
251	Omit common suffixes like `_Islands' and `_City', unless that
252		would lead to ambiguity.  E.g. prefer `Cayman' to
253		`Cayman_Islands' and `Guatemala' to `Guatemala_City',
254		but prefer `Mexico_City' to `Mexico' because the country
255		of Mexico has several time zones.
256	Use `_' to represent a space.
257	Omit `.' from abbreviations in names, e.g. prefer `St_Helena'
258		to `St._Helena'.
259	Do not change established names if they only marginally
260		violate the above rules.  For example, don't change
261		the existing name `Rome' to `Milan' merely because
262		Milan's population has grown to be somewhat greater
263		than Rome's.
264	If a name is changed, put its old spelling in the `backward' file.
265
266The file `zone.tab' lists the geographical locations used to name
267time zone rule files.
268
269Older versions of this package used a different naming scheme,
270and these older names are still supported.
271See the file `backward' for most of these older names
272(e.g. `US/Eastern' instead of `America/New_York').
273The other old-fashioned names still supported are
274`WET', `CET', `MET', `EET' (see the file `europe'),
275and `Factory' (see the file `factory').
276
277
278----- Time zone abbreviations -----
279
280When this package is installed, it generates time zone abbreviations
281like `EST' to be compatible with human tradition and POSIX.1.
282Here are the general rules used for choosing time zone abbreviations,
283in decreasing order of importance:
284
285	Use abbreviations that consist of three or more ASCII letters.
286		Previous editions of this database also used characters like
287		' ' and '?', but these characters have a special meaning to
288		the shell and cause commands like
289			set `date`
290		to have unexpected effects.
291		Previous editions of this rule required upper-case letters,
292		but the Congressman who introduced Chamorro Standard Time
293		preferred "ChST", so the rule has been relaxed.
294
295		This rule guarantees that all abbreviations could have
296		been specified by a POSIX.1 TZ string.  POSIX.1
297		requires at least three characters for an
298		abbreviation.  POSIX.1-1996 says that an abbreviation
299		cannot start with ':', and cannot contain ',', '-',
300		'+', NUL, or a digit.  Draft 7 of POSIX 1003.1-200x
301		changes this rule to say that an abbreviation can
302		contain only '-', '+', and alphanumeric characters in
303		the current locale.  To be portable to both sets of
304		rules, an abbreviation must therefore use only ASCII
305		letters, as these are the only letters that are
306		alphabetic in all locales.
307
308	Use abbreviations that are in common use among English-speakers,
309		e.g. `EST' for Eastern Standard Time in North America.
310		We assume that applications translate them to other languages
311		as part of the normal localization process; for example,
312		a French application might translate `EST' to `HNE'.
313
314	For zones whose times are taken from a city's longitude, use the
315		traditional xMT notation, e.g. `PMT' for Paris Mean Time.
316		The only name like this in current use is `GMT'.
317
318	If there is no common English abbreviation, abbreviate the English
319		translation of the usual phrase used by native speakers.
320		If this is not available or is a phrase mentioning the country
321		(e.g. ``Cape Verde Time''), then:
322
323		When a country has a single or principal time zone region,
324			append `T' to the country's ISO	code, e.g. `CVT' for
325			Cape Verde Time.  For summer time append `ST';
326			for double summer time append `DST'; etc.
327		When a country has multiple time zones, take the first three
328			letters of an English place name identifying each zone
329			and then append `T', `ST', etc. as before;
330			e.g. `VLAST' for VLAdivostok Summer Time.
331
332	Use "zzz" for locations while uninhabited.  The mnemonic is that
333		these locations are, in some sense, asleep.
334
335Application writers should note that these abbreviations are ambiguous
336in practice: e.g. `EST' has a different meaning in Australia than
337it does in the United States.  In new applications, it's often better
338to use numeric UTC offsets like `-0500' instead of time zone
339abbreviations like `EST'; this avoids the ambiguity.
340
341
342----- Calendrical issues -----
343
344Calendrical issues are a bit out of scope for a time zone database,
345but they indicate the sort of problems that we would run into if we
346extended the time zone database further into the past.  An excellent
347resource in this area is Nachum Dershowitz and Edward M. Reingold,
348<a href="http://emr.cs.uiuc.edu/home/reingold/calendar-book/index.shtml">
349Calendrical Calculations
350</a>, Cambridge University Press (1997).  Other information and
351sources are given below.  They sometimes disagree.
352
353
354France
355
356Gregorian calendar adopted 1582-12-20.
357French Revolutionary calendar used 1793-11-24 through 1805-12-31,
358and (in Paris only) 1871-05-06 through 1871-05-23.
359
360
361Russia
362
363From Chris Carrier <72157.3334@CompuServe.COM> (1996-12-02):
364On 1929-10-01 the Soviet Union instituted an ``Eternal Calendar''
365with 30-day months plus 5 holidays, with a 5-day week.
366On 1931-12-01 it changed to a 6-day week; in 1934 it reverted to the
367Gregorian calendar while retaining the 6-day week; on 1940-06-27 it
368reverted to the 7-day week.  With the 6-day week the usual days
369off were the 6th, 12th, 18th, 24th and 30th of the month.
370(Source: Evitiar Zerubavel, _The Seven Day Circle_)
371
372
373Mark Brader reported a similar story in "The Book of Calendars", edited
374by Frank Parise (1982, Facts on File, ISBN 0-8719-6467-8), page 377.  But:
375
376From: Petteri Sulonen (via Usenet)
377Date: 14 Jan 1999 00:00:00 GMT
378Message-ID: <Petteri.Sulonen-1401991626030001@lapin-kulta.in.helsinki.fi>
379
380If your source is correct, how come documents between 1929 -- 1940 were
381still dated using the conventional, Gregorian calendar?
382
383I can post a scan of a document dated December 1, 1934, signed by
384Yenukidze, the secretary, on behalf of Kalinin, the President of the
385Executive Committee of the Supreme Soviet, if you like.
386
387
388
389Sweden (and Finland)
390
391From: msb@sq.com (Mark Brader)
392<a href="news:1996Jul6.012937.29190@sq.com">
393Subject: Re: Gregorian reform -- a part of locale?
394</a>
395Date: 1996-07-06
396
397In 1700, Denmark made the transition from Julian to Gregorian.  Sweden
398decided to *start* a transition in 1700 as well, but rather than have one of
399those unsightly calendar gaps :-), they simply decreed that the next leap
400year after 1696 would be in 1744 -- putting the whole country on a calendar
401different from both Julian and Gregorian for a period of 40 years.
402
403However, in 1704 something went wrong and the plan was not carried through;
404they did, after all, have a leap year that year.  And one in 1708.  In 1712
405they gave it up and went back to Julian, putting 30 days in February that
406year!...
407
408Then in 1753, Sweden made the transition to Gregorian in the usual manner,
409getting there only 13 years behind the original schedule.
410
411(A previous posting of this story was challenged, and Swedish readers
412produced the following references to support it: "Tiderakning och historia"
413by Natanael Beckman (1924) and "Tid, en bok om tiderakning och
414kalendervasen" by Lars-Olof Lode'n (no date was given).)
415
416
417Grotefend's data
418
419From: "Michael Palmer" <mpalmer@netcom.com> [with one obvious typo fixed]
420Subject: Re: Gregorian Calendar (was Re: Another FHC related question
421Newsgroups: soc.genealogy.german
422Date: Tue, 9 Feb 1999 02:32:48 -800
423Message-ID: <199902091032.CAA09644@netcom10.netcom.com>
424
425The following is a(n incomplete) listing, arranged chronologically, of
426European states, with the date they converted from the Julian to the
427Gregorian calendar:
428
42904/15 Oct 1582 - Italy (with exceptions), Spain, Portugal, Poland (Roman
430                 Catholics and Danzig only)
43109/20 Dec 1582 - France, Lorraine
432
43321 Dec 1582/
434   01 Jan 1583 - Holland, Brabant, Flanders, Hennegau
43510/21 Feb 1583 - bishopric of Liege (L"uttich)
43613/24 Feb 1583 - bishopric of Augsburg
43704/15 Oct 1583 - electorate of Trier
43805/16 Oct 1583 - Bavaria, bishoprics of Freising, Eichstedt, Regensburg,
439                 Salzburg, Brixen
44013/24 Oct 1583 - Austrian Oberelsass and Breisgau
44120/31 Oct 1583 - bishopric of Basel
44202/13 Nov 1583 - duchy of J"ulich-Berg
44302/13 Nov 1583 - electorate and city of K"oln
44404/15 Nov 1583 - bishopric of W"urzburg
44511/22 Nov 1583 - electorate of Mainz
44616/27 Nov 1583 - bishopric of Strassburg and the margraviate of Baden
44717/28 Nov 1583 - bishopric of M"unster and duchy of Cleve
44814/25 Dec 1583 - Steiermark
449
45006/17 Jan 1584 - Austria and Bohemia
45111/22 Jan 1584 - Luzern, Uri, Schwyz, Zug, Freiburg, Solothurn
45212/23 Jan 1584 - Silesia and the Lausitz
45322 Jan/
454   02 Feb 1584 - Hungary (legally on 21 Oct 1587)
455      Jun 1584 - Unterwalden
45601/12 Jul 1584 - duchy of Westfalen
457
45816/27 Jun 1585 - bishopric of Paderborn
459
46014/25 Dec 1590 - Transylvania
461
46222 Aug/
463   02 Sep 1612 - duchy of Prussia
464
46513/24 Dec 1614 - Pfalz-Neuburg
466
467          1617 - duchy of Kurland (reverted to the Julian calendar in
468                 1796)
469
470          1624 - bishopric of Osnabr"uck
471
472          1630 - bishopric of Minden
473
47415/26 Mar 1631 - bishopric of Hildesheim
475
476          1655 - Kanton Wallis
477
47805/16 Feb 1682 - city of Strassburg
479
48018 Feb/
481   01 Mar 1700 - Protestant Germany (including Swedish possessions in
482                 Germany), Denmark, Norway
48330 Jun/
484   12 Jul 1700 - Gelderland, Zutphen
48510 Nov/
486   12 Dec 1700 - Utrecht, Overijssel
487
48831 Dec 1700/
489   12 Jan 1701 - Friesland, Groningen, Z"urich, Bern, Basel, Geneva,
490                 Turgau, and Schaffhausen
491
492          1724 - Glarus, Appenzell, and the city of St. Gallen
493
49401 Jan 1750    - Pisa and Florence
495
49602/14 Sep 1752 - Great Britain
497
49817 Feb/
499   01 Mar 1753 - Sweden
500
5011760-1812      - Graub"unden
502
503The Russian empire (including Finland and the Baltic states) did not
504convert to the Gregorian calendar until the Soviet revolution of 1917.
505
506Source:  H. Grotefend, _Taschenbuch der Zeitrechnung des deutschen
507Mittelalters und der Neuzeit_, herausgegeben von Dr. O. Grotefend
508(Hannover:  Hahnsche Buchhandlung, 1941), pp. 26-28.
509
510
511----- Time and time zones on Mars -----
512
513Some people have adjusted their work schedules to fit Mars time.
514Dozens of special Mars watches were built for Jet Propulsion
515Laboratory workers who kept Mars time during the Mars Exploration
516Rovers mission (2004).  These timepieces look like normal Seikos and
517Citizens but use Mars seconds rather than terrestrial seconds.
518
519A Mars solar day is called a "sol" and has a mean period equal to
520about 24 hours 39 minutes 35.244 seconds in terrestrial time.  It is
521divided into a conventional 24-hour clock, so each Mars second equals
522about 1.02749125 terrestrial seconds.
523
524The prime meridian of Mars goes through the center of the crater
525Airy-0, named in honor of the British astronomer who built the
526Greenwich telescope that defines Earth's prime meridian.  Mean solar
527time on the Mars prime meridian is called Mars Coordinated Time (MTC).
528
529Each landed mission on Mars has adopted a different reference for
530solar time keeping, so there is no real standard for Mars time zones.
531For example, the Mars Exploration Rover project (2004) defined two
532time zones "Local Solar Time A" and "Local Solar Time B" for its two
533missions, each zone designed so that its time equals local true solar
534time at approximately the middle of the nominal mission.  Such a "time
535zone" is not particularly suited for any application other than the
536mission itself.
537
538Many calendars have been proposed for Mars, but none have achieved
539wide acceptance.  Astronomers often use Mars Sol Date (MSD) which is a
540sequential count of Mars solar days elapsed since about 1873-12-29
54112:00 GMT.
542
543The tz database does not currently support Mars time, but it is
544documented here in the hopes that support will be added eventually.
545
546Sources:
547
548Michael Allison and Robert Schmunk,
549"Technical Notes on Mars Solar Time as Adopted by the Mars24 Sunclock"
550<http://www.giss.nasa.gov/tools/mars24/help/notes.html> (2004-03-15).
551
552Jia-Rui Chong, "Workdays Fit for a Martian", Los Angeles Times
553(2004-01-14), pp A1, A20-A21.
554