Subject: Re: date feature request
To: None <>
From: John Darrow <>
List: netbsd-users
Date: 11/14/2006 00:12:23
On 13 Nov 2006 22:40:18 -0600, George Georgalis <> wrote:
>would the invocation 
>date -R [[[[[cc]yy]mm]dd]hh]mm[.ss] [+format]
>be a reasonable feature request to date(1)? is there
>another way to get date [+format] from an arbitrary
>canonical time?

On unix systems, the "canonical" time format (time_t) is actually
seconds from the epoch.  The input format shown above is just provided
by date(1) to make it easier for those silly people who actually want
to manually fiddle with their clocks.  ;-)

Converting a time_t to an arbitrary string (like the above) is easy;
just call strftime with the right format, which is exactly what date
does internally.  But going the other way is non-trivial, due to
having to know when leap years, leap seconds, etc. occurred, which is
why the system provides a mktime() call which will take a struct tm *
and convert it into a time_t.  You then just need a parsing routine to
break your string into a struct tm (substituting current values for
fields you didn't provide), as done in date.c::setthetime().

It would be trivial (<10 lines) to add a flag to date(1) telling it
to not set the time, but just parse the string and then print
according to the format.

The main question is what option letter to use?  -R (like suggested
above)?  -N (a common "don't actually do it, just show me what would
happen" option letter)?  Something else?  Is there any prior art for
this?  Does POSIX or anything else have anything to say?  What color
should we paint the bike shed? ;-)