4
0

getdate.texi 16 KB

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