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