X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=doc%2Fgetdate.texi;h=1d312a68959e0079b197add55376e6fc117fddd7;hb=21002fe811420acc5ff49cba391e43be48f13047;hp=6c3acd143e87abfa91397cd35b8fd29782681888;hpb=f566b8f147fc72c596471e1dde6e91b6d4e94d9b;p=chaz%2Ftar diff --git a/doc/getdate.texi b/doc/getdate.texi index 6c3acd1..1d312a6 100644 --- a/doc/getdate.texi +++ b/doc/getdate.texi @@ -1,8 +1,20 @@ +@c GNU date syntax documentation + +@c Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, +@c 2003, 2004 Free Software Foundation, Inc. + +@c Permission is granted to copy, distribute and/or modify this document +@c under the terms of the GNU Free Documentation License, Version 1.1 or +@c any later version published by the Free Software Foundation; with no +@c Invariant Sections, with no Front-Cover Texts, and with no Back-Cover +@c Texts. A copy of the license is included in the ``GNU Free +@c Documentation License'' file as part of this distribution. + @node Date input formats @chapter Date input formats @cindex date input formats -@findex getdate +@findex get_date First, a quote: @@ -33,19 +45,7 @@ or a week from Sunday, with feelings of helpless confusion. @dots{} This section describes the textual date representations that @sc{gnu} programs accept. These are the strings you, as a user, can supply as arguments to the various programs. The C interface (via the -@code{getdate} function) is not described here. - -@cindex beginning of time, for @sc{posix} -@cindex epoch, for @sc{posix} -Although the date syntax here can represent any possible time since the -year zero, computer integers often cannot represent such a wide range of -time. On @sc{posix} systems, the clock starts at 1970-01-01 00:00:00 -@sc{utc}: @sc{posix} does not require support for times before the -@sc{posix} Epoch and times far in the future. Traditional Unix systems -have 32-bit signed @code{time_t} and can represent times from 1901-12-13 -20:45:52 through 2038-01-19 03:14:07 @sc{utc}. Systems with 64-bit -signed @code{time_t} can represent all the times in the expected -lifetime of the universe. +@code{get_date} function) is not described here. @menu * General date syntax:: Common rules. @@ -55,7 +55,8 @@ lifetime of the universe. * Day of week items:: Monday and others. * Relative items in date strings:: next tuesday, 2 years ago. * Pure numbers in date strings:: 19931219, 1440. -* Authors of getdate:: Bellovin, Eggert, Berets, Salz, et al. +* Seconds since the Epoch:: @@1078100502. +* Authors of get_date:: Bellovin, Eggert, Salz, Berets, et al. @end menu @@ -100,6 +101,36 @@ When a month is written this way, it is still considered to be written numerically, instead of being ``spelled in full''; this changes the allowed strings. +@cindex language, in dates +In the current implementation, only English is supported for words and +abbreviations like @samp{AM}, @samp{DST}, @samp{EST}, @samp{first}, +@samp{January}, @samp{Sunday}, @samp{tomorrow}, and @samp{year}. + +@cindex language, in dates +@cindex time zone item +The output of @command{date} is not always acceptable as a date string, +not only because of the language problem, but also because there is no +standard meaning for time zone items like @samp{IST}. When using +@command{date} to generate a date string intended to be parsed later, +specify a date format that is independent of language and that does not +use time zone items other than @samp{UTC} and @samp{Z}. Here are some +ways to do this: + +@example +$ LC_ALL=C TZ=UTC0 date +Mon Mar 1 00:21:42 UTC 2004 +$ TZ=UTC0 date +'%Y-%m-%d %H:%M:%SZ' +2004-03-01 00:21:42Z +$ date --iso-8601=ns # a GNU extension +2004-02-29T16:21:42,692722128-0800 +$ date --rfc-2822 # a GNU extension +Sun, 29 Feb 2004 16:21:42 -0800 +$ date +'%Y-%m-%d %H:%M:%S %z' # %z is a GNU extension. +2004-02-29 16:21:42 -0800 +$ date +'@@%s.%N' # %s and %N are GNU extensions. +@@1078100502.692722128 +@end example + @cindex case, ignored in dates @cindex comments, in dates Alphabetic case is completely ignored in dates. Comments may be introduced @@ -188,7 +219,7 @@ A @dfn{time of day item} in date strings specifies the time on a given day. Here are some examples, all of which represent the same time: @example -20:02:0 +20:02:00.000000 20:02 8:02pm 20:02-0500 # In @sc{est} (U.S. Eastern Standard Time). @@ -197,7 +228,9 @@ day. Here are some examples, all of which represent the same time: More generally, the time of the day may be given as @samp{@var{hour}:@var{minute}:@var{second}}, where @var{hour} is a number between 0 and 23, @var{minute} is a number between 0 and -59, and @var{second} is a number between 0 and 59. Alternatively, +59, and @var{second} is a number between 0 and 59 possibly followed by +@samp{.} or @samp{,} and a fraction containing one or more digits. +Alternatively, @samp{:@var{second}} can be omitted, in which case it is taken to be zero. @@ -238,13 +271,15 @@ but not both. @cindex time zone item A @dfn{time zone item} specifies an international time zone, indicated -by a small set of letters, e.g., @samp{UTC} for Coordinated Universal +by a small set of letters, e.g., @samp{UTC} or @samp{Z} +for Coordinated Universal Time. Any included periods are ignored. By following a non-daylight-saving time zone by the string @samp{DST} in a separate word (that is, separated by some white space), the corresponding daylight saving time zone may be specified. -Time zone items are obsolescent and are not recommended, because they +Time zone items other than @samp{UTC} and @samp{Z} +are obsolescent and are not recommended, because they are ambiguous; for example, @samp{EST} has a different meaning in Australia than in the United States. Instead, it's better to use unambiguous numeric time zone corrections like @samp{-0500}, as @@ -340,6 +375,26 @@ When a relative item causes the resulting date to cross a boundary where the clocks were adjusted, typically for daylight-saving time, the resulting date and time are adjusted accordingly. +The fuzz in units can cause problems with relative items. For +example, @samp{2003-07-31 -1 month} might evaluate to 2003-07-01, +because 2003-06-31 is an invalid date. To determine the previous +month more reliably, you can ask for the month before the 15th of the +current month. For example: + +@example +$ date -R +Thu, 31 Jul 2003 13:02:39 -0700 +$ date --date='-1 month' +'Last month was %B?' +Last month was July? +$ date --date="$(date +%Y-%m-15) -1 month" +'Last month was %B!' +Last month was June! +@end example + +Also, take care when manipulating dates around clock changes such as +daylight saving leaps. In a few cases these have added or subtracted +as much as 24 hours from the clock, so it is often wise to adopt +universal time by setting the @env{TZ} environment variable to +@samp{UTC0} before embarking on calendrical calculations. @node Pure numbers in date strings @section Pure numbers in date strings @@ -347,7 +402,7 @@ the resulting date and time are adjusted accordingly. @cindex pure numbers in date strings The precise interpretation of a pure decimal number depends -the context in the date string. +on the context in the date string. If the decimal number is of the form @var{yyyy}@var{mm}@var{dd} and no other calendar date item (@pxref{Calendar date items}) appears before it @@ -365,25 +420,56 @@ in the date string, but no relative item, then the number overrides the year. -@node Authors of getdate -@section Authors of @code{getdate} +@node Seconds since the Epoch +@section Seconds since the Epoch + +If you precede a number with @samp{@@}, it represents an internal time +stamp as a count of seconds. The number can contain an internal +decimal point (either @samp{.} or @samp{,}); any excess precision not +supported by the internal representation is truncated toward minus +infinity. + +@cindex beginning of time, for @acronym{POSIX} +@cindex epoch, for @acronym{POSIX} +Internally, computer times are represented as a count of seconds since +an epoch---a well-defined point of time. On @acronym{GNU} and +@acronym{POSIX} systems, the epoch is 1970-01-01 00:00:00 @sc{utc}, so +@samp{@@0} represents this time, @samp{@@1} represents 1970-01-01 +00:00:01 @sc{utc}, and so forth. @acronym{GNU} and most other +@acronym{POSIX}-compliant systems support such times as an extension +to @acronym{POSIX}, using negative counts, so that @samp{@@-1} +represents 1969-12-31 23:59:59 @sc{utc}. + +Traditional Unix systems count seconds with 32-bit two's-complement +integers and can represent times from 1901-12-13 20:45:52 through +2038-01-19 03:14:07 @sc{utc}. More modern systems use 64-bit counts +of seconds with nanosecond subcounts, and can represent all the times +in the known lifetime of the universe to a resolution of 1 nanosecond. + +On most systems, these counts ignore the presence of leap seconds. +For example, on most systems @samp{@@915148799} represents 1998-12-31 +23:59:59 @sc{utc}, @samp{@@915148800} represents 1999-01-01 00:00:00 +@sc{utc}, and there is no way to represent the intervening leap second +1998-12-31 23:59:60 @sc{utc}. -@cindex authors of @code{getdate} +@node Authors of get_date +@section Authors of @code{get_date} + +@cindex authors of @code{get_date} @cindex Bellovin, Steven M. +@cindex Salz, Rich @cindex Berets, Jim -@cindex Eggert, Paul @cindex MacKenzie, David @cindex Meyering, Jim -@cindex Salz, Rich -@code{getdate} was originally implemented by Steven M. Bellovin +@cindex Eggert, Paul +@code{get_date} was originally implemented by Steven M. Bellovin (@email{smb@@research.att.com}) while at the University of North Carolina at Chapel Hill. The code was later tweaked by a couple of people on Usenet, then completely overhauled by Rich $alz (@email{rsalz@@bbn.com}) and Jim Berets (@email{jberets@@bbn.com}) in August, 1990. Various revisions for the @sc{gnu} system were made by David MacKenzie, Jim Meyering, -and others. The code was rewritten again in 1999 by Paul Eggert, -to improve its support for daylight saving time. +Paul Eggert and others. @cindex Pinard, F. @cindex Berry, K.