1 @node Date input formats
2 @chapter Date input formats
4 @cindex date input formats
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.
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{}
30 --- Robert Grudin, @cite{Time and the Art of Living}.
33 This section describes the textual date representations that 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.
38 @cindex beginning of time, for Unix
39 @cindex epoch, for Unix
40 Although the date syntax here can represent any possible time since zero
41 A.D., computer integers are not big enough for such a (comparatively)
42 long time. The earliest date semantically allowed on Unix systems is
43 midnight, 1 January 1970 UCT.
46 * General date syntax:: Common rules.
47 * Calendar date item:: 19 Dec 1994.
48 * Time of day item:: 9:20pm.
49 * Time zone item:: EST, DST, BST, UTC, ...
50 * Day of week item:: Monday and others.
51 * Relative item in date strings:: next tuesday, 2 years ago.
52 * Pure numbers in date strings:: 19931219, 1440.
53 * Authors of getdate:: Bellovin, Salz, Berets, et al.
57 @node General date syntax
58 @section General date syntax
60 @cindex general date syntax
62 @cindex items in date strings
63 A @dfn{date} is a string, possibly empty, containing many items
64 separated by whitespace. The whitespace may be omitted when no
65 ambiguity arises. The empty string means the beginning of today (i.e.,
66 midnight). Order of the items is immaterial. A date string may contain
67 many flavors of items:
70 @item calendar date items
71 @item time of the day items
73 @item day of the week items
78 @noindent We describe each of these item types in turn, below.
80 @cindex numbers, written-out
81 @cindex ordinal numbers
82 @findex first @r{in date strings}
83 @findex next @r{in date strings}
84 @findex last @r{in date strings}
85 A few numbers may be written out in words in most contexts. This is
86 most useful for specifying day of the week items or relative items (see
87 below). Here is the list: @samp{first} for 1, @samp{next} for 2,
88 @samp{third} for 3, @samp{fourth} for 4, @samp{fifth} for 5,
89 @samp{sixth} for 6, @samp{seventh} for 7, @samp{eighth} for 8,
90 @samp{ninth} for 9, @samp{tenth} for 10, @samp{eleventh} for 11 and
91 @samp{twelfth} for 12. Also, @samp{last} means exactly @math{-1}.
93 @cindex months, written-out
94 When a month is written this way, it is still considered to be written
95 numerically, instead of being ``spelled in full''; this changes the
98 @cindex case, ignored in dates
99 @cindex comments, in dates
100 Alphabetic case is completely ignored in dates. Comments may be introduced
101 between round parentheses, as long as included parentheses are properly
102 nested. Hyphens not followed by a digit are currently ignored. Leading
103 zeros on numbers are ignored.
106 @node Calendar date item
107 @section Calendar date item
109 @cindex calendar date item
111 A @dfn{calendar date item} specifies a day of the year. It is
112 specified differently, depending on whether the month is specified
113 numerically or literally. All these strings specify the same calendar date:
116 1970-09-17 # ISO 8601.
117 70-9-17 # Assume 19xx for 69 through 99, 20xx for 00 through 68.
118 70-09-17 # Leading zeros are ignored.
119 9/17/72 # Common U.S. writing.
121 24 Sept 72 # September has a special abbreviation.
122 24 Sep 72 # Three-letter abbreviations always allowed.
128 The year can also be omitted. In this case, the last specified year is
129 used, or the current year if none. For example:
138 @cindex ISO 8601 date format
139 @cindex date format, ISO 8601
140 For numeric months, the ISO 8601 format
141 @samp{@var{year}-@var{month}-@var{day}} is allowed, where @var{year} is
142 any positive number, @var{month} is a number between 01 and 12, and
143 @var{day} is a number between 01 and 31. A leading zero must be present
144 if a number is less than ten. If @var{year} is 68 or smaller, then 2000
145 is added to it; otherwise, if @var{year} is less than 100,
146 then 1900 is added to it. The construct
147 @samp{@var{month}/@var{day}/@var{year}}, popular in the United States,
148 is accepted. Also @samp{@var{month}/@var{day}}, omitting the year.
150 @cindex month names in date strings
151 @cindex abbreviations for months
152 Literal months may be spelled out in full: @samp{January},
153 @samp{February}, @samp{March}, @samp{April}, @samp{May}, @samp{June},
154 @samp{July}, @samp{August}, @samp{September}, @samp{October},
155 @samp{November} or @samp{December}. Literal months may be abbreviated
156 to their first three letters, possibly followed by an abbreviating dot.
157 It is also permitted to write @samp{Sept} instead of @samp{September}.
159 When months are written literally, the calendar date may be given as any
163 @var{day} @var{month} @var{year}
164 @var{day} @var{month}
165 @var{month} @var{day} @var{year}
166 @var{day}-@var{month}-@var{year}
169 Or, omitting the year:
172 @var{month} @var{day}
176 @node Time of day item
177 @section Time of day item
179 @cindex time of day item
181 A @dfn{time of day item} in date strings specifies the time on a given
182 day. Here are some examples, all of which represent the same time:
188 20:02-0500 # In EST (Eastern U.S. Standard Time).
191 More generally, the time of the day may be given as
192 @samp{@var{hour}:@var{minute}:@var{second}}, where @var{hour} is
193 a number between 0 and 23, @var{minute} is a number between 0 and
194 59, and @var{second} is a number between 0 and 59. Alternatively,
195 @samp{:@var{second}} can be omitted, in which case it is taken to
198 @findex am @r{in date strings}
199 @findex pm @r{in date strings}
200 @findex midnight @r{in date strings}
201 @findex noon @r{in date strings}
202 If the time is followed by @samp{am} or @samp{pm} (or @samp{a.m.}
203 or @samp{p.m.}), @var{hour} is restricted to run from 1 to 12, and
204 @samp{:@var{minute}} may be omitted (taken to be zero). @samp{am}
205 indicates the first half of the day, @samp{pm} indicates the second
206 half of the day. In this notation, 12 is the predecessor of 1:
207 midnight is @samp{12am} while noon is @samp{12pm}.
209 @cindex time zone correction
210 @cindex minutes, time zone correction by
211 The time may alternatively be followed by a time zone correction,
212 expressed as @samp{@var{s}@var{hh}@var{mm}}, where @var{s} is @samp{+}
213 or @samp{-}, @var{hh} is a number of zone hours and @var{mm} is a number
214 of zone minutes. When a time zone correction is given this way, it
215 forces interpretation of the time relative to
216 Coordinated Universal Time (UTC), overriding any previous
217 specification for the time zone or the local time zone. The @var{minute}
218 part of the time of the day may not be elided when a time zone correction
219 is used. This is the only way to specify a time zone correction by
220 fractional parts of an hour.
222 Either @samp{am}/@samp{pm} or a time zone correction may be specified,
227 @section Time zone item
229 @cindex time zone item
231 A @dfn{time zone item} specifies an international time zone, indicated by
232 a small set of letters. They are supported for backward compatibility reasons,
233 but they are not recommended because they are ambiguous in practice:
234 for example, the abbreviation @samp{EST} has different meanings in
235 Australia and the United States. Any included period is ignored. Military
236 time zone designations use a single letter. Currently, only integral
237 zone hours may be represented in a time zone item. See the previous
238 section for a finer control over the time zone correction.
240 Here are many non-daylight-saving-time time zones, indexed by the zone
245 @samp{Y} for militaries.
247 @samp{X} for militaries.
249 @samp{W} for militaries.
251 @samp{V} for militaries.
253 @samp{PST} for Pacific Standard, and
254 @samp{U} for militaries.
256 @samp{MST} for Mountain Standard, and
257 @samp{T} for militaries.
259 @samp{CST} for Central Standard, and
260 @samp{S} for militaries.
262 @samp{EST} for Eastern Standard, and
263 @samp{R} for militaries.
265 @samp{AST} for Atlantic Standard, and
266 @samp{Q} for militaries.
268 @samp{P} for militaries.
270 @samp{O} for militaries.
272 @samp{N} for militaries.
274 @cindex Greenwich Mean Time
275 @cindex Coordinated Universal Time
276 @cindex Universal Coordinated Time
277 @cindex Universal Time (Coordinated)
278 @samp{GMT} for Greenwich Mean,
279 @samp{UT} for Universal,
280 @samp{UTC} for Coordinated Universal,
281 @samp{WET} for Western European, and
282 @samp{Z} for ISO 8601 and militaries.
284 @samp{A} for militaries,
285 @samp{CET} for Central European,
286 @samp{MET} for Midden Europesche Tijd (Dutch), and
287 @samp{MEZ} for Mittel-Europ@"aische Zeit (German).
289 @samp{B} for militaries, and
290 @samp{EET} for Eastern European.
292 @samp{C} for militaries.
294 @samp{D} for militaries.
296 @samp{E} for militaries.
298 @samp{F} for militaries.
300 @samp{G} for militaries.
302 @samp{H} for militaries.
304 @samp{I} for militaries, and
305 @samp{JST} for Japan Standard.
307 @samp{GST} for Guam Standard, and
308 @samp{K} for militaries.
310 @samp{L} for militaries.
312 @samp{M} for militaries, and
313 @samp{NZST} for New Zealand Standard.
316 @cindex daylight-saving time
317 Here are many daylight-saving time (DST) time zones,
318 indexed by the zone hour value. Also, by
319 following a non-DST time zone by the string @samp{DST} in a separate word
320 (that is, separated by some whitespace), the corresponding DST time zone
325 @samp{PDT} for Pacific Daylight.
327 @samp{MDT} for Mountain Daylight.
329 @samp{CDT} for Central Daylight.
331 @samp{EDT} for Eastern Daylight.
333 @samp{ADT} for Atlantic Daylight.
335 @samp{BST} for British Summer, and
336 @samp{WEST} for Western European Summer.
338 @samp{CEST} for Central European Summer,
339 @samp{MEST} for Midden Europesche S. Tijd (Dutch), and
340 @samp{MESZ} for Mittel-Europ@"aische Sommerzeit (German).
342 @samp{NZDT} for New Zealand Daylight.
346 @node Day of week item
347 @section Day of week item
349 @cindex day of week item
351 The explicit mention of a day of the week will forward the date
352 (only if necessary) to reach that day of the week in the future.
354 Days of the week may be spelled out in full: @samp{Sunday},
355 @samp{Monday}, @samp{Tuesday}, @samp{Wednesday}, @samp{Thursday},
356 @samp{Friday} or @samp{Saturday}. Days may be abbreviated to their
357 first three letters, optionally followed by a period. The special
358 abbreviations @samp{Tues} for @samp{Tuesday}, @samp{Wednes} for
359 @samp{Wednesday} and @samp{Thur} or @samp{Thurs} for @samp{Thursday} are
362 @findex next @var{day}
363 @findex last @var{day}
364 A number may precede a day of the week item to move forward
365 supplementary weeks. It is best used in expression like @samp{third
366 monday}. In this context, @samp{last @var{day}} or @samp{next
367 @var{day}} is also acceptable; they move one week before or after
368 the day that @var{day} by itself would represent.
370 A comma following a day of the week item is ignored.
373 @node Relative item in date strings
374 @section Relative item in date strings
376 @cindex relative items in date strings
377 @cindex displacement of dates
379 @dfn{Relative items} adjust a date (or the current date if none) forward
380 or backward. The effects of relative items accumulate. Here are some
390 @findex year @r{in date strings}
391 @findex month @r{in date strings}
392 @findex fortnight @r{in date strings}
393 @findex week @r{in date strings}
394 @findex day @r{in date strings}
395 @findex hour @r{in date strings}
396 @findex minute @r{in date strings}
397 The unit of time displacement may be selected by the string @samp{year}
398 or @samp{month} for moving by whole years or months. These are fuzzy
399 units, as years and months are not all of equal duration. More precise
400 units are @samp{fortnight} which is worth 14 days, @samp{week} worth 7
401 days, @samp{day} worth 24 hours, @samp{hour} worth 60 minutes,
402 @samp{minute} or @samp{min} worth 60 seconds, and @samp{second} or
403 @samp{sec} worth one second. An @samp{s} suffix on these units is
404 accepted and ignored.
406 @findex ago @r{in date strings}
407 The unit of time may be preceded by a multiplier, given as an optionally
408 signed number. Unsigned numbers are taken as positively signed. No
409 number at all implies 1 for a multiplier. Following a relative item by
410 the string @samp{ago} is equivalent to preceding the unit by a
411 multiplicator with value @math{-1}.
413 @findex day @r{in date strings}
414 @findex tomorrow @r{in date strings}
415 @findex yesterday @r{in date strings}
416 The string @samp{tomorrow} is worth one day in the future (equivalent
417 to @samp{day}), the string @samp{yesterday} is worth
418 one day in the past (equivalent to @samp{day ago}).
420 @findex now @r{in date strings}
421 @findex today @r{in date strings}
422 @findex this @r{in date strings}
423 The strings @samp{now} or @samp{today} are relative items corresponding
424 to zero-valued time displacement, these strings come from the fact
425 a zero-valued time displacement represents the current time when not
426 otherwise change by previous items. They may be used to stress other
427 items, like in @samp{12:00 today}. The string @samp{this} also has
428 the meaning of a zero-valued time displacement, but is preferred in
429 date strings like @samp{this thursday}.
431 When a relative item makes the resulting date to cross the boundary
432 between DST and non-DST (or vice-versa), the hour is adjusted according
436 @node Pure numbers in date strings
437 @section Pure numbers in date strings
439 @cindex pure numbers in date strings
441 The precise intepretation of a pure decimal number is dependent of
442 the context in the date string.
444 If the decimal number is of the form @var{yyyy}@var{mm}@var{dd} and no
445 other calendar date item (@pxref{Calendar date item}) appears before it
446 in the date string, then @var{yyyy} is read as the year, @var{mm} as the
447 month number and @var{dd} as the day of the month, for the specified
450 If the decimal number is of the form @var{hh}@var{mm} and no other time
451 of day item appears before it in the date string, then @var{hh} is read
452 as the hour of the day and @var{mm} as the minute of the hour, for the
453 specified time of the day. @var{mm} can also be omitted.
455 If both a calendar date and a time of day appear to the left of a number
456 in the date string, but no relative item, then the number overrides the
460 @node Authors of getdate
461 @section Authors of @code{getdate}
463 @cindex authors of @code{getdate}
465 @cindex Bellovin, Steven M.
468 @cindex MacKenzie, David
469 @cindex Meyering, Jim
470 @code{getdate} was originally implemented by Steven M. Bellovin
471 (@email{smb@@research.att.com}) while at the University of North Carolina
472 at Chapel Hill. The code was later tweaked by a couple of people on
473 Usenet, then completely overhauled by Rich $alz (@email{rsalz@@bbn.com})
474 and Jim Berets (@email{jberets@@bbn.com}) in August, 1990. Various
475 revisions for the GNU system were made by David MacKenzie, Jim Meyering,
480 This chapter was originally produced by Fran@,{c}ois Pinard
481 (@email{pinard@@iro.umontreal.ca}) from the @file{getdate.y} source code,
482 and then edited by K.@: Berry (@email{kb@@cs.umb.edu}).