Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 22 Jan 2000 11:58:54 -0500
From:      "Crist J. Clark" <cjc@cc942873-a.ewndsr1.nj.home.com>
To:        freebsd-questions@FreeBSD.ORG
Cc:        cjclark@home.com
Subject:   Re: sh(1) Messing with My Mind
Message-ID:  <20000122115854.A3951@cc942873-a.ewndsr1.nj.home.com>
In-Reply-To: <200001221506.QAA14283@dorifer.heim3.tu-clausthal.de>; from olli@dorifer.heim3.tu-clausthal.de on Sat, Jan 22, 2000 at 04:06:03PM %2B0100
References:  <868r13$2gq9$1@atlantis.rz.tu-clausthal.de> <200001221506.QAA14283@dorifer.heim3.tu-clausthal.de>

next in thread | previous in thread | raw e-mail | index | archive | help
On Sat, Jan 22, 2000 at 04:06:03PM +0100, Oliver Fromme wrote:
> Crist J. Clark <cjc@cc942873-a.ewndsr1.nj.home.com> wrote in list.freebsd-questions:
>  > But since we're having so much fun with all of this, maybe I should
>  > try this one on all of you. Given Ben's code above, how would _you_
>  > determine how long ago $DATE was from the present time?
> 
> I'd first convert the date string to a time_t value.  The
> easiest way to accomplish that is probably to install GNU
> date:
> 
>    DATE="Fri 21 Jan 2000 00:15:59 GMT"
>    TIMET=`gdate -d "$DATE" +%s`
> 
> $TIMET will then contain the number 948413759.  You can get
> the current time (int time_t format) like this:
> 
>    NOW=`date +%s`
> 
> This works both with GNU date and BSD date (but BSD date
> doesn't support something like the -d option of GNU date
> above, AFAIK).

Yep, that was the catch. date(1) only converts a string to a time_t if
you are actually going to go and change the system
clock. Hmmm... Maybe a change-request PR on that one.

I had ended up writing a very small C helper program. Without all of
the error checks, this is all you need to do,

   strptime(argv[1],"%+",prevdump_tm);
   predump_t = mktime(prevdump_tm);
   return ( ( time(NULL) - predump_t ) > INTERVAL )

-- 
Crist J. Clark                           cjclark@home.com


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20000122115854.A3951>