Theory revision 1.1
11.1Sjtc@(#)Theory 7.2 21.1Sjtc 31.1SjtcThese time and date functions are much like the System V Release 2.0 (SVR2) 41.1Sjtctime and date functions; there are a few additions and changes to extend 51.1Sjtcthe usefulness of the SVR2 functions: 61.1Sjtc 71.1Sjtc* In SVR2, time display in a process is controlled by the environment 81.1Sjtc variable TZ, which "must be a three-letter time zone name, followed 91.1Sjtc by a number representing the difference between local time and 101.1Sjtc Greenwich Mean Time in hours, followed by an optional three-letter 111.1Sjtc name for a daylight time zone;" when the optional daylight time zone is 121.1Sjtc present, "standard U.S.A. Daylight Savings Time conversion is applied." 131.1Sjtc This means that SVR2 can't deal with other (for example, Australian) 141.1Sjtc daylight savings time rules, or situations where more than two 151.1Sjtc time zone abbreviations are used in an area. 161.1Sjtc 171.1Sjtc* In SVR2, time conversion information is compiled into each program 181.1Sjtc that does time conversion. This means that when time conversion 191.1Sjtc rules change (as in the United States in 1987), all programs that 201.1Sjtc do time conversion must be recompiled to ensure proper results. 211.1Sjtc 221.1Sjtc* In SVR2, time conversion fails for near-minimum or near-maximum 231.1Sjtc time_t values when doing conversions for places that don't use GMT. 241.1Sjtc 251.1Sjtc* In SVR2, there's no tamper-proof way for a process to learn the 261.1Sjtc system's best idea of local wall clock. (This is important for 271.1Sjtc applications that an administrator wants used only at certain times-- 281.1Sjtc without regard to whether the user has fiddled the "TZ" environment 291.1Sjtc variable. While an administrator can "do everything in GMT" to get 301.1Sjtc around the problem, doing so is inconvenient and precludes handling 311.1Sjtc daylight savings time shifts--as might be required to limit phone 321.1Sjtc calls to off-peak hours.) 331.1Sjtc 341.1Sjtc* These functions can account for leap seconds, thanks to Bradley White 351.1Sjtc (bww@k.cs.cmu.edu). 361.1Sjtc 371.1SjtcThese are the changes that have been made to the SVR2 functions: 381.1Sjtc 391.1Sjtc* The "TZ" environment variable is used in generating the name of a file 401.1Sjtc from which time zone information is read (or is interpreted a la 411.1Sjtc POSIX); "TZ" is no longer constrained to be a three-letter time zone 421.1Sjtc name followed by a number of hours and an optional three-letter 431.1Sjtc daylight time zone name. The daylight saving time rules to be used 441.1Sjtc for a particular time zone are encoded in the time zone file; 451.1Sjtc the format of the file allows U.S., Australian, and other rules to be 461.1Sjtc encoded, and allows for situations where more than two time zone 471.1Sjtc abbreviations are used. 481.1Sjtc 491.1Sjtc It was recognized that allowing the "TZ" environment variable to 501.1Sjtc take on values such as "US/Eastern" might cause "old" programs 511.1Sjtc (that expect "TZ" to have a certain form) to operate incorrectly; 521.1Sjtc consideration was given to using some other environment variable 531.1Sjtc (for example, "TIMEZONE") to hold the string used to generate the 541.1Sjtc time zone information file name. In the end, however, it was decided 551.1Sjtc to continue using "TZ": it is widely used for time zone purposes; 561.1Sjtc separately maintaining both "TZ" and "TIMEZONE" seemed a nuisance; 571.1Sjtc and systems where "new" forms of "TZ" might cause problems can simply 581.1Sjtc use TZ values such as "EST5EDT" which can be used both by 591.1Sjtc "new" programs (a la POSIX) and "old" programs (as zone names and 601.1Sjtc offsets). 611.1Sjtc 621.1Sjtc* To handle places where more than two time zone abbreviations are used, 631.1Sjtc the functions "localtime" and "gmtime" set tzname[tmp->tm_isdst] 641.1Sjtc (where "tmp" is the value the function returns) to the time zone 651.1Sjtc abbreviation to be used. This differs from SVR2, where the elements 661.1Sjtc of tzname are only changed as a result of calls to tzset. 671.1Sjtc 681.1Sjtc* Since the "TZ" environment variable can now be used to control time 691.1Sjtc conversion, the "daylight" and "timezone" variables are no longer 701.1Sjtc needed or supported. (You can use a compile-time option to cause 711.1Sjtc these variables to be defined and to be set by "tzset"; however, their 721.1Sjtc values will not be used by "localtime.") 731.1Sjtc 741.1Sjtc* The "localtime" function has been set up to deliver correct results 751.1Sjtc for near-minimum or near-maximum time_t values. (A comment in the 761.1Sjtc source code tells how to get compatibly wrong results). 771.1Sjtc 781.1Sjtc* A function "tzsetwall" has been added to arrange for the system's 791.1Sjtc best approximation to local wall clock time to be delivered by 801.1Sjtc subsequent calls to "localtime." Source code for portable 811.1Sjtc applications that "must" run on local wall clock time should call 821.1Sjtc "tzsetwall();" if such code is moved to "old" systems that don't provide 831.1Sjtc tzsetwall, you won't be able to generate an executable program. 841.1Sjtc (These time zone functions also arrange for local wall clock time to be 851.1Sjtc used if tzset is called--directly or indirectly--and there's no "TZ" 861.1Sjtc environment variable; portable applications should not, however, rely 871.1Sjtc on this behavior since it's not the way SVR2 systems behave.) 881.1Sjtc 891.1SjtcPoints of interest to folks with Version 7 or BSD systems: 901.1Sjtc 911.1Sjtc* The BSD "timezone" function is not present in this package; 921.1Sjtc it's impossible to reliably map timezone's arguments (a "minutes west 931.1Sjtc of GMT" value and a "daylight saving time in effect" flag) to a 941.1Sjtc time zone abbreviation, and we refuse to guess. 951.1Sjtc Programs that in the past used the timezone function may now examine 961.1Sjtc tzname[localtime(&clock)->tm_isdst] to learn the correct time 971.1Sjtc zone abbreviation to use. Alternatively, use localtime(&clock)->tm_zone 981.1Sjtc if this has been enabled. 991.1Sjtc 1001.1Sjtc* The BSD gettimeofday function is not used in this package; 1011.1Sjtc this lets users control the time zone used in doing time conversions. 1021.1Sjtc Users who don't try to control things (that is, users who do not set 1031.1Sjtc the environment variable TZ) get the time conversion specified in the 1041.1Sjtc file "/etc/zoneinfo/localtime"; see the time zone compiler writeup for 1051.1Sjtc information on how to initialize this file. 1061.1Sjtc 1071.1SjtcThe functions that are conditionally compiled if STD_INSPIRED is defined should, 1081.1Sjtcat this point, be looked on primarily as food for thought. They are not in 1091.1Sjtcany sense "standard compatible"--some are not, in fact, specified in *any* 1101.1Sjtcstandard. They do, however, represent responses of various authors to 1111.1Sjtcstandardization proposals. 1121.1Sjtc 1131.1SjtcOther time conversion proposals, in particular the one developed by folks at 1141.1SjtcHewlett Packard, offer a wider selection of functions that provide capabilities 1151.1Sjtcbeyond those provided here. The absence of such functions from this package 1161.1Sjtcis not meant to discourage the development, standardization, or use of such 1171.1Sjtcfunctions. Rather, their absence reflects the decision to make this package 1181.1Sjtcclose to SVR2 (with the exceptions outlined above) to ensure its broad 1191.1Sjtcacceptability. If more powerful time conversion functions can be standardized, 1201.1Sjtcso much the better. 121