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

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

RE: DATE set broken


From: Barnes, Brian
Subject: RE: DATE set broken
Date: Thu, 7 Nov 2002 11:48:37 -0600

Bob,

I just used the MAN page and found it most confusing. I had to go to
deja.com and look for problems others have had to find an example of an
acceptable format. Here is a tiny Perl script I once wrote to allow
spreadsheet users to take advantage of integer times:

address@hidden:~> time2bin.pl june 1 2:00 PM 2002
1022958000
address@hidden:~> time2bin.pl 1022958000         
06-01-2002 02:00:00 PM

address@hidden:~> time2bin.pl 2000 june 1 2:00 PM     
959886000
address@hidden:~> time2bin.pl  959886000          
06-01-2000 02:00:00 PM

It will accept just about any "reasonable" time/date format and spit out the
ctime for it. 

Following is 100% of the documentation for setting a date:
 -s, --set=STRING    set time described by STRING

Since this usage (date [-u|--utc|--universal] [MMDDhhmm[[CC]YY][.ss]]) does
not contain the -s(ET), it must be this one, "date [OPTION]... [+FORMAT]".
So, we have a +FORMAT and a STRING as clues to the usage. But, "FORMAT
controls the output" so that won't work. All we have to work with is STRING.
I tried a bunch which it didn't like. 

>This is from the info page.
>     date [OPTION]... [+FORMAT]
>     date [-u|--utc|--universal] [ MMDDhhmm[[CC]YY][.ss] ]
>What is misleading about either of those?

FORMAT applies only to showing the time. There is zero information about
setting it except that it is a string. Not much to go on. And, your process
is not reversible. Any fully specified format you can print should be
acceptable as input.

The info page, which some systems do not have, does have much more to go on.

        Brian


-----Original Message-----
From: address@hidden [mailto:address@hidden
Sent: Wednesday, November 06, 2002 8:24 PM
To: Barnes, Brian
Cc: 'address@hidden'
Subject: Re: DATE set broken


> Your date set feature is horribly broken and/or misleadingly documented. 

It could certainly be improved.  Please make suggestions for
improvements!  But I don't think it is really that bad.  Let's take a
look at it.

Here is from the man page.

      date [-u]
      date [-u] +format
      date [-u] [mmddhhmm[[cc]yy]]
      date [-a [-]sss[.fff]]

This is from the info page.

     date [OPTION]... [+FORMAT]
     date [-u|--utc|--universal] [ MMDDhhmm[[CC]YY][.ss] ]

What is misleading about either of those?

> Per your documentation, these should work (date [-u|--utc|--universal]
> [MMDDhhmm[[CC]YY][.ss]])
>       date -s 11061137 <enter>
>       date -s 110611372002 <enter>

No.  Where did it ever say that?  Try this instead.

        date 110611372002 <enter>

Which matches the line here in the documentation.

      date [-u] [mmddhhmm[[cc]yy]]

Month, day, hour, minute, year.  But the info page also shows the
optional seconds tacked onto the end too.  Hmm...

> What is your format???? 
>        date [OPTION]... [+FORMAT]
>        -s, --set=STRING
>               set time described by STRING
> The + sign causes an error. 

Yes.  The -s option takes a STRING.  It is a GNU extension which has
been added to the code to add more functionality.  Try this syntax.
The -s is needed to let the program know you are not using the classic
syntax but using the extended syntax.

        date -s "Wed Nov 6 11:37 2002" <enter>

But the +FORMATs are for printing dates.  Which means you are not
setting the clock when you are printing but rather displaying a time.
Normally you would not use any option other than the plus.

  date +%a

But if you want to display the date at a particular time you can do
that.  But you need the -d DATESTR option.  Again from the info page.

  `-d DATESTR'
  `--date=DATESTR'
       Display the time and date specified in DATESTR instead of the
       current time and date.  DATESTR can be in almost any common
       format.  It can contain month names, time zones, `am' and `pm',
       `yesterday', `ago', `next', etc.  *Note Date input formats::.

  date -d '1 week ago' +%B
  October

> None of the % FORMAT options work

The +FORMAT options are for printing.  Back to the info page.

  Invoking `date' with no FORMAT argument is equivalent to invoking
  `date '+%a %b %e %H:%M:%S %Z %Y''.

Give this a try.

  date '+%a %b %e %H:%M:%S %Z %Y'
  Wed Nov  6 19:11:26 MST 2002

> Give an example. You appear to accept one format for reading, but not for
> setting. The 2 operations should be 100% reversible. Bad design and/or
> implementation. 

Please bring up the info page for date.  Then look in the section
marked "Examples of date".  There you will find many examples.
Perhaps you had not read the documentation?  Although only one example
of setting the system clock.  That is not something that very many
users ever need to do.  But there are lots of examples for printing
the date and time in various formats.

If you have a network connection I recommend setting the data using
ntpdate from a NTP server.  Then using ntpd to keep the clock up to
date all of the time.  It is a very lightweight protocol and works
much better than trying to set the date manually.  However, if you are
offline then manual setting is about the best you can do.

If you have improvements to the documentation they would be much
appreciated.  What would you say in the info documentation to improve
the understanding?

Bob




reply via email to

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