From owner-freebsd-hackers Tue Jun 12 4: 1: 4 2001 Delivered-To: freebsd-hackers@freebsd.org Received: from mail.noos.fr (descartes.noos.net [212.198.2.74]) by hub.freebsd.org (Postfix) with ESMTP id 6485337B403 for ; Tue, 12 Jun 2001 04:01:00 -0700 (PDT) (envelope-from root@gits.dyndns.org) Received: (qmail 965234 invoked by uid 0); 12 Jun 2001 11:00:58 -0000 Received: from unknown (HELO gits.dyndns.org) ([212.198.228.81]) (envelope-sender ) by 212.198.2.74 (qmail-ldap-1.03) with SMTP for ; 12 Jun 2001 11:00:58 -0000 Received: (from root@localhost) by gits.dyndns.org (8.11.3/8.11.3) id f5CB0uo70876; Tue, 12 Jun 2001 13:00:56 +0200 (CEST) (envelope-from root) Message-Id: <200106121100.f5CB0uo70876@gits.dyndns.org> Subject: Re: Perl module for periodic scripts In-Reply-To: <3B25E519.ED3BE981@tornadogroup.com> To: Matthew Seaman Date: Tue, 12 Jun 2001 13:00:56 +0200 (CEST) Cc: Valentin Nechayev , Matthew Seaman , freebsd-hackers@FreeBSD.ORG Reply-To: clefevre@redirect.to From: Cyrille Lefevre Organization: ACME X-Face: V|+c;4!|B?E%BE^{E6);aI.[<97Zd*>^#%Y5Cxv;%Y[PT-LW3;A:fRrJ8+^k"e7@+30g0YD0*^^3jgyShN7o?a]C la*Zv'5NA,=963bM%J^o]C X-Mailer: ELM [version 2.4ME+ PL92 (25)] MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=US-ASCII Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG Matthew Seaman wrote: [snip] > > > see the following url on a portable (awk and ksh) replacement for > > > date -v-1d : > > > > Then the program will contain perl, ksh and awk code? There are too many > > languages used, aren't there? Also realize please that base system does not welcome in the portable unix shell programming world ;^) > > contain ksh. Monolithic perl code, without awk & ksh, will be better because > > perl is in base system already... not everybody known perl, while everybody known sh/sed/awk. > Quite so. The current admixture of sh and perl in 470.status-named seems > unaesthetic to me. I'll see if it's possible to rewrite this perl script. > On the other hand, FreeBSD /bin/sh is a lot more like Solaris /bin/ksh than it is like Solaris /bin/sh. Cyrille's ksh code should > port fairly readily to FreeBSD /bin/sh. first of all, it's not my code, but the code is free. here is an ash (POSIX?) port of date2julian and julian2date. please, left the (c)opytight where it is. thanks. # Date calculations using POSIX shell # Gregorian calendar only. # Tapani Tarvainen July 1998, May 2000 # This code is in the public domain. # Julian Day Number from calendar date date2julian () # day month year { local day month year tmpmonth tmpyear day=$1; month=$2; year=$3 tmpmonth=$(( (12 * $year) + $month - 3 )) tmpyear=$(( $tmpmonth / 12 )) echo $(( (((734 * $tmpmonth) + 15) / 24) - (2 * $tmpyear) + \ ($tmpyear / 4) - ($tmpyear / 100) + ($tmpyear / 400) + \ $day + 1721119 )) } # Calendar date from Julian Day Number julian2date () # julianday { local day month year tmpday centuries tmpday=$(( $1 - 1721119 )) centuries=$(( ((4 * $tmpday) - 1) / 146097 )) tmpday=$(( $tmpday + $centuries - ($centuries / 4) )) year=$(( ((4 * $tmpday) - 1) / 1461 )) tmpday=$(( $tmpday - ((1461 * $year) / 4) )) month=$(( ((10 * $tmpday) - 5) / 306 )) day=$(( $tmpday - (((306 * $month) + 5) / 10) )) month=$(( $month + 2 )) year=$(( $year + ($month / 12) )) month=$(( ($month % 12) + 1 )) echo $day $month $year } now=$(date "+%d %m %Y") julian=$(date2julian $now) julian=$(( $julian - 1 )) yesterday=$(julian2date $julian) echo $now : $yesterday Cyrille. -- home: mailto:clefevre@redirect.to UNIX is user-friendly; it's just particular work: mailto:Cyrille.Lefevre@edf.fr about who it chooses to be friends with. To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message