bug-sh-utils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: GNU date = BSD date ?!


From: Bob Proulx
Subject: Re: GNU date = BSD date ?!
Date: Tue, 20 Nov 2001 00:56:17 -0700

> Another buglet.  With GNU date from sh-utils this time.

Thanks for the report.  But there is no bug there.  You are using date
incorrectly.

>        date [OPTION]... [+FORMAT]
>        date [OPTION] [MMDDhhmm[[CC]YY][.ss]]

The traditional way to use date.  Except that the yy is sometimes in
the front and sometimes in the back.

> with a --set option for time setting:
> 
>        -s, --set=STRING
>               set time described by STRING

The --set option is a gnu extension to use extended date formats.
Check out the online info documentation "Date input formats" for
details.  What it will parse is quite rich.

> Lets try 20th November at midday:
> 
> address@hidden ntp-4.1.71]# date --set=11201200
> date: invalid date `11201200'

The --set=STRING will parse a number of date formats but 11201200 does
not match any of them.  It is expecting 'Tue Nov 20 00:27:44 MST 2001'
type of date strings.  The original style of packed decimal format is
already supported by date with no option and is therefore not needed
in the --set=STRING option.

Using the traditional style:

  date 11201200

Using the GNU style:

  date --set='November 20 12:00'

> Just for reference, here's the relevent bit of the BSD manual page for the
> date command:

> SYNOPSIS
>      date [-d dst] [-r seconds] [-t minutes_west] [-nu] [+format]
>           [[[[[[cc]yy]mm]dd]HH]MM[.SS]]

Note the yy at the front here.

Here is what the Version 6 and Version 7 manuals say:

        date [ yymmddhhmm [ .ss ] ]

Interesting that the BSD 4.3 manual also lists yy at the front and has
an example in it:

                date 8506131627

        sets the date to June 13 1985, 4:27 PM.  The year, month and
        day may be omitted; the default values will be the current
        ones.  ..."

Somewhere along the way the yy moved to the back of the packed decimal
format string and that is now the standard.  One of those little
oddities that keeps unix interesting.

Summary:  If you are using packed decimal then just give it to date
straight.  'date 11201242'  If you want a human-like string then use
--set=STRING to parse it.  'date --set="November 20 12:42"'  If you
want to increment or decrement the clock by a small amount then use
then use the parser again like this, date --set="+2 seconds", but
really NTP is highly recommended as the prefered method of keeping the
clock set.  http://www.eecis.udel.edu/~ntp/

Bob



reply via email to

[Prev in Thread] Current Thread [Next in Thread]