home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / std_unix / mod.std.unix.v5 / text0023.txt < prev    next >
Encoding:
Text File  |  1987-06-30  |  3.4 KB  |  82 lines

  1. >From: floyd!opus!ka@SEISMO.CSS.GOV (Kenneth Almquist)
  2. Date: Tue, 28 Jan 86 21:46:36 EST
  3. Organization: Bell Labs, Holmdel, NJ
  4.  
  5. This article proposes a method of handling time zones which I think
  6. meets all the requirements that have been mentioned.
  7.  
  8. The offset from GMT of some timezones is not an integral number of
  9. hours, so I specify this offset in seconds.  The idea of compiling a
  10. complete list of time zone names into ctime is utopian, so I have
  11. included the time zone name.  Finally, the only way to deal with
  12. daylight savings time appears to be to specify a list of time inter-
  13. vals during which it applies.  Putting this all together, we get the
  14. following, which should be placed in /usr/include/tz.h:
  15.  
  16. #define TZNAMLEN 6
  17. #define NTZLIM 30
  18.  
  19. struct tzlimits {
  20.     time_t tzl_start;        /* when daylight savings time starts */
  21.     time_t tzl_end;            /* when it ends */
  22. };
  23.  
  24. struct tz {
  25.     time_t tz_offset;        /* offset in seconds from GMT */
  26.     char tz_name[TZNAMLEN];        /* regular name of this time zone */
  27.     char tz_dstname[TZNAMLEN];    /* name during daylight savings time */
  28.     struct tzlimits tz_dst[NTZLIM];    /* intervals when DST applies */]
  29. };
  30.  
  31. extern struct tz tz;
  32.  
  33. /* end of tz.h */
  34.  
  35.  
  36. It should be possible for a user to use a time zone other than the
  37. system time zone, but on the other hand it should be possible for
  38. programs like uucico to be able to use the system time zone regardless
  39. of what the user does.  Ctime should not break just because the
  40. environment has been zapped.  To meet these requirements I propose the
  41. routine "gettz".
  42.  
  43. Gettz is invoked as "Gettz(flag)".  The first call to gettz fills in
  44. the global variable tz.  Subsequent calls to gettz have no effect.
  45.  
  46. Normally gettz gets the local time for the machine, but if flag is
  47. nonzero and the environment variable TZFILE is set, gettz reads the
  48. contents of that file specifed by TZFILE into the variable tz instead.
  49.  
  50. The routines ctime and localtime call gettz with an argument of 1, so
  51. that programs normally do not need to invoke gettz directly.
  52. Programs like uucico which want to force the system time zone to be
  53. used should call gettz with an argument of zero prior to the first
  54. call of localtime or ctime.
  55.  
  56. Gettz returns a negative value when an error occurs and zero
  57. otherwize.  When an error occurs, gettz will attempt to set tz to the
  58. local time zone; if that fails it will set it to GMT.
  59.  
  60. For the benefit of users, the directory /usr/lib/tz contains files
  61. specifying all the common timezones.  The user can also create his own
  62. private timezone files using the utility maketz.  (These files cannot
  63. be created with text editors because they are binary files.)  The
  64. local time zone is linked to /usr/lib/tz/local.  Most versions of the
  65. operating system will copy this file into the kernel at system boot
  66. time and provide a system call to fetch the local time zone which will
  67. be used by gettz, but this is not required.  (The last sentence is for
  68. the benefit of very small machines that might find storing the time
  69. zone in the kernel to be too costly; I may be worrying too much here.)
  70.  
  71. Any problems with this?  The main one is that distant times will not
  72. be represented in daylight savings time; I don't think that this is a
  73. problem because times before Jan 1, 1970 cannot be represented anyway,
  74. and it is a matter for speculation what the daylight savings time rule
  75. will be in the year 2000.
  76.                 Kenneth Almquist
  77.                 ihnp4!houxm!hropus!ka    (official name)
  78.                 ihnp4!opus!ka        (shorter path)
  79.  
  80. Volume-Number: Volume 5, Number 24
  81.  
  82.