Home | History | Annotate | Line # | Download | only in time
Theory revision 1.1.1.3
      1  1.1.1.3  jtc @(#)Theory	7.5
      2      1.1  jtc 
      3  1.1.1.3  jtc 
      4  1.1.1.3  jtc ----- Outline -----
      5  1.1.1.3  jtc 
      6  1.1.1.3  jtc 	Time and date functions
      7  1.1.1.3  jtc 	Names of time zone regions
      8  1.1.1.3  jtc 	Time zone abbreviations
      9  1.1.1.3  jtc 
     10  1.1.1.3  jtc 
     11  1.1.1.3  jtc ----- Time and date functions -----
     12  1.1.1.3  jtc 
     13  1.1.1.3  jtc These time and date functions are upwards compatible with POSIX.1,
     14  1.1.1.3  jtc an international standard for Unix-like systems.
     15  1.1.1.3  jtc As of this writing, the current edition of POSIX.1 is:
     16  1.1.1.3  jtc 
     17  1.1.1.3  jtc   Information technology --Portable Operating System Interface (POSIX (R))
     18  1.1.1.3  jtc   -- Part 1: System Application Program Interface (API) [C Language]
     19  1.1.1.3  jtc   ISO/IEC 9945-1:1996
     20  1.1.1.3  jtc   ANSI/IEEE Std 1003.1, 1996 Edition
     21  1.1.1.3  jtc   1996-07-12
     22  1.1.1.3  jtc 
     23  1.1.1.3  jtc POSIX.1 has the following properties and limitations.
     24  1.1.1.3  jtc 
     25  1.1.1.3  jtc *	In POSIX.1, time display in a process is controlled by the
     26  1.1.1.3  jtc 	environment variable TZ.  Unfortunately, the POSIX.1 TZ string takes
     27  1.1.1.3  jtc 	a form that is hard to describe and is error-prone in practice.
     28  1.1.1.3  jtc 	Also, POSIX.1 TZ strings can't deal with other (for example, Israeli)
     29  1.1.1.3  jtc 	daylight saving time rules, or situations where more than two
     30      1.1  jtc 	time zone abbreviations are used in an area.
     31      1.1  jtc 
     32  1.1.1.3  jtc 	The POSIX.1 TZ string takes the following form:
     33  1.1.1.3  jtc 
     34  1.1.1.3  jtc 		stdoffset[dst[offset],date[/time],date[/time]]
     35  1.1.1.3  jtc 
     36  1.1.1.3  jtc 	where:
     37  1.1.1.3  jtc 	
     38  1.1.1.3  jtc 	std and dst
     39  1.1.1.3  jtc 		are 3 or more characters specifying the standard
     40  1.1.1.3  jtc 		and daylight saving time (DST) zone names.
     41  1.1.1.3  jtc 	offset
     42  1.1.1.3  jtc 		is of the form `[-]hh:[mm[:ss]]' and specifies the
     43  1.1.1.3  jtc 		offset west of UTC.  The default DST offset is one hour
     44  1.1.1.3  jtc 		ahead of standard time.
     45  1.1.1.3  jtc 	date[/time],date[/time]
     46  1.1.1.3  jtc 		specifies the beginning and end of DST.  If this is absent,
     47  1.1.1.3  jtc 		the system supplies its own rules for DST, and these can
     48  1.1.1.3  jtc 		differ from year to year; typically US DST rules are used.
     49  1.1.1.3  jtc 	time
     50  1.1.1.3  jtc 		takes the form `hh:[mm[:ss]]' and defaults to 02:00.
     51  1.1.1.3  jtc 	date
     52  1.1.1.3  jtc 		takes one of the following forms:
     53  1.1.1.3  jtc 		Jn (1<=n<=365)
     54  1.1.1.3  jtc 			origin-1 day number not counting February 29
     55  1.1.1.3  jtc 		n (0<=n<=365)
     56  1.1.1.3  jtc 			origin-0 day number counting February 29 if present
     57  1.1.1.3  jtc 		Mm.n.d (0[Sunday]<=d<=6[Saturday], 1<=n<=5, 1<=m<=12)
     58  1.1.1.3  jtc 			for the dth day of week n of month m of the year,
     59  1.1.1.3  jtc 			where week 1 is the first week in which day d appears,
     60  1.1.1.3  jtc 			and `5' stands for the last week in which day d appears
     61  1.1.1.3  jtc 			(which may be either the 4th or 5th week).
     62  1.1.1.3  jtc 
     63  1.1.1.3  jtc *	In POSIX.1, when a TZ value like "EST5EDT" is parsed,
     64  1.1.1.3  jtc 	typically the current US DST rules are used,
     65  1.1.1.3  jtc 	but this means that the US DST rules are compiled into each program
     66  1.1.1.3  jtc 	that does time conversion.  This means that when US time conversion
     67      1.1  jtc 	rules change (as in the United States in 1987), all programs that
     68      1.1  jtc 	do time conversion must be recompiled to ensure proper results.
     69      1.1  jtc 
     70  1.1.1.3  jtc *	In POSIX.1, there's no tamper-proof way for a process to learn the
     71      1.1  jtc 	system's best idea of local wall clock.  (This is important for
     72      1.1  jtc 	applications that an administrator wants used only at certain times--
     73      1.1  jtc 	without regard to whether the user has fiddled the "TZ" environment
     74      1.1  jtc 	variable.  While an administrator can "do everything in GMT" to get
     75      1.1  jtc 	around the problem, doing so is inconvenient and precludes handling
     76  1.1.1.3  jtc 	daylight saving time shifts--as might be required to limit phone
     77      1.1  jtc 	calls to off-peak hours.)
     78      1.1  jtc 
     79  1.1.1.3  jtc *	POSIX.1 requires that systems ignore leap seconds.
     80      1.1  jtc 
     81  1.1.1.3  jtc These are the extensions that have been made to the POSIX.1 functions:
     82      1.1  jtc 
     83      1.1  jtc *	The "TZ" environment variable is used in generating the name of a file
     84      1.1  jtc 	from which time zone information is read (or is interpreted a la
     85      1.1  jtc 	POSIX); "TZ" is no longer constrained to be a three-letter time zone
     86      1.1  jtc 	name followed by a number of hours and an optional three-letter
     87      1.1  jtc 	daylight time zone name.  The daylight saving time rules to be used
     88      1.1  jtc 	for a particular time zone are encoded in the time zone file;
     89      1.1  jtc 	the format of the file allows U.S., Australian, and other rules to be
     90      1.1  jtc 	encoded, and allows for situations where more than two time zone
     91      1.1  jtc 	abbreviations are used.
     92      1.1  jtc 
     93      1.1  jtc 	It was recognized that allowing the "TZ" environment variable to
     94  1.1.1.2  jtc 	take on values such as "America/New_York" might cause "old" programs
     95      1.1  jtc 	(that expect "TZ" to have a certain form) to operate incorrectly;
     96      1.1  jtc 	consideration was given to using some other environment variable
     97      1.1  jtc 	(for example, "TIMEZONE") to hold the string used to generate the
     98      1.1  jtc 	time zone information file name.  In the end, however, it was decided
     99      1.1  jtc 	to continue using "TZ":  it is widely used for time zone purposes;
    100      1.1  jtc 	separately maintaining both "TZ" and "TIMEZONE" seemed a nuisance;
    101      1.1  jtc 	and systems where "new" forms of "TZ" might cause problems can simply
    102      1.1  jtc 	use TZ values such as "EST5EDT" which can be used both by
    103      1.1  jtc 	"new" programs (a la POSIX) and "old" programs (as zone names and
    104      1.1  jtc 	offsets).
    105      1.1  jtc 
    106      1.1  jtc *	To handle places where more than two time zone abbreviations are used,
    107      1.1  jtc 	the functions "localtime" and "gmtime" set tzname[tmp->tm_isdst]
    108      1.1  jtc 	(where "tmp" is the value the function returns) to the time zone
    109  1.1.1.3  jtc 	abbreviation to be used.  This differs from POSIX.1, where the elements
    110      1.1  jtc 	of tzname are only changed as a result of calls to tzset.
    111      1.1  jtc 
    112      1.1  jtc *	Since the "TZ" environment variable can now be used to control time
    113      1.1  jtc 	conversion, the "daylight" and "timezone" variables are no longer
    114  1.1.1.3  jtc 	needed.  (These variables are defined and set by "tzset"; however, their
    115      1.1  jtc 	values will not be used by "localtime.")
    116      1.1  jtc 
    117      1.1  jtc *	The "localtime" function has been set up to deliver correct results
    118      1.1  jtc 	for near-minimum or near-maximum time_t values.  (A comment in the
    119      1.1  jtc 	source code tells how to get compatibly wrong results).
    120      1.1  jtc 
    121      1.1  jtc *	A function "tzsetwall" has been added to arrange for the system's
    122      1.1  jtc 	best approximation to local wall clock time to be delivered by
    123      1.1  jtc 	subsequent calls to "localtime."  Source code for portable
    124      1.1  jtc 	applications that "must" run on local wall clock time should call
    125  1.1.1.2  jtc 	"tzsetwall();" if such code is moved to "old" systems that don't
    126  1.1.1.2  jtc 	provide tzsetwall, you won't be able to generate an executable program.
    127      1.1  jtc 	(These time zone functions also arrange for local wall clock time to be
    128      1.1  jtc 	used if tzset is called--directly or indirectly--and there's no "TZ"
    129      1.1  jtc 	environment variable; portable applications should not, however, rely
    130      1.1  jtc 	on this behavior since it's not the way SVR2 systems behave.)
    131      1.1  jtc 
    132  1.1.1.3  jtc *	These functions can account for leap seconds, thanks to Bradley White
    133  1.1.1.3  jtc 	(bww (a] k.cs.cmu.edu).
    134  1.1.1.3  jtc 
    135  1.1.1.3  jtc Points of interest to folks with other systems:
    136  1.1.1.3  jtc 
    137  1.1.1.3  jtc *	This package is already part of many POSIX-compliant hosts,
    138  1.1.1.3  jtc 	including BSD, HP, Linux, Network Appliance, SCO, SGI, and Sun.
    139  1.1.1.3  jtc 	On such hosts, the primary use of this package
    140  1.1.1.3  jtc 	is to update obsolete time zone rule tables.
    141  1.1.1.3  jtc 	To do this, you may need to compile the time zone compiler
    142  1.1.1.3  jtc 	`zic' supplied with this package instead of using the system `zic',
    143  1.1.1.3  jtc 	since the format of zic's input changed slightly in late 1994,
    144  1.1.1.3  jtc 	and many vendors still do not support the new input format.
    145      1.1  jtc 
    146  1.1.1.3  jtc *	The Unix Version 7 "timezone" function is not present in this package;
    147      1.1  jtc 	it's impossible to reliably map timezone's arguments (a "minutes west
    148      1.1  jtc 	of GMT" value and a "daylight saving time in effect" flag) to a
    149      1.1  jtc 	time zone abbreviation, and we refuse to guess.
    150      1.1  jtc 	Programs that in the past used the timezone function may now examine
    151      1.1  jtc 	tzname[localtime(&clock)->tm_isdst] to learn the correct time
    152  1.1.1.2  jtc 	zone abbreviation to use.  Alternatively, use
    153  1.1.1.2  jtc 	localtime(&clock)->tm_zone if this has been enabled.
    154      1.1  jtc 
    155  1.1.1.3  jtc *	The 4.2BSD gettimeofday function is not used in this package.
    156  1.1.1.3  jtc 	This formerly let users obtain the current UTC offset and DST flag,
    157  1.1.1.3  jtc 	but this functionality was removed in later versions of BSD.
    158  1.1.1.3  jtc 
    159  1.1.1.3  jtc *	In SVR2, time conversion fails for near-minimum or near-maximum
    160  1.1.1.3  jtc 	time_t values when doing conversions for places that don't use GMT.
    161  1.1.1.3  jtc 	This package takes care to do these conversions correctly.
    162      1.1  jtc 
    163  1.1.1.2  jtc The functions that are conditionally compiled if STD_INSPIRED is defined
    164  1.1.1.2  jtc should, at this point, be looked on primarily as food for thought.  They are
    165  1.1.1.2  jtc not in any sense "standard compatible"--some are not, in fact, specified in
    166  1.1.1.2  jtc *any* standard.  They do, however, represent responses of various authors to
    167      1.1  jtc standardization proposals.
    168      1.1  jtc 
    169      1.1  jtc Other time conversion proposals, in particular the one developed by folks at
    170      1.1  jtc Hewlett Packard, offer a wider selection of functions that provide capabilities
    171      1.1  jtc beyond those provided here.  The absence of such functions from this package
    172      1.1  jtc is not meant to discourage the development, standardization, or use of such
    173      1.1  jtc functions.  Rather, their absence reflects the decision to make this package
    174  1.1.1.3  jtc contain valid extensions to POSIX.1, to ensure its broad
    175      1.1  jtc acceptability.  If more powerful time conversion functions can be standardized,
    176      1.1  jtc so much the better.
    177  1.1.1.3  jtc 
    178  1.1.1.3  jtc 
    179  1.1.1.3  jtc ----- Names of time zone rule files -----
    180  1.1.1.3  jtc 
    181  1.1.1.3  jtc The names of this package's installed time zone rule files are chosen to
    182  1.1.1.3  jtc help minimize possible future incompatibilities due to political events.
    183  1.1.1.3  jtc Ordinarily, names of countries are not used, to avoid incompatibilities
    184  1.1.1.3  jtc when countries change their name (e.g. Zaire->Congo) or
    185  1.1.1.3  jtc when locations change countries (e.g. Hong Kong from UK colony to China).
    186  1.1.1.3  jtc 
    187  1.1.1.3  jtc Names normally have the form AREA/LOCATION, where AREA is the name
    188  1.1.1.3  jtc of a continent or ocean, and LOCATION is the name of a specific
    189  1.1.1.3  jtc location within that region.  North and South America share the same
    190  1.1.1.3  jtc area, `America'.  Typical names are `Africa/Cairo', `America/New_York',
    191  1.1.1.3  jtc and `Pacific/Honolulu'.
    192  1.1.1.3  jtc 
    193  1.1.1.3  jtc Here are the general rules used for choosing location names,
    194  1.1.1.3  jtc in decreasing order of importance:
    195  1.1.1.3  jtc 
    196  1.1.1.3  jtc 	Use only valid Posix file names.  Use only Ascii letters, digits, `.',
    197  1.1.1.3  jtc 		`-' and `_'.  Do not exceed 14 characters or start with `-'.
    198  1.1.1.3  jtc 		E.g. prefer `Brunei' to `Bandar_Seri_Begawan'.
    199  1.1.1.3  jtc 	Include at least one location per time zone rule set per country.
    200  1.1.1.3  jtc 		One such location is enough.
    201  1.1.1.3  jtc 	If all the clocks in a country's region have agreed since 1970,
    202  1.1.1.3  jtc 		don't bother to include more than one location
    203  1.1.1.3  jtc 		even if subregions' clocks disagreed before 1970.
    204  1.1.1.3  jtc 		Otherwise these tables would become annoyingly large.
    205  1.1.1.3  jtc 	If a name is ambiguous, use a less ambiguous alternative;
    206  1.1.1.3  jtc 		e.g. many cities are named San Jose and Georgetown, so
    207  1.1.1.3  jtc 		prefer `Costa_Rica' to `San_Jose' and `Guyana' to `Georgetown'.
    208  1.1.1.3  jtc 	Keep locations compact.  Use cities or small islands, not countries
    209  1.1.1.3  jtc 		or regions, so that any future time zone changes do not split
    210  1.1.1.3  jtc 		locations into different time zones.  E.g. prefer `Paris'
    211  1.1.1.3  jtc 		to `France', since France has had multiple time zones.
    212  1.1.1.3  jtc 	Use traditional English spelling, e.g. prefer `Rome' to `Roma', and
    213  1.1.1.3  jtc 		prefer `Athens' to the true name (which uses Greek letters).
    214  1.1.1.3  jtc 		The Posix file name restrictions encourage this rule.
    215  1.1.1.3  jtc 	Use the most populous among locations in a country's time zone,
    216  1.1.1.3  jtc 		e.g. prefer `Shanghai' to `Beijing'.  Among locations with
    217  1.1.1.3  jtc 		similar populations, pick the best-known location,
    218  1.1.1.3  jtc 		e.g. prefer `Rome' to `Milan'.
    219  1.1.1.3  jtc 	Use the singular form, e.g. prefer `Canary' to `Canaries'.
    220  1.1.1.3  jtc 	Omit common suffixes like `_Islands' and `_City', unless that
    221  1.1.1.3  jtc 		would lead to ambiguity.  E.g. prefer `Cayman' to
    222  1.1.1.3  jtc 		`Cayman_Islands' and `Guatemala' to `Guatemala_City',
    223  1.1.1.3  jtc 		but prefer `Mexico_City' to `Mexico' because the country
    224  1.1.1.3  jtc 		of Mexico has several time zones.
    225  1.1.1.3  jtc 	Use `_' to represent a space.
    226  1.1.1.3  jtc 	Omit `.' from abbreviations in names, e.g. prefer `St_Helena'
    227  1.1.1.3  jtc 		to `St._Helena'.
    228  1.1.1.3  jtc 
    229  1.1.1.3  jtc The file `zone.tab' lists the geographical locations used to name
    230  1.1.1.3  jtc time zone rule files.
    231  1.1.1.3  jtc 
    232  1.1.1.3  jtc Older versions of this package used a different naming scheme,
    233  1.1.1.3  jtc and these older names are still supported.
    234  1.1.1.3  jtc See the file `backwards' for most of these older names
    235  1.1.1.3  jtc (e.g. `US/Eastern' instead of `America/New_York').
    236  1.1.1.3  jtc The other old-fashioned names still supported are
    237  1.1.1.3  jtc `WET', `CET', `MET', `EET' (see the file `europe'),
    238  1.1.1.3  jtc and `Factory' (see the file `factory').
    239  1.1.1.3  jtc 
    240  1.1.1.3  jtc 
    241  1.1.1.3  jtc ----- Time zone abbreviations -----
    242  1.1.1.3  jtc 
    243  1.1.1.3  jtc When this package is installed, it generates time zone abbreviations
    244  1.1.1.3  jtc like `EST' to be compatible with human tradition and POSIX.1.
    245  1.1.1.3  jtc Here are the general rules used for choosing time zone abbreviations,
    246  1.1.1.3  jtc in decreasing order of importance:
    247  1.1.1.3  jtc 
    248  1.1.1.3  jtc 	Use abbreviations that consist of 3 or more upper-case Ascii letters,
    249  1.1.1.3  jtc 		except use "___" for locations while uninhabited.
    250  1.1.1.3  jtc 		Posix.1 requires at least 3 characters, and the restriction to
    251  1.1.1.3  jtc 		upper-case Ascii letters follows most traditions.
    252  1.1.1.3  jtc 		Previous editions of this database also used characters like
    253  1.1.1.3  jtc 		' ' and '?', but these characters have a special meaning to
    254  1.1.1.3  jtc 		the shell and cause commands like
    255  1.1.1.3  jtc 			set `date`
    256  1.1.1.3  jtc 		to have unexpected effects.  In theory, the character set could
    257  1.1.1.3  jtc 		be !%./@A-Z^_a-z{}, but these tables use only upper-case
    258  1.1.1.3  jtc 		Ascii letters (and "___").
    259  1.1.1.3  jtc 	Use abbreviations that are in common use among English-speakers,
    260  1.1.1.3  jtc 		e.g. `EST' for Eastern Standard Time in North America.
    261  1.1.1.3  jtc 		We assume that applications translate them to other languages
    262  1.1.1.3  jtc 		as part of the normal localization process; for example,
    263  1.1.1.3  jtc 		a French application might translate `EST' to `HNE'.
    264  1.1.1.3  jtc 	For zones whose times are taken from a city's longitude, use the
    265  1.1.1.3  jtc 		traditional xMT notation, e.g. `PMT' for Paris Mean Time.
    266  1.1.1.3  jtc 		The only name like this in current use is `GMT'.
    267  1.1.1.3  jtc 	If there is no common English abbreviation, abbreviate the English
    268  1.1.1.3  jtc 		translation of the usual phrase used by native speakers.
    269  1.1.1.3  jtc 		If this is not available or is a phrase mentioning the country
    270  1.1.1.3  jtc 		(e.g. ``Cape Verde Time''), then:
    271  1.1.1.3  jtc 
    272  1.1.1.3  jtc 		When a country has a single or principal time zone region,
    273  1.1.1.3  jtc 			append `T' to the country's ISO	code, e.g. `CVT' for
    274  1.1.1.3  jtc 			Cape Verde Time.  For summer time append `ST';
    275  1.1.1.3  jtc 			for double summer time append `DST'; etc.
    276  1.1.1.3  jtc 		When a country has multiple time zones, take the first three
    277  1.1.1.3  jtc 			letters of an English place name identifying each zone
    278  1.1.1.3  jtc 			and then append `T', `ST', etc. as before;
    279  1.1.1.3  jtc 			e.g. `VLAST' for VLAdivostok Summer Time.
    280  1.1.1.3  jtc 
    281  1.1.1.3  jtc Application writers should note that these abbreviations are ambiguous
    282  1.1.1.3  jtc in practice: e.g. `EST' has a different meaning in Australia than
    283  1.1.1.3  jtc it does in the United States.  In new applications, it's often better
    284  1.1.1.3  jtc to use numeric GMT offsets like `-0500' instead of time zone
    285  1.1.1.3  jtc abbreviations like `EST'; this avoids the ambiguity.
    286