home *** CD-ROM | disk | FTP | other *** search
- >From: floyd!opus!ka@SEISMO.CSS.GOV (Kenneth Almquist)
- Date: Tue, 28 Jan 86 21:46:36 EST
- Organization: Bell Labs, Holmdel, NJ
-
- This article proposes a method of handling time zones which I think
- meets all the requirements that have been mentioned.
-
- The offset from GMT of some timezones is not an integral number of
- hours, so I specify this offset in seconds. The idea of compiling a
- complete list of time zone names into ctime is utopian, so I have
- included the time zone name. Finally, the only way to deal with
- daylight savings time appears to be to specify a list of time inter-
- vals during which it applies. Putting this all together, we get the
- following, which should be placed in /usr/include/tz.h:
-
- #define TZNAMLEN 6
- #define NTZLIM 30
-
- struct tzlimits {
- time_t tzl_start; /* when daylight savings time starts */
- time_t tzl_end; /* when it ends */
- };
-
- struct tz {
- time_t tz_offset; /* offset in seconds from GMT */
- char tz_name[TZNAMLEN]; /* regular name of this time zone */
- char tz_dstname[TZNAMLEN]; /* name during daylight savings time */
- struct tzlimits tz_dst[NTZLIM]; /* intervals when DST applies */]
- };
-
- extern struct tz tz;
-
- /* end of tz.h */
-
-
- It should be possible for a user to use a time zone other than the
- system time zone, but on the other hand it should be possible for
- programs like uucico to be able to use the system time zone regardless
- of what the user does. Ctime should not break just because the
- environment has been zapped. To meet these requirements I propose the
- routine "gettz".
-
- Gettz is invoked as "Gettz(flag)". The first call to gettz fills in
- the global variable tz. Subsequent calls to gettz have no effect.
-
- Normally gettz gets the local time for the machine, but if flag is
- nonzero and the environment variable TZFILE is set, gettz reads the
- contents of that file specifed by TZFILE into the variable tz instead.
-
- The routines ctime and localtime call gettz with an argument of 1, so
- that programs normally do not need to invoke gettz directly.
- Programs like uucico which want to force the system time zone to be
- used should call gettz with an argument of zero prior to the first
- call of localtime or ctime.
-
- Gettz returns a negative value when an error occurs and zero
- otherwize. When an error occurs, gettz will attempt to set tz to the
- local time zone; if that fails it will set it to GMT.
-
- For the benefit of users, the directory /usr/lib/tz contains files
- specifying all the common timezones. The user can also create his own
- private timezone files using the utility maketz. (These files cannot
- be created with text editors because they are binary files.) The
- local time zone is linked to /usr/lib/tz/local. Most versions of the
- operating system will copy this file into the kernel at system boot
- time and provide a system call to fetch the local time zone which will
- be used by gettz, but this is not required. (The last sentence is for
- the benefit of very small machines that might find storing the time
- zone in the kernel to be too costly; I may be worrying too much here.)
-
- Any problems with this? The main one is that distant times will not
- be represented in daylight savings time; I don't think that this is a
- problem because times before Jan 1, 1970 cannot be represented anyway,
- and it is a matter for speculation what the daylight savings time rule
- will be in the year 2000.
- Kenneth Almquist
- ihnp4!houxm!hropus!ka (official name)
- ihnp4!opus!ka (shorter path)
-
- Volume-Number: Volume 5, Number 24
-
-