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