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