Date: Tue, 12 Jun 2001 13:00:56 +0200 (CEST) From: Cyrille Lefevre <clefevre@redirect.to> To: Matthew Seaman <matthew.seaman@tornadogroup.com> Cc: Valentin Nechayev <netch@iv.nn.kiev.ua>, Matthew Seaman <m.seaman@plasm.demon.co.uk>, freebsd-hackers@FreeBSD.ORG Subject: Re: Perl module for periodic scripts Message-ID: <200106121100.f5CB0uo70876@gits.dyndns.org> In-Reply-To: <3B25E519.ED3BE981@tornadogroup.com>
next in thread | previous in thread | raw e-mail | index | archive | help
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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200106121100.f5CB0uo70876>