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