need "yy-ddd-hh:mm:ss ==> (time_t) clock" converter

Guy Harris guy at auspex.auspex.com
Wed Jan 23 09:11:22 AEST 1991


>Question: how does getdate(SVR4) differ from Steve Bellovin's getdate()
>	  as found in the news packages ?  Is it similar or does it do
>	  something entirely different ?

Something fairly different.

Bellovin's uses YACC to parse a number of hard-coded formats.  It takes,
as its arguments, a pointer to the string to parse and an optional
pointer to a "struct timeb" holding the current time, the current offset
from GMT and "daylight savings time is honored" flag.  (If the pointer
is NULL, it will call "ftime()" to get that information itself.  Netnews
comes with an "ftime()" routine for systems with S3/S5-style timezone
handling.)

It returns a "time_t" representing the parsed time in seconds since the
Epoch.

S5R4's parses the date by trying a list of formats specified in the file
whose name appears in the environment variable DATEMSK.  It takes, as
its argument, a pointer to the string to parse.

(Unfortunately, according to the manual, it requires DATEMSK to be set,
and won't pick the file based on the setting of LANG or LC_TIME; the
strings it will accept for some things, such as "%A" or "%B" or "%b" or
"%c", will come from the locale, but there doesn't seem to be a way to
tell it to accept "%m/%d/%y" as one of the formats if LANG is set to an
appropriate value for the US, "%d/%m/%y" for locales that work that way,
"%d.%m.%y" for locales that work that way, etc. - it appears you'd have
to have different DATEMSK files for different locales, and set DATEMSK
as well as LANG.  Not fatal, but annoyingly inconvenient.

Yes, I know it has a "%c" that represents "the locale's appropriate date
and time representation", and "%X" that represents "the locale's
appropriate time representation", and "%x" that represents "the locale's
appropriate date representation"; unfortunately, I'm not sure there is
*one single* "appropriate" representation for a locale - is the
appropriate representation for the date in the US locale something that
handles "1/22/91", or something that handles "January 22, 1991", or...?)

It returns a pointer to a "struct tm" representing the parsed time in
broken-down *local* time format; if you want to make a "time_t" out of
it, you have to run the "struct tm" through "mktime()".



More information about the Comp.unix.programmer mailing list