getdate.texi 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392
  1. @node Date input formats
  2. @chapter Date input formats
  3. @cindex date input formats
  4. @findex getdate
  5. First, a quote:
  6. @quotation
  7. Our units of temporal measurement, from seconds on up to months, are so
  8. complicated, asymmetrical and disjunctive so as to make coherent mental
  9. reckoning in time all but impossible. Indeed, had some tyrannical god
  10. contrived to enslave our minds to time, to make it all but impossible
  11. for us to escape subjection to sodden routines and unpleasant surprises,
  12. he could hardly have done better than handing down our present system.
  13. It is like a set of trapezoidal building blocks, with no vertical or
  14. horizontal surfaces, like a language in which the simplest thought
  15. demands ornate constructions, useless particles and lengthy
  16. circumlocutions. Unlike the more successful patterns of language and
  17. science, which enable us to face experience boldly or at least
  18. level-headedly, our system of temporal calculation silently and
  19. persistently encourages our terror of time.
  20. @dots{} It is as though architects had to measure length in feet, width
  21. in meters and height in ells; as though basic instruction manuals
  22. demanded a knowledge of five different languages. It is no wonder then
  23. that we often look into our own immediate past or future, last Tuesday
  24. or a week from Sunday, with feelings of helpless confusion. @dots{}
  25. --- Robert Grudin, @cite{Time and the Art of Living}.
  26. @end quotation
  27. This section describes the textual date representations that @sc{gnu}
  28. programs accept. These are the strings you, as a user, can supply as
  29. arguments to the various programs. The C interface (via the
  30. @code{getdate} function) is not described here.
  31. @cindex beginning of time, for @sc{posix}
  32. @cindex epoch, for @sc{posix}
  33. Although the date syntax here can represent any possible time since the
  34. year zero, computer integers often cannot represent such a wide range of
  35. time. On @sc{posix} systems, the clock starts at 1970-01-01 00:00:00
  36. @sc{utc}: @sc{posix} does not require support for times before the
  37. @sc{posix} Epoch and times far in the future. Traditional Unix systems
  38. have 32-bit signed @code{time_t} and can represent times from 1901-12-13
  39. 20:45:52 through 2038-01-19 03:14:07 @sc{utc}. Systems with 64-bit
  40. signed @code{time_t} can represent all the times in the expected
  41. lifetime of the universe.
  42. @menu
  43. * General date syntax:: Common rules.
  44. * Calendar date items:: 19 Dec 1994.
  45. * Time of day items:: 9:20pm.
  46. * Time zone items:: @sc{est}, @sc{pdt}, @sc{gmt}, ...
  47. * Day of week items:: Monday and others.
  48. * Relative items in date strings:: next tuesday, 2 years ago.
  49. * Pure numbers in date strings:: 19931219, 1440.
  50. * Authors of getdate:: Bellovin, Eggert, Berets, Salz, et al.
  51. @end menu
  52. @node General date syntax
  53. @section General date syntax
  54. @cindex general date syntax
  55. @cindex items in date strings
  56. A @dfn{date} is a string, possibly empty, containing many items
  57. separated by whitespace. The whitespace may be omitted when no
  58. ambiguity arises. The empty string means the beginning of today (i.e.,
  59. midnight). Order of the items is immaterial. A date string may contain
  60. many flavors of items:
  61. @itemize @bullet
  62. @item calendar date items
  63. @item time of the day items
  64. @item time zone items
  65. @item day of the week items
  66. @item relative items
  67. @item pure numbers.
  68. @end itemize
  69. @noindent We describe each of these item types in turn, below.
  70. @cindex numbers, written-out
  71. @cindex ordinal numbers
  72. @findex first @r{in date strings}
  73. @findex next @r{in date strings}
  74. @findex last @r{in date strings}
  75. A few numbers may be written out in words in most contexts. This is
  76. most useful for specifying day of the week items or relative items (see
  77. below). Here is the list: @samp{first} for 1, @samp{next} for 2,
  78. @samp{third} for 3, @samp{fourth} for 4, @samp{fifth} for 5,
  79. @samp{sixth} for 6, @samp{seventh} for 7, @samp{eighth} for 8,
  80. @samp{ninth} for 9, @samp{tenth} for 10, @samp{eleventh} for 11 and
  81. @samp{twelfth} for 12. Also, @samp{last} means exactly @math{-1}.
  82. @cindex months, written-out
  83. When a month is written this way, it is still considered to be written
  84. numerically, instead of being ``spelled in full''; this changes the
  85. allowed strings.
  86. @cindex case, ignored in dates
  87. @cindex comments, in dates
  88. Alphabetic case is completely ignored in dates. Comments may be introduced
  89. between round parentheses, as long as included parentheses are properly
  90. nested. Hyphens not followed by a digit are currently ignored. Leading
  91. zeros on numbers are ignored.
  92. @node Calendar date items
  93. @section Calendar date items
  94. @cindex calendar date item
  95. A @dfn{calendar date item} specifies a day of the year. It is
  96. specified differently, depending on whether the month is specified
  97. numerically or literally. All these strings specify the same calendar date:
  98. @example
  99. 1972-09-24 # @sc{iso} 8601.
  100. 72-9-24 # Assume 19xx for 69 through 99,
  101. # 20xx for 00 through 68.
  102. 72-09-24 # Leading zeros are ignored.
  103. 9/24/72 # Common U.S. writing.
  104. 24 September 1972
  105. 24 Sept 72 # September has a special abbreviation.
  106. 24 Sep 72 # Three-letter abbreviations always allowed.
  107. Sep 24, 1972
  108. 24-sep-72
  109. 24sep72
  110. @end example
  111. The year can also be omitted. In this case, the last specified year is
  112. used, or the current year if none. For example:
  113. @example
  114. 9/24
  115. sep 24
  116. @end example
  117. Here are the rules.
  118. @cindex @sc{iso} 8601 date format
  119. @cindex date format, @sc{iso} 8601
  120. For numeric months, the @sc{iso} 8601 format
  121. @samp{@var{year}-@var{month}-@var{day}} is allowed, where @var{year} is
  122. any positive number, @var{month} is a number between 01 and 12, and
  123. @var{day} is a number between 01 and 31. A leading zero must be present
  124. if a number is less than ten. If @var{year} is 68 or smaller, then 2000
  125. is added to it; otherwise, if @var{year} is less than 100,
  126. then 1900 is added to it. The construct
  127. @samp{@var{month}/@var{day}/@var{year}}, popular in the United States,
  128. is accepted. Also @samp{@var{month}/@var{day}}, omitting the year.
  129. @cindex month names in date strings
  130. @cindex abbreviations for months
  131. Literal months may be spelled out in full: @samp{January},
  132. @samp{February}, @samp{March}, @samp{April}, @samp{May}, @samp{June},
  133. @samp{July}, @samp{August}, @samp{September}, @samp{October},
  134. @samp{November} or @samp{December}. Literal months may be abbreviated
  135. to their first three letters, possibly followed by an abbreviating dot.
  136. It is also permitted to write @samp{Sept} instead of @samp{September}.
  137. When months are written literally, the calendar date may be given as any
  138. of the following:
  139. @example
  140. @var{day} @var{month} @var{year}
  141. @var{day} @var{month}
  142. @var{month} @var{day} @var{year}
  143. @var{day}-@var{month}-@var{year}
  144. @end example
  145. Or, omitting the year:
  146. @example
  147. @var{month} @var{day}
  148. @end example
  149. @node Time of day items
  150. @section Time of day items
  151. @cindex time of day item
  152. A @dfn{time of day item} in date strings specifies the time on a given
  153. day. Here are some examples, all of which represent the same time:
  154. @example
  155. 20:02:0
  156. 20:02
  157. 8:02pm
  158. 20:02-0500 # In @sc{est} (U.S. Eastern Standard Time).
  159. @end example
  160. More generally, the time of the day may be given as
  161. @samp{@var{hour}:@var{minute}:@var{second}}, where @var{hour} is
  162. a number between 0 and 23, @var{minute} is a number between 0 and
  163. 59, and @var{second} is a number between 0 and 59. Alternatively,
  164. @samp{:@var{second}} can be omitted, in which case it is taken to
  165. be zero.
  166. @findex am @r{in date strings}
  167. @findex pm @r{in date strings}
  168. @findex midnight @r{in date strings}
  169. @findex noon @r{in date strings}
  170. If the time is followed by @samp{am} or @samp{pm} (or @samp{a.m.}
  171. or @samp{p.m.}), @var{hour} is restricted to run from 1 to 12, and
  172. @samp{:@var{minute}} may be omitted (taken to be zero). @samp{am}
  173. indicates the first half of the day, @samp{pm} indicates the second
  174. half of the day. In this notation, 12 is the predecessor of 1:
  175. midnight is @samp{12am} while noon is @samp{12pm}.
  176. (This is the zero-oriented interpretation of @samp{12am} and @samp{12pm},
  177. as opposed to the old tradition derived from Latin
  178. which uses @samp{12m} for noon and @samp{12pm} for midnight.)
  179. @cindex time zone correction
  180. @cindex minutes, time zone correction by
  181. The time may alternatively be followed by a time zone correction,
  182. expressed as @samp{@var{s}@var{hh}@var{mm}}, where @var{s} is @samp{+}
  183. or @samp{-}, @var{hh} is a number of zone hours and @var{mm} is a number
  184. of zone minutes. When a time zone correction is given this way, it
  185. forces interpretation of the time relative to
  186. Coordinated Universal Time (@sc{utc}), overriding any previous
  187. specification for the time zone or the local time zone. The @var{minute}
  188. part of the time of the day may not be elided when a time zone correction
  189. is used. This is the best way to specify a time zone correction by
  190. fractional parts of an hour.
  191. Either @samp{am}/@samp{pm} or a time zone correction may be specified,
  192. but not both.
  193. @node Time zone items
  194. @section Time zone items
  195. @cindex time zone item
  196. A @dfn{time zone item} specifies an international time zone, indicated
  197. by a small set of letters, e.g., @samp{UTC} for Coordinated Universal
  198. Time. Any included periods are ignored. By following a
  199. non-daylight-saving time zone by the string @samp{DST} in a separate
  200. word (that is, separated by some white space), the corresponding
  201. daylight saving time zone may be specified.
  202. Time zone items are obsolescent and are not recommended, because they
  203. are ambiguous; for example, @samp{EST} has a different meaning in
  204. Australia than in the United States. Instead, it's better to use
  205. unambiguous numeric time zone corrections like @samp{-0500}, as
  206. described in the previous section.
  207. @node Day of week items
  208. @section Day of week items
  209. @cindex day of week item
  210. The explicit mention of a day of the week will forward the date
  211. (only if necessary) to reach that day of the week in the future.
  212. Days of the week may be spelled out in full: @samp{Sunday},
  213. @samp{Monday}, @samp{Tuesday}, @samp{Wednesday}, @samp{Thursday},
  214. @samp{Friday} or @samp{Saturday}. Days may be abbreviated to their
  215. first three letters, optionally followed by a period. The special
  216. abbreviations @samp{Tues} for @samp{Tuesday}, @samp{Wednes} for
  217. @samp{Wednesday} and @samp{Thur} or @samp{Thurs} for @samp{Thursday} are
  218. also allowed.
  219. @findex next @var{day}
  220. @findex last @var{day}
  221. A number may precede a day of the week item to move forward
  222. supplementary weeks. It is best used in expression like @samp{third
  223. monday}. In this context, @samp{last @var{day}} or @samp{next
  224. @var{day}} is also acceptable; they move one week before or after
  225. the day that @var{day} by itself would represent.
  226. A comma following a day of the week item is ignored.
  227. @node Relative items in date strings
  228. @section Relative items in date strings
  229. @cindex relative items in date strings
  230. @cindex displacement of dates
  231. @dfn{Relative items} adjust a date (or the current date if none) forward
  232. or backward. The effects of relative items accumulate. Here are some
  233. examples:
  234. @example
  235. 1 year
  236. 1 year ago
  237. 3 years
  238. 2 days
  239. @end example
  240. @findex year @r{in date strings}
  241. @findex month @r{in date strings}
  242. @findex fortnight @r{in date strings}
  243. @findex week @r{in date strings}
  244. @findex day @r{in date strings}
  245. @findex hour @r{in date strings}
  246. @findex minute @r{in date strings}
  247. The unit of time displacement may be selected by the string @samp{year}
  248. or @samp{month} for moving by whole years or months. These are fuzzy
  249. units, as years and months are not all of equal duration. More precise
  250. units are @samp{fortnight} which is worth 14 days, @samp{week} worth 7
  251. days, @samp{day} worth 24 hours, @samp{hour} worth 60 minutes,
  252. @samp{minute} or @samp{min} worth 60 seconds, and @samp{second} or
  253. @samp{sec} worth one second. An @samp{s} suffix on these units is
  254. accepted and ignored.
  255. @findex ago @r{in date strings}
  256. The unit of time may be preceded by a multiplier, given as an optionally
  257. signed number. Unsigned numbers are taken as positively signed. No
  258. number at all implies 1 for a multiplier. Following a relative item by
  259. the string @samp{ago} is equivalent to preceding the unit by a
  260. multiplier with value @math{-1}.
  261. @findex day @r{in date strings}
  262. @findex tomorrow @r{in date strings}
  263. @findex yesterday @r{in date strings}
  264. The string @samp{tomorrow} is worth one day in the future (equivalent
  265. to @samp{day}), the string @samp{yesterday} is worth
  266. one day in the past (equivalent to @samp{day ago}).
  267. @findex now @r{in date strings}
  268. @findex today @r{in date strings}
  269. @findex this @r{in date strings}
  270. The strings @samp{now} or @samp{today} are relative items corresponding
  271. to zero-valued time displacement, these strings come from the fact
  272. a zero-valued time displacement represents the current time when not
  273. otherwise changed by previous items. They may be used to stress other
  274. items, like in @samp{12:00 today}. The string @samp{this} also has
  275. the meaning of a zero-valued time displacement, but is preferred in
  276. date strings like @samp{this thursday}.
  277. When a relative item causes the resulting date to cross a boundary
  278. where the clocks were adjusted, typically for daylight-saving time,
  279. the resulting date and time are adjusted accordingly.
  280. @node Pure numbers in date strings
  281. @section Pure numbers in date strings
  282. @cindex pure numbers in date strings
  283. The precise interpretation of a pure decimal number depends
  284. the context in the date string.
  285. If the decimal number is of the form @var{yyyy}@var{mm}@var{dd} and no
  286. other calendar date item (@pxref{Calendar date items}) appears before it
  287. in the date string, then @var{yyyy} is read as the year, @var{mm} as the
  288. month number and @var{dd} as the day of the month, for the specified
  289. calendar date.
  290. If the decimal number is of the form @var{hh}@var{mm} and no other time
  291. of day item appears before it in the date string, then @var{hh} is read
  292. as the hour of the day and @var{mm} as the minute of the hour, for the
  293. specified time of the day. @var{mm} can also be omitted.
  294. If both a calendar date and a time of day appear to the left of a number
  295. in the date string, but no relative item, then the number overrides the
  296. year.
  297. @node Authors of getdate
  298. @section Authors of @code{getdate}
  299. @cindex authors of @code{getdate}
  300. @cindex Bellovin, Steven M.
  301. @cindex Berets, Jim
  302. @cindex Eggert, Paul
  303. @cindex MacKenzie, David
  304. @cindex Meyering, Jim
  305. @cindex Salz, Rich
  306. @code{getdate} was originally implemented by Steven M. Bellovin
  307. (@email{smb@@research.att.com}) while at the University of North Carolina
  308. at Chapel Hill. The code was later tweaked by a couple of people on
  309. Usenet, then completely overhauled by Rich $alz (@email{rsalz@@bbn.com})
  310. and Jim Berets (@email{jberets@@bbn.com}) in August, 1990. Various
  311. revisions for the @sc{gnu} system were made by David MacKenzie, Jim Meyering,
  312. and others. The code was rewritten again in 1999 by Paul Eggert,
  313. to improve its support for daylight saving time.
  314. @cindex Pinard, F.
  315. @cindex Berry, K.
  316. This chapter was originally produced by Fran@,{c}ois Pinard
  317. (@email{pinard@@iro.umontreal.ca}) from the @file{getdate.y} source code,
  318. and then edited by K.@: Berry (@email{kb@@cs.umb.edu}).