From owner-freebsd-questions Sat Jan 22 8:54:21 2000 Delivered-To: freebsd-questions@freebsd.org Received: from cc942873-a.ewndsr1.nj.home.com (cc942873-a.ewndsr1.nj.home.com [24.2.89.207]) by hub.freebsd.org (Postfix) with ESMTP id 5953214E65 for ; Sat, 22 Jan 2000 08:54:18 -0800 (PST) (envelope-from cjc@cc942873-a.ewndsr1.nj.home.com) Received: (from cjc@localhost) by cc942873-a.ewndsr1.nj.home.com (8.9.3/8.9.3) id LAA04043; Sat, 22 Jan 2000 11:59:00 -0500 (EST) (envelope-from cjc) Date: Sat, 22 Jan 2000 11:58:54 -0500 From: "Crist J. Clark" 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> Reply-To: cjclark@home.com References: <868r13$2gq9$1@atlantis.rz.tu-clausthal.de> <200001221506.QAA14283@dorifer.heim3.tu-clausthal.de> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Mailer: Mutt 1.0i 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 +0100 Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG On Sat, Jan 22, 2000 at 04:06:03PM +0100, Oliver Fromme wrote: > Crist J. Clark 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