Theory revision 1.1 1 1.1 jtc @(#)Theory 7.2
2 1.1 jtc
3 1.1 jtc These time and date functions are much like the System V Release 2.0 (SVR2)
4 1.1 jtc time and date functions; there are a few additions and changes to extend
5 1.1 jtc the usefulness of the SVR2 functions:
6 1.1 jtc
7 1.1 jtc * In SVR2, time display in a process is controlled by the environment
8 1.1 jtc variable TZ, which "must be a three-letter time zone name, followed
9 1.1 jtc by a number representing the difference between local time and
10 1.1 jtc Greenwich Mean Time in hours, followed by an optional three-letter
11 1.1 jtc name for a daylight time zone;" when the optional daylight time zone is
12 1.1 jtc present, "standard U.S.A. Daylight Savings Time conversion is applied."
13 1.1 jtc This means that SVR2 can't deal with other (for example, Australian)
14 1.1 jtc daylight savings time rules, or situations where more than two
15 1.1 jtc time zone abbreviations are used in an area.
16 1.1 jtc
17 1.1 jtc * In SVR2, time conversion information is compiled into each program
18 1.1 jtc that does time conversion. This means that when time conversion
19 1.1 jtc rules change (as in the United States in 1987), all programs that
20 1.1 jtc do time conversion must be recompiled to ensure proper results.
21 1.1 jtc
22 1.1 jtc * In SVR2, time conversion fails for near-minimum or near-maximum
23 1.1 jtc time_t values when doing conversions for places that don't use GMT.
24 1.1 jtc
25 1.1 jtc * In SVR2, there's no tamper-proof way for a process to learn the
26 1.1 jtc system's best idea of local wall clock. (This is important for
27 1.1 jtc applications that an administrator wants used only at certain times--
28 1.1 jtc without regard to whether the user has fiddled the "TZ" environment
29 1.1 jtc variable. While an administrator can "do everything in GMT" to get
30 1.1 jtc around the problem, doing so is inconvenient and precludes handling
31 1.1 jtc daylight savings time shifts--as might be required to limit phone
32 1.1 jtc calls to off-peak hours.)
33 1.1 jtc
34 1.1 jtc * These functions can account for leap seconds, thanks to Bradley White
35 1.1 jtc (bww (a] k.cs.cmu.edu).
36 1.1 jtc
37 1.1 jtc These are the changes that have been made to the SVR2 functions:
38 1.1 jtc
39 1.1 jtc * The "TZ" environment variable is used in generating the name of a file
40 1.1 jtc from which time zone information is read (or is interpreted a la
41 1.1 jtc POSIX); "TZ" is no longer constrained to be a three-letter time zone
42 1.1 jtc name followed by a number of hours and an optional three-letter
43 1.1 jtc daylight time zone name. The daylight saving time rules to be used
44 1.1 jtc for a particular time zone are encoded in the time zone file;
45 1.1 jtc the format of the file allows U.S., Australian, and other rules to be
46 1.1 jtc encoded, and allows for situations where more than two time zone
47 1.1 jtc abbreviations are used.
48 1.1 jtc
49 1.1 jtc It was recognized that allowing the "TZ" environment variable to
50 1.1 jtc take on values such as "US/Eastern" might cause "old" programs
51 1.1 jtc (that expect "TZ" to have a certain form) to operate incorrectly;
52 1.1 jtc consideration was given to using some other environment variable
53 1.1 jtc (for example, "TIMEZONE") to hold the string used to generate the
54 1.1 jtc time zone information file name. In the end, however, it was decided
55 1.1 jtc to continue using "TZ": it is widely used for time zone purposes;
56 1.1 jtc separately maintaining both "TZ" and "TIMEZONE" seemed a nuisance;
57 1.1 jtc and systems where "new" forms of "TZ" might cause problems can simply
58 1.1 jtc use TZ values such as "EST5EDT" which can be used both by
59 1.1 jtc "new" programs (a la POSIX) and "old" programs (as zone names and
60 1.1 jtc offsets).
61 1.1 jtc
62 1.1 jtc * To handle places where more than two time zone abbreviations are used,
63 1.1 jtc the functions "localtime" and "gmtime" set tzname[tmp->tm_isdst]
64 1.1 jtc (where "tmp" is the value the function returns) to the time zone
65 1.1 jtc abbreviation to be used. This differs from SVR2, where the elements
66 1.1 jtc of tzname are only changed as a result of calls to tzset.
67 1.1 jtc
68 1.1 jtc * Since the "TZ" environment variable can now be used to control time
69 1.1 jtc conversion, the "daylight" and "timezone" variables are no longer
70 1.1 jtc needed or supported. (You can use a compile-time option to cause
71 1.1 jtc these variables to be defined and to be set by "tzset"; however, their
72 1.1 jtc values will not be used by "localtime.")
73 1.1 jtc
74 1.1 jtc * The "localtime" function has been set up to deliver correct results
75 1.1 jtc for near-minimum or near-maximum time_t values. (A comment in the
76 1.1 jtc source code tells how to get compatibly wrong results).
77 1.1 jtc
78 1.1 jtc * A function "tzsetwall" has been added to arrange for the system's
79 1.1 jtc best approximation to local wall clock time to be delivered by
80 1.1 jtc subsequent calls to "localtime." Source code for portable
81 1.1 jtc applications that "must" run on local wall clock time should call
82 1.1 jtc "tzsetwall();" if such code is moved to "old" systems that don't provide
83 1.1 jtc tzsetwall, you won't be able to generate an executable program.
84 1.1 jtc (These time zone functions also arrange for local wall clock time to be
85 1.1 jtc used if tzset is called--directly or indirectly--and there's no "TZ"
86 1.1 jtc environment variable; portable applications should not, however, rely
87 1.1 jtc on this behavior since it's not the way SVR2 systems behave.)
88 1.1 jtc
89 1.1 jtc Points of interest to folks with Version 7 or BSD systems:
90 1.1 jtc
91 1.1 jtc * The BSD "timezone" function is not present in this package;
92 1.1 jtc it's impossible to reliably map timezone's arguments (a "minutes west
93 1.1 jtc of GMT" value and a "daylight saving time in effect" flag) to a
94 1.1 jtc time zone abbreviation, and we refuse to guess.
95 1.1 jtc Programs that in the past used the timezone function may now examine
96 1.1 jtc tzname[localtime(&clock)->tm_isdst] to learn the correct time
97 1.1 jtc zone abbreviation to use. Alternatively, use localtime(&clock)->tm_zone
98 1.1 jtc if this has been enabled.
99 1.1 jtc
100 1.1 jtc * The BSD gettimeofday function is not used in this package;
101 1.1 jtc this lets users control the time zone used in doing time conversions.
102 1.1 jtc Users who don't try to control things (that is, users who do not set
103 1.1 jtc the environment variable TZ) get the time conversion specified in the
104 1.1 jtc file "/etc/zoneinfo/localtime"; see the time zone compiler writeup for
105 1.1 jtc information on how to initialize this file.
106 1.1 jtc
107 1.1 jtc The functions that are conditionally compiled if STD_INSPIRED is defined should,
108 1.1 jtc at this point, be looked on primarily as food for thought. They are not in
109 1.1 jtc any sense "standard compatible"--some are not, in fact, specified in *any*
110 1.1 jtc standard. They do, however, represent responses of various authors to
111 1.1 jtc standardization proposals.
112 1.1 jtc
113 1.1 jtc Other time conversion proposals, in particular the one developed by folks at
114 1.1 jtc Hewlett Packard, offer a wider selection of functions that provide capabilities
115 1.1 jtc beyond those provided here. The absence of such functions from this package
116 1.1 jtc is not meant to discourage the development, standardization, or use of such
117 1.1 jtc functions. Rather, their absence reflects the decision to make this package
118 1.1 jtc close to SVR2 (with the exceptions outlined above) to ensure its broad
119 1.1 jtc acceptability. If more powerful time conversion functions can be standardized,
120 1.1 jtc so much the better.
121