getdate.texi 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421
  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 known
  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, Salz, Berets, 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 language, in dates
  87. In the current implementation, only English is supported for words and
  88. abbreviations like @samp{AM}, @samp{DST}, @samp{EST}, @samp{first},
  89. @samp{January}, @samp{Sunday}, @samp{tomorrow}, and @samp{year}.
  90. @cindex language, in dates
  91. @cindex time zone item
  92. The output of @command{date} is not always acceptable as a date string,
  93. not only because of the language problem, but also because there is no
  94. standard meaning for time zone items like @samp{IST}. When using
  95. @command{date} to generate a date string intended to be parsed later,
  96. specify a date format that is independent of language and that does not
  97. use time zone items other than @samp{UTC} and @samp{Z}. Here are some
  98. ways to do this:
  99. @example
  100. $ LC_ALL=C TZ=UTC0 date
  101. Fri Dec 15 19:48:05 UTC 2000
  102. $ TZ=UTC0 date +"%Y-%m-%d %H:%M:%SZ"
  103. 2000-12-15 19:48:05Z
  104. $ date --iso-8601=seconds # a GNU extension
  105. 2000-12-15T11:48:05-0800
  106. $ date --rfc-822 # a GNU extension
  107. Fri, 15 Dec 2000 11:48:05 -0800
  108. $ date +"%Y-%m-%d %H:%M:%S %z" # %z is a GNU extension.
  109. 2000-12-15 11:48:05 -0800
  110. @end example
  111. @cindex case, ignored in dates
  112. @cindex comments, in dates
  113. Alphabetic case is completely ignored in dates. Comments may be introduced
  114. between round parentheses, as long as included parentheses are properly
  115. nested. Hyphens not followed by a digit are currently ignored. Leading
  116. zeros on numbers are ignored.
  117. @node Calendar date items
  118. @section Calendar date items
  119. @cindex calendar date item
  120. A @dfn{calendar date item} specifies a day of the year. It is
  121. specified differently, depending on whether the month is specified
  122. numerically or literally. All these strings specify the same calendar date:
  123. @example
  124. 1972-09-24 # @sc{iso} 8601.
  125. 72-9-24 # Assume 19xx for 69 through 99,
  126. # 20xx for 00 through 68.
  127. 72-09-24 # Leading zeros are ignored.
  128. 9/24/72 # Common U.S. writing.
  129. 24 September 1972
  130. 24 Sept 72 # September has a special abbreviation.
  131. 24 Sep 72 # Three-letter abbreviations always allowed.
  132. Sep 24, 1972
  133. 24-sep-72
  134. 24sep72
  135. @end example
  136. The year can also be omitted. In this case, the last specified year is
  137. used, or the current year if none. For example:
  138. @example
  139. 9/24
  140. sep 24
  141. @end example
  142. Here are the rules.
  143. @cindex @sc{iso} 8601 date format
  144. @cindex date format, @sc{iso} 8601
  145. For numeric months, the @sc{iso} 8601 format
  146. @samp{@var{year}-@var{month}-@var{day}} is allowed, where @var{year} is
  147. any positive number, @var{month} is a number between 01 and 12, and
  148. @var{day} is a number between 01 and 31. A leading zero must be present
  149. if a number is less than ten. If @var{year} is 68 or smaller, then 2000
  150. is added to it; otherwise, if @var{year} is less than 100,
  151. then 1900 is added to it. The construct
  152. @samp{@var{month}/@var{day}/@var{year}}, popular in the United States,
  153. is accepted. Also @samp{@var{month}/@var{day}}, omitting the year.
  154. @cindex month names in date strings
  155. @cindex abbreviations for months
  156. Literal months may be spelled out in full: @samp{January},
  157. @samp{February}, @samp{March}, @samp{April}, @samp{May}, @samp{June},
  158. @samp{July}, @samp{August}, @samp{September}, @samp{October},
  159. @samp{November} or @samp{December}. Literal months may be abbreviated
  160. to their first three letters, possibly followed by an abbreviating dot.
  161. It is also permitted to write @samp{Sept} instead of @samp{September}.
  162. When months are written literally, the calendar date may be given as any
  163. of the following:
  164. @example
  165. @var{day} @var{month} @var{year}
  166. @var{day} @var{month}
  167. @var{month} @var{day} @var{year}
  168. @var{day}-@var{month}-@var{year}
  169. @end example
  170. Or, omitting the year:
  171. @example
  172. @var{month} @var{day}
  173. @end example
  174. @node Time of day items
  175. @section Time of day items
  176. @cindex time of day item
  177. A @dfn{time of day item} in date strings specifies the time on a given
  178. day. Here are some examples, all of which represent the same time:
  179. @example
  180. 20:02:0
  181. 20:02
  182. 8:02pm
  183. 20:02-0500 # In @sc{est} (U.S. Eastern Standard Time).
  184. @end example
  185. More generally, the time of the day may be given as
  186. @samp{@var{hour}:@var{minute}:@var{second}}, where @var{hour} is
  187. a number between 0 and 23, @var{minute} is a number between 0 and
  188. 59, and @var{second} is a number between 0 and 59. Alternatively,
  189. @samp{:@var{second}} can be omitted, in which case it is taken to
  190. be zero.
  191. @findex am @r{in date strings}
  192. @findex pm @r{in date strings}
  193. @findex midnight @r{in date strings}
  194. @findex noon @r{in date strings}
  195. If the time is followed by @samp{am} or @samp{pm} (or @samp{a.m.}
  196. or @samp{p.m.}), @var{hour} is restricted to run from 1 to 12, and
  197. @samp{:@var{minute}} may be omitted (taken to be zero). @samp{am}
  198. indicates the first half of the day, @samp{pm} indicates the second
  199. half of the day. In this notation, 12 is the predecessor of 1:
  200. midnight is @samp{12am} while noon is @samp{12pm}.
  201. (This is the zero-oriented interpretation of @samp{12am} and @samp{12pm},
  202. as opposed to the old tradition derived from Latin
  203. which uses @samp{12m} for noon and @samp{12pm} for midnight.)
  204. @cindex time zone correction
  205. @cindex minutes, time zone correction by
  206. The time may alternatively be followed by a time zone correction,
  207. expressed as @samp{@var{s}@var{hh}@var{mm}}, where @var{s} is @samp{+}
  208. or @samp{-}, @var{hh} is a number of zone hours and @var{mm} is a number
  209. of zone minutes. When a time zone correction is given this way, it
  210. forces interpretation of the time relative to
  211. Coordinated Universal Time (@sc{utc}), overriding any previous
  212. specification for the time zone or the local time zone. The @var{minute}
  213. part of the time of the day may not be elided when a time zone correction
  214. is used. This is the best way to specify a time zone correction by
  215. fractional parts of an hour.
  216. Either @samp{am}/@samp{pm} or a time zone correction may be specified,
  217. but not both.
  218. @node Time zone items
  219. @section Time zone items
  220. @cindex time zone item
  221. A @dfn{time zone item} specifies an international time zone, indicated
  222. by a small set of letters, e.g., @samp{UTC} or @samp{Z}
  223. for Coordinated Universal
  224. Time. Any included periods are ignored. By following a
  225. non-daylight-saving time zone by the string @samp{DST} in a separate
  226. word (that is, separated by some white space), the corresponding
  227. daylight saving time zone may be specified.
  228. Time zone items other than @samp{UTC} and @samp{Z}
  229. are obsolescent and are not recommended, because they
  230. are ambiguous; for example, @samp{EST} has a different meaning in
  231. Australia than in the United States. Instead, it's better to use
  232. unambiguous numeric time zone corrections like @samp{-0500}, as
  233. described in the previous section.
  234. @node Day of week items
  235. @section Day of week items
  236. @cindex day of week item
  237. The explicit mention of a day of the week will forward the date
  238. (only if necessary) to reach that day of the week in the future.
  239. Days of the week may be spelled out in full: @samp{Sunday},
  240. @samp{Monday}, @samp{Tuesday}, @samp{Wednesday}, @samp{Thursday},
  241. @samp{Friday} or @samp{Saturday}. Days may be abbreviated to their
  242. first three letters, optionally followed by a period. The special
  243. abbreviations @samp{Tues} for @samp{Tuesday}, @samp{Wednes} for
  244. @samp{Wednesday} and @samp{Thur} or @samp{Thurs} for @samp{Thursday} are
  245. also allowed.
  246. @findex next @var{day}
  247. @findex last @var{day}
  248. A number may precede a day of the week item to move forward
  249. supplementary weeks. It is best used in expression like @samp{third
  250. monday}. In this context, @samp{last @var{day}} or @samp{next
  251. @var{day}} is also acceptable; they move one week before or after
  252. the day that @var{day} by itself would represent.
  253. A comma following a day of the week item is ignored.
  254. @node Relative items in date strings
  255. @section Relative items in date strings
  256. @cindex relative items in date strings
  257. @cindex displacement of dates
  258. @dfn{Relative items} adjust a date (or the current date if none) forward
  259. or backward. The effects of relative items accumulate. Here are some
  260. examples:
  261. @example
  262. 1 year
  263. 1 year ago
  264. 3 years
  265. 2 days
  266. @end example
  267. @findex year @r{in date strings}
  268. @findex month @r{in date strings}
  269. @findex fortnight @r{in date strings}
  270. @findex week @r{in date strings}
  271. @findex day @r{in date strings}
  272. @findex hour @r{in date strings}
  273. @findex minute @r{in date strings}
  274. The unit of time displacement may be selected by the string @samp{year}
  275. or @samp{month} for moving by whole years or months. These are fuzzy
  276. units, as years and months are not all of equal duration. More precise
  277. units are @samp{fortnight} which is worth 14 days, @samp{week} worth 7
  278. days, @samp{day} worth 24 hours, @samp{hour} worth 60 minutes,
  279. @samp{minute} or @samp{min} worth 60 seconds, and @samp{second} or
  280. @samp{sec} worth one second. An @samp{s} suffix on these units is
  281. accepted and ignored.
  282. @findex ago @r{in date strings}
  283. The unit of time may be preceded by a multiplier, given as an optionally
  284. signed number. Unsigned numbers are taken as positively signed. No
  285. number at all implies 1 for a multiplier. Following a relative item by
  286. the string @samp{ago} is equivalent to preceding the unit by a
  287. multiplier with value @math{-1}.
  288. @findex day @r{in date strings}
  289. @findex tomorrow @r{in date strings}
  290. @findex yesterday @r{in date strings}
  291. The string @samp{tomorrow} is worth one day in the future (equivalent
  292. to @samp{day}), the string @samp{yesterday} is worth
  293. one day in the past (equivalent to @samp{day ago}).
  294. @findex now @r{in date strings}
  295. @findex today @r{in date strings}
  296. @findex this @r{in date strings}
  297. The strings @samp{now} or @samp{today} are relative items corresponding
  298. to zero-valued time displacement, these strings come from the fact
  299. a zero-valued time displacement represents the current time when not
  300. otherwise changed by previous items. They may be used to stress other
  301. items, like in @samp{12:00 today}. The string @samp{this} also has
  302. the meaning of a zero-valued time displacement, but is preferred in
  303. date strings like @samp{this thursday}.
  304. When a relative item causes the resulting date to cross a boundary
  305. where the clocks were adjusted, typically for daylight-saving time,
  306. the resulting date and time are adjusted accordingly.
  307. @node Pure numbers in date strings
  308. @section Pure numbers in date strings
  309. @cindex pure numbers in date strings
  310. The precise interpretation of a pure decimal number depends
  311. on the context in the date string.
  312. If the decimal number is of the form @var{yyyy}@var{mm}@var{dd} and no
  313. other calendar date item (@pxref{Calendar date items}) appears before it
  314. in the date string, then @var{yyyy} is read as the year, @var{mm} as the
  315. month number and @var{dd} as the day of the month, for the specified
  316. calendar date.
  317. If the decimal number is of the form @var{hh}@var{mm} and no other time
  318. of day item appears before it in the date string, then @var{hh} is read
  319. as the hour of the day and @var{mm} as the minute of the hour, for the
  320. specified time of the day. @var{mm} can also be omitted.
  321. If both a calendar date and a time of day appear to the left of a number
  322. in the date string, but no relative item, then the number overrides the
  323. year.
  324. @node Authors of getdate
  325. @section Authors of @code{getdate}
  326. @cindex authors of @code{getdate}
  327. @cindex Bellovin, Steven M.
  328. @cindex Salz, Rich
  329. @cindex Berets, Jim
  330. @cindex MacKenzie, David
  331. @cindex Meyering, Jim
  332. @cindex Eggert, Paul
  333. @code{getdate} was originally implemented by Steven M. Bellovin
  334. (@email{smb@@research.att.com}) while at the University of North Carolina
  335. at Chapel Hill. The code was later tweaked by a couple of people on
  336. Usenet, then completely overhauled by Rich $alz (@email{rsalz@@bbn.com})
  337. and Jim Berets (@email{jberets@@bbn.com}) in August, 1990. Various
  338. revisions for the @sc{gnu} system were made by David MacKenzie, Jim Meyering,
  339. Paul Eggert and others.
  340. @cindex Pinard, F.
  341. @cindex Berry, K.
  342. This chapter was originally produced by Fran@,{c}ois Pinard
  343. (@email{pinard@@iro.umontreal.ca}) from the @file{getdate.y} source code,
  344. and then edited by K.@: Berry (@email{kb@@cs.umb.edu}).