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

  1. [ This is part of RFC.001 and is a reposting of V5N65. -mod ]
  2.  
  3. Date: 02 Mar 86 05:47:32 +1100 (Sun)
  4. From: Robert Elz <munnari!kre@SEISMO.CSS.GOV>
  5. >Subject: localtime(), ctime() and timezones
  6.  
  7. It seems to me that this discussion is getting a bit overblown,
  8. as far as P1003 is concerned, it doesn't really seem to be
  9. as difficult or complex as some people are making out.
  10.  
  11. So, I'm going to propose something that could be inserted into
  12. P1003 (with the obvious extra definitions that I'm going to
  13. leave out on the assumption that everyone knows what they are,
  14. like the definition of a "struct tm").
  15.  
  16. In some words of other, it would go like this (with hopefully
  17. a lot of cleaning up of the typography to get rid of quotes
  18. and things like that where I would really prefer to use italics
  19. or bold):
  20.  
  21. Implementations shall provide the following functions:
  22.  
  23.     struct tm *gmttime(t) time_t *t;
  24.     struct tm *localtime(t) time_t *t;
  25.     int settz(p) char *p;
  26.     char *asctime(tp) struct tm *tp;
  27.     char *ctime(t) time_t *t;
  28.  
  29. gmttime: converts the time_t "*t" to a "struct tm" representing
  30. the same time (in Universal Co-ordinated Time).  (waffle about
  31. the returned value being in a static area, etc, goes here).
  32.  
  33. localtime: converts the time_t "*t" to a "struct tm" representing
  34. the given time adjusted to represent some local time difference.
  35. "local time" will be specified by a call to "settz", if no such
  36. call has preceded the call to localtime(), localtime() will call
  37. "settz(getenv("TZ"));".  Implementors should note that for any defined
  38. past time (from midnight January 1, 1970 until the time the call is made)
  39. the local time returned should be accurate (taking into account the effects
  40. of daylight saving, if any).  For future times, the local time returned
  41. should be as likely to be accurate as current projections of
  42. future timezone rules and daylight saving time changes allow.
  43.  
  44. settz: enables users to specify the local time conversion to be
  45. used by localtime.  The string is an implementation specific
  46. representation of the timezone offset desired, with 2 special
  47. cases..  The null pointer (t == (char *)0) will always select
  48. the appropriate local time offset for the host executing the call.
  49. A null string (t != (char *)0 && *t == '\0') will select
  50. no local time transformations (making localtime() equivalent
  51. to gmttime()).  Implementations should provide, and document,
  52. some mechanism to allow users to select another timezone.
  53. This mechanism is beyond the scope of the standard.  Implementors
  54. should, if possible, allow users to define their own timezones,
  55. and not restrict them to use one of some standard set.
  56. If settz is called with an unrecognisable argument, the effect
  57. is implementation defined.  (Users might expect any of three
  58. "reasonable"? actions could be taken here -- use GMT, use local time,
  59. or use local time in the area where the implementation was performed).
  60. settz returns 0 if the timezone selected could be obtained, and
  61. -1 otherwise.  settz can be called as many times as needed, each
  62. call affects future calls of localtime, until another call to settz.
  63.  
  64. acstime: returns a 25 character string representing the time
  65. specified by "*tp".  The format of the string is ... (you all know it).
  66.  
  67. ctime: is defined to be "asctime(localtime(t))".
  68.  
  69. ...................
  70.  
  71. Notes: this is (about) the right level of detail for the standard.
  72. There is no need to specify what the form of the argument to
  73. settz() is.  This enables things like the Sys V "EST5EDT" string,
  74. and Arthur Olson's (elsie!ado) "localtime" "Eastern" etc, to all
  75. be used with impunity - the implementor gets to choose whatever
  76. is appropriate to him - just provided that he can satisfy the
  77. needs of his customers (implementors who provide no means of getting
  78. daylight saving right in the Southern hemisphere can probably
  79. expect not to sell many copies there - but that's their choice).
  80.  
  81. In particular - this discourages programmers from writing programs
  82. which "know" what the local time should be - there's no reason at
  83. all why a program should ever need to do more than select GMT,
  84. host local time, or a user specified time zone.  (nb: while localtime
  85. uses the TZ environment variable in cases where the program has made
  86. no call to settz(), there's nothing to stop a program getting the
  87. argument to settz() from anywhere it pleases, including from several
  88. different environment variables if it chooses, and needs to operate
  89. in several timezones, or from an external configuration file, or
  90. wherever is appropriate).
  91.  
  92. This works for existing programs (in general) - localtime() performs
  93. the required call to settz() the first time it is called (directly
  94. or via ctime()).  There's no need to worry about who sets TZ, if
  95. its not set, getenv("TZ") will return (char *)0 and settz() will
  96. then use the appropriate local time for the host.  How settz()
  97. gets that information is an implementation matter.  The security
  98. problems (people faking local time for programs that expect it
  99. to be host local time, by setting TZ before running the program)
  100. can easily solved by causing those (comparatively few) programs
  101. to do "settz((char *)0)" before their first call to localtime().
  102.  
  103. What's missing:  So far here there is no mention of the "timezone name".
  104. None of the standard mechanisms is really adequate here.  The V7
  105. (and 4.xbsd) "timezone" function is clearly inadequate (although
  106. 4.2 bsd allows users to set the environment variable TZNAME to anything
  107. they like) since there can clearly be several possible names for the
  108. same offset, and "timezone" has no way to discover which one is wanted.
  109. Requiring the name to resice in the environment somewhere (Sys V) is also
  110. inadequate (there are too many problems about making sure it is set
  111. in all the right places).
  112.  
  113. Arthur Olson's scheme causes "localtime" to set a global variable
  114. "tz_abbr" to the correct string name for the timezone just used.
  115. I can't think of any cases where anything more than this is needed,
  116. but it is less flexible then "timezone()" and it would require
  117. programs that currently call timezone() to have to be altered.
  118. (He also has his version of "ctime" (but not "asctime") include
  119. the timezone in its output - I doubt if that is feasible for P1003,
  120. too many existing programs know what every byte in the returned
  121. string from ctime() contains.)
  122.  
  123. I solicit suggestions for what to do here - one might be to
  124. retain "timezone" but not require that it be capable of returning
  125. anything except the zone name corresponding to the last call of
  126. localtime() - then with ado's implementation it could simply
  127. ignore its arguments and return tz_abbr - I suspect that would
  128. satisfy all existing uses (and the ones it doesn't are quite
  129. likely not to work in general anyway).  Opinions?
  130.  
  131. There's also no discussion of how this relates to processes
  132. and images.  Not because there's anything doubtful here,
  133. but just because the necessary words take a lot of space.
  134. (informally, "the first call to localtime" is intended to
  135. be "the first after the program is exec'd, ignoring any
  136. fork()'s it may have since performed, as long as there
  137. has been no subsequent exec).  Getting this kind of thing
  138. right is essential for a standatds document, its not essential
  139. here.
  140.  
  141. ...................
  142.  
  143. A justification for all this ...  Today, just about 2 1/2 hours ago
  144. (it's early on a Sun morning as I write this) the daylight saving
  145. rules changed in at least 2 Australian states (no-one really seems
  146. very sure of what happened, or really why).  The politicians gave
  147. us less than a month's warning that it was coming (and the month
  148. was February, which isn't a long month...).
  149.  
  150. If there's anyone who doesn't believe that some form of dynamic
  151. timezone setting is required, they're welcome to come to Australia
  152. and suffer our local politicians (this isn't the first time: a
  153. couple of years ago New South Wales decided to extend daylight
  154. saving for a month to try and save on power bills - the amount of
  155. notice given was about the same - at that time, at least one local
  156. site decided to scrap running on GMT and run on localtime (ala VMS)
  157. instead.  They're still doing that, I think, and suffering because
  158. of it).
  159.  
  160. I'm extremely grateful that Arthur Olson decided to try an implementation,
  161. and donate it to the community - he made the task of converting things here
  162. much easier than it otherwise would have been.  His implementation
  163. meets the above specs (in fact, it inspired them...), and will work
  164. for all the contorted exampes that people have been proposing (multiple
  165. shifts in a year, multi-hour saving, even daylight wasting).
  166.  
  167. But note - there's no need for the standard to require this
  168. generality, market pressures will do that - all the standard
  169. needs to do is supply a suitable interface.  Arthur Olson's
  170. implementation proves that the above reccomendation is
  171. implementable (munnari is running his code, in libc, right now)
  172. and effecient enough.
  173.  
  174. [ Your last sentence gives the reason that I've encouraged
  175. discussions of implementations in the newsgroup:  it's good
  176. to know that a proposed standard is implementable and handles
  177. actual cases.  But you're right, of course, that the
  178. P1003 standard doesn't need implementation details.  -mod ]
  179.  
  180. Jack Jansen's (mcvax!jack) somewhat similar, but slightly different scheme
  181. would probably work just as well.
  182.  
  183. Bob Devine's (hao!asgb!devine) "I don't think its needed" attitude
  184. can also fit the standard - if he's right then he's probably going
  185. to have a very fast localtime() which will serve him well.
  186. If he's wrong, then he's not going to get many customers.
  187.  
  188. That's good - the more the better - that gives us users (or us system
  189. implementors perhaps) a wide choice of methods.
  190.  
  191. Robert Elz        kre%munnari.oz@seismo.css.gov    seismo!munnari!kre
  192.  
  193. Volume-Number: Volume 6, Number 31
  194.  
  195.