home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / std_unix / mod.std.unix.v5 / text0064.txt < prev    next >
Encoding:
Internet Message Format  |  1987-06-30  |  9.4 KB

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