getdate.texi 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483
  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 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 Unix
  32. @cindex epoch, for Unix
  33. Although the date syntax here can represent any possible time since zero
  34. A.D., computer integers are not big enough for such a (comparatively)
  35. long time. The earliest date semantically allowed on Unix systems is
  36. midnight, 1 January 1970 UCT.
  37. @menu
  38. * General date syntax:: Common rules.
  39. * Calendar date items:: 19 Dec 1994.
  40. * Time of day items:: 9:20pm.
  41. * Time zone items:: EST, DST, BST, UTC, ...
  42. * Day of week items:: Monday and others.
  43. * Relative items in date strings:: next tuesday, 2 years ago.
  44. * Pure numbers in date strings:: 19931219, 1440.
  45. * Authors of getdate:: Bellovin, Salz, Berets, et al.
  46. @end menu
  47. @node General date syntax
  48. @section General date syntax
  49. @cindex general date syntax
  50. @cindex items in date strings
  51. A @dfn{date} is a string, possibly empty, containing many items
  52. separated by whitespace. The whitespace may be omitted when no
  53. ambiguity arises. The empty string means the beginning of today (i.e.,
  54. midnight). Order of the items is immaterial. A date string may contain
  55. many flavors of items:
  56. @itemize @bullet
  57. @item calendar date items
  58. @item time of the day items
  59. @item time zone items
  60. @item day of the week items
  61. @item relative items
  62. @item pure numbers.
  63. @end itemize
  64. @noindent We describe each of these item types in turn, below.
  65. @cindex numbers, written-out
  66. @cindex ordinal numbers
  67. @findex first @r{in date strings}
  68. @findex next @r{in date strings}
  69. @findex last @r{in date strings}
  70. A few numbers may be written out in words in most contexts. This is
  71. most useful for specifying day of the week items or relative items (see
  72. below). Here is the list: @samp{first} for 1, @samp{next} for 2,
  73. @samp{third} for 3, @samp{fourth} for 4, @samp{fifth} for 5,
  74. @samp{sixth} for 6, @samp{seventh} for 7, @samp{eighth} for 8,
  75. @samp{ninth} for 9, @samp{tenth} for 10, @samp{eleventh} for 11 and
  76. @samp{twelfth} for 12. Also, @samp{last} means exactly @math{-1}.
  77. @cindex months, written-out
  78. When a month is written this way, it is still considered to be written
  79. numerically, instead of being ``spelled in full''; this changes the
  80. allowed strings.
  81. @cindex case, ignored in dates
  82. @cindex comments, in dates
  83. Alphabetic case is completely ignored in dates. Comments may be introduced
  84. between round parentheses, as long as included parentheses are properly
  85. nested. Hyphens not followed by a digit are currently ignored. Leading
  86. zeros on numbers are ignored.
  87. @node Calendar date items
  88. @section Calendar date items
  89. @cindex calendar date item
  90. A @dfn{calendar date item} specifies a day of the year. It is
  91. specified differently, depending on whether the month is specified
  92. numerically or literally. All these strings specify the same calendar date:
  93. @example
  94. 1972-09-24 # ISO 8601.
  95. 72-9-24 # Assume 19xx for 69 through 99,
  96. # 20xx for 00 through 68.
  97. 72-09-24 # Leading zeros are ignored.
  98. 9/24/72 # Common U.S. writing.
  99. 24 September 1972
  100. 24 Sept 72 # September has a special abbreviation.
  101. 24 Sep 72 # Three-letter abbreviations always allowed.
  102. Sep 24, 1972
  103. 24-sep-72
  104. 24sep72
  105. @end example
  106. The year can also be omitted. In this case, the last specified year is
  107. used, or the current year if none. For example:
  108. @example
  109. 9/24
  110. sep 24
  111. @end example
  112. Here are the rules.
  113. @cindex ISO 8601 date format
  114. @cindex date format, ISO 8601
  115. For numeric months, the ISO 8601 format
  116. @samp{@var{year}-@var{month}-@var{day}} is allowed, where @var{year} is
  117. any positive number, @var{month} is a number between 01 and 12, and
  118. @var{day} is a number between 01 and 31. A leading zero must be present
  119. if a number is less than ten. If @var{year} is 68 or smaller, then 2000
  120. is added to it; otherwise, if @var{year} is less than 100,
  121. then 1900 is added to it. The construct
  122. @samp{@var{month}/@var{day}/@var{year}}, popular in the United States,
  123. is accepted. Also @samp{@var{month}/@var{day}}, omitting the year.
  124. @cindex month names in date strings
  125. @cindex abbreviations for months
  126. Literal months may be spelled out in full: @samp{January},
  127. @samp{February}, @samp{March}, @samp{April}, @samp{May}, @samp{June},
  128. @samp{July}, @samp{August}, @samp{September}, @samp{October},
  129. @samp{November} or @samp{December}. Literal months may be abbreviated
  130. to their first three letters, possibly followed by an abbreviating dot.
  131. It is also permitted to write @samp{Sept} instead of @samp{September}.
  132. When months are written literally, the calendar date may be given as any
  133. of the following:
  134. @example
  135. @var{day} @var{month} @var{year}
  136. @var{day} @var{month}
  137. @var{month} @var{day} @var{year}
  138. @var{day}-@var{month}-@var{year}
  139. @end example
  140. Or, omitting the year:
  141. @example
  142. @var{month} @var{day}
  143. @end example
  144. @node Time of day items
  145. @section Time of day items
  146. @cindex time of day item
  147. A @dfn{time of day item} in date strings specifies the time on a given
  148. day. Here are some examples, all of which represent the same time:
  149. @example
  150. 20:02:0
  151. 20:02
  152. 8:02pm
  153. 20:02-0500 # In EST (Eastern U.S. Standard Time).
  154. @end example
  155. More generally, the time of the day may be given as
  156. @samp{@var{hour}:@var{minute}:@var{second}}, where @var{hour} is
  157. a number between 0 and 23, @var{minute} is a number between 0 and
  158. 59, and @var{second} is a number between 0 and 59. Alternatively,
  159. @samp{:@var{second}} can be omitted, in which case it is taken to
  160. be zero.
  161. @findex am @r{in date strings}
  162. @findex pm @r{in date strings}
  163. @findex midnight @r{in date strings}
  164. @findex noon @r{in date strings}
  165. If the time is followed by @samp{am} or @samp{pm} (or @samp{a.m.}
  166. or @samp{p.m.}), @var{hour} is restricted to run from 1 to 12, and
  167. @samp{:@var{minute}} may be omitted (taken to be zero). @samp{am}
  168. indicates the first half of the day, @samp{pm} indicates the second
  169. half of the day. In this notation, 12 is the predecessor of 1:
  170. midnight is @samp{12am} while noon is @samp{12pm}.
  171. @cindex time zone correction
  172. @cindex minutes, time zone correction by
  173. The time may alternatively be followed by a time zone correction,
  174. expressed as @samp{@var{s}@var{hh}@var{mm}}, where @var{s} is @samp{+}
  175. or @samp{-}, @var{hh} is a number of zone hours and @var{mm} is a number
  176. of zone minutes. When a time zone correction is given this way, it
  177. forces interpretation of the time relative to
  178. Coordinated Universal Time (UTC), overriding any previous
  179. specification for the time zone or the local time zone. The @var{minute}
  180. part of the time of the day may not be elided when a time zone correction
  181. is used. This is the only way to specify a time zone correction by
  182. fractional parts of an hour.
  183. Either @samp{am}/@samp{pm} or a time zone correction may be specified,
  184. but not both.
  185. @node Time zone items
  186. @section Time zone items
  187. @cindex time zone item
  188. A @dfn{time zone item} specifies an international time zone, indicated by
  189. a small set of letters. They are supported for backward compatibility reasons,
  190. but they are not recommended because they are ambiguous in practice:
  191. for example, the abbreviation @samp{EST} has different meanings in
  192. Australia and the United States. Any included period is ignored. Military
  193. time zone designations use a single letter. Currently, only integral
  194. zone hours may be represented in a time zone item. See the previous
  195. section for a finer control over the time zone correction.
  196. Here are many non-daylight-saving-time time zones, indexed by the zone
  197. hour value.
  198. @table @asis
  199. @item -1200
  200. @samp{Y} for militaries.
  201. @item -1100
  202. @samp{X} for militaries.
  203. @item -1000
  204. @samp{W} for militaries.
  205. @item -0900
  206. @samp{V} for militaries.
  207. @item -0800
  208. @samp{PST} for Pacific Standard, and
  209. @samp{U} for militaries.
  210. @item -0700
  211. @samp{MST} for Mountain Standard, and
  212. @samp{T} for militaries.
  213. @item -0600
  214. @samp{CST} for Central Standard, and
  215. @samp{S} for militaries.
  216. @item -0500
  217. @samp{EST} for Eastern Standard, and
  218. @samp{R} for militaries.
  219. @item -0400
  220. @samp{AST} for Atlantic Standard, and
  221. @samp{Q} for militaries.
  222. @item -0300
  223. @samp{P} for militaries.
  224. @item -0200
  225. @samp{O} for militaries.
  226. @item -0100
  227. @samp{N} for militaries.
  228. @item +0000
  229. @cindex Greenwich Mean Time
  230. @cindex Coordinated Universal Time
  231. @cindex Universal Coordinated Time
  232. @cindex Universal Time (Coordinated)
  233. @samp{GMT} for Greenwich Mean,
  234. @samp{UT} for Universal,
  235. @samp{UTC} for Coordinated Universal,
  236. @samp{WET} for Western European, and
  237. @samp{Z} for ISO 8601 and militaries.
  238. @item +0100
  239. @samp{A} for militaries,
  240. @samp{CET} for Central European,
  241. @samp{MET} for Midden Europesche Tijd (Dutch), and
  242. @samp{MEZ} for Mittel-Europ@"aische Zeit (German).
  243. @item +0200
  244. @samp{B} for militaries, and
  245. @samp{EET} for Eastern European.
  246. @item +0300
  247. @samp{C} for militaries.
  248. @item +0400
  249. @samp{D} for militaries.
  250. @item +0500
  251. @samp{E} for militaries.
  252. @item +0600
  253. @samp{F} for militaries.
  254. @item +0700
  255. @samp{G} for militaries.
  256. @item +0800
  257. @samp{H} for militaries.
  258. @item +0900
  259. @samp{I} for militaries, and
  260. @samp{JST} for Japan Standard.
  261. @item +1000
  262. @samp{GST} for Guam Standard, and
  263. @samp{K} for militaries.
  264. @item +1100
  265. @samp{L} for militaries.
  266. @item +1200
  267. @samp{M} for militaries, and
  268. @samp{NZST} for New Zealand Standard.
  269. @end table
  270. @cindex daylight-saving time
  271. Here are many daylight-saving time (DST) time zones,
  272. indexed by the zone hour value. Also, by
  273. following a non-DST time zone by the string @samp{DST} in a separate word
  274. (that is, separated by some whitespace), the corresponding DST time zone
  275. may be specified.
  276. @table @asis
  277. @item -0700
  278. @samp{PDT} for Pacific Daylight.
  279. @item -0600
  280. @samp{MDT} for Mountain Daylight.
  281. @item -0500
  282. @samp{CDT} for Central Daylight.
  283. @item -0400
  284. @samp{EDT} for Eastern Daylight.
  285. @item -0300
  286. @samp{ADT} for Atlantic Daylight.
  287. @item +0100
  288. @samp{BST} for British Summer, and
  289. @samp{WEST} for Western European Summer.
  290. @item +0200
  291. @samp{CEST} for Central European Summer,
  292. @samp{MEST} for Midden Europesche S. Tijd (Dutch), and
  293. @samp{MESZ} for Mittel-Europ@"aische Sommerzeit (German).
  294. @item +1300
  295. @samp{NZDT} for New Zealand Daylight.
  296. @end table
  297. @node Day of week items
  298. @section Day of week items
  299. @cindex day of week item
  300. The explicit mention of a day of the week will forward the date
  301. (only if necessary) to reach that day of the week in the future.
  302. Days of the week may be spelled out in full: @samp{Sunday},
  303. @samp{Monday}, @samp{Tuesday}, @samp{Wednesday}, @samp{Thursday},
  304. @samp{Friday} or @samp{Saturday}. Days may be abbreviated to their
  305. first three letters, optionally followed by a period. The special
  306. abbreviations @samp{Tues} for @samp{Tuesday}, @samp{Wednes} for
  307. @samp{Wednesday} and @samp{Thur} or @samp{Thurs} for @samp{Thursday} are
  308. also allowed.
  309. @findex next @var{day}
  310. @findex last @var{day}
  311. A number may precede a day of the week item to move forward
  312. supplementary weeks. It is best used in expression like @samp{third
  313. monday}. In this context, @samp{last @var{day}} or @samp{next
  314. @var{day}} is also acceptable; they move one week before or after
  315. the day that @var{day} by itself would represent.
  316. A comma following a day of the week item is ignored.
  317. @node Relative items in date strings
  318. @section Relative items in date strings
  319. @cindex relative items in date strings
  320. @cindex displacement of dates
  321. @dfn{Relative items} adjust a date (or the current date if none) forward
  322. or backward. The effects of relative items accumulate. Here are some
  323. examples:
  324. @example
  325. 1 year
  326. 1 year ago
  327. 3 years
  328. 2 days
  329. @end example
  330. @findex year @r{in date strings}
  331. @findex month @r{in date strings}
  332. @findex fortnight @r{in date strings}
  333. @findex week @r{in date strings}
  334. @findex day @r{in date strings}
  335. @findex hour @r{in date strings}
  336. @findex minute @r{in date strings}
  337. The unit of time displacement may be selected by the string @samp{year}
  338. or @samp{month} for moving by whole years or months. These are fuzzy
  339. units, as years and months are not all of equal duration. More precise
  340. units are @samp{fortnight} which is worth 14 days, @samp{week} worth 7
  341. days, @samp{day} worth 24 hours, @samp{hour} worth 60 minutes,
  342. @samp{minute} or @samp{min} worth 60 seconds, and @samp{second} or
  343. @samp{sec} worth one second. An @samp{s} suffix on these units is
  344. accepted and ignored.
  345. @findex ago @r{in date strings}
  346. The unit of time may be preceded by a multiplier, given as an optionally
  347. signed number. Unsigned numbers are taken as positively signed. No
  348. number at all implies 1 for a multiplier. Following a relative item by
  349. the string @samp{ago} is equivalent to preceding the unit by a
  350. multiplicator with value @math{-1}.
  351. @findex day @r{in date strings}
  352. @findex tomorrow @r{in date strings}
  353. @findex yesterday @r{in date strings}
  354. The string @samp{tomorrow} is worth one day in the future (equivalent
  355. to @samp{day}), the string @samp{yesterday} is worth
  356. one day in the past (equivalent to @samp{day ago}).
  357. @findex now @r{in date strings}
  358. @findex today @r{in date strings}
  359. @findex this @r{in date strings}
  360. The strings @samp{now} or @samp{today} are relative items corresponding
  361. to zero-valued time displacement, these strings come from the fact
  362. a zero-valued time displacement represents the current time when not
  363. otherwise changed by previous items. They may be used to stress other
  364. items, like in @samp{12:00 today}. The string @samp{this} also has
  365. the meaning of a zero-valued time displacement, but is preferred in
  366. date strings like @samp{this thursday}.
  367. When a relative item causes the resulting date to cross the boundary
  368. between DST and non-DST (or vice-versa), the hour is adjusted according
  369. to the local time.
  370. @node Pure numbers in date strings
  371. @section Pure numbers in date strings
  372. @cindex pure numbers in date strings
  373. The precise intepretation of a pure decimal number depends
  374. the context in the date string.
  375. If the decimal number is of the form @var{yyyy}@var{mm}@var{dd} and no
  376. other calendar date item (@pxref{Calendar date items}) appears before it
  377. in the date string, then @var{yyyy} is read as the year, @var{mm} as the
  378. month number and @var{dd} as the day of the month, for the specified
  379. calendar date.
  380. If the decimal number is of the form @var{hh}@var{mm} and no other time
  381. of day item appears before it in the date string, then @var{hh} is read
  382. as the hour of the day and @var{mm} as the minute of the hour, for the
  383. specified time of the day. @var{mm} can also be omitted.
  384. If both a calendar date and a time of day appear to the left of a number
  385. in the date string, but no relative item, then the number overrides the
  386. year.
  387. @node Authors of getdate
  388. @section Authors of @code{getdate}
  389. @cindex authors of @code{getdate}
  390. @cindex Bellovin, Steven M.
  391. @cindex Salz, Rich
  392. @cindex Berets, Jim
  393. @cindex MacKenzie, David
  394. @cindex Meyering, Jim
  395. @code{getdate} was originally implemented by Steven M. Bellovin
  396. (@email{smb@@research.att.com}) while at the University of North Carolina
  397. at Chapel Hill. The code was later tweaked by a couple of people on
  398. Usenet, then completely overhauled by Rich $alz (@email{rsalz@@bbn.com})
  399. and Jim Berets (@email{jberets@@bbn.com}) in August, 1990. Various
  400. revisions for the GNU system were made by David MacKenzie, Jim Meyering,
  401. and others.
  402. @cindex Pinard, F.
  403. @cindex Berry, K.
  404. This chapter was originally produced by Fran@,{c}ois Pinard
  405. (@email{pinard@@iro.umontreal.ca}) from the @file{getdate.y} source code,
  406. and then edited by K.@: Berry (@email{kb@@cs.umb.edu}).