Subject: | |
From: | |
Reply To: | |
Date: | Mon, 20 Mar 2006 14:48:07 -0800 |
Content-Type: | text/plain |
Parts/Attachments: |
|
|
sometime ago, eben asked about calculating the number of days between
two dates. i offered a script called 'doy' that had been part of tim
erickson's collection (but which is now on invent3k).
a kind soul privately mentioned to me some of the short-comings in the
script. here's an improved version. the date handling is still not
rigorous (you can still hand it a logically invalid date and it will
blissfully answer) but for a script it's pretty good (imo). (watch for
line wrapping!) - d
parm p1="!hpmonth" p2="!hpdate" p3="!hpyear"
if not (numeric('!p1') and numeric('!p2') and numeric('!p3'))
echo
echo DOY [month],[day],[year]
echo req req req
echo
echo This command calculates the number of days in a year for
echo the inputted date since January of the given year. The
echo default date is today's date. DOY also sets a ci variable
echo 'doy_days' that contains the number of days displayed at
echo the end of this script. DOY does take leap year into
echo consideration.
echo
return
endif
if bound(doy_days)
deletevar doy_days
endif
setvar _doy_month !p1
setvar _doy_day !p2
# primative checking....things could still go wrong
if _doy_month > 12 or _doy_day > 31
echo ERROR: Invalid month/day given
return
endif
setvar _doy_year !p3
if bound(hpyyyy) and hpyyyy > 2049 and _doy_year < 100
echo ERROR: This script will no longer work as expected
return
endif
if _doy_year < hpsplityear
setvar _doy_year 2000 + _doy_year
elseif _doy_year < 100
setvar _doy_year 1900 + _doy_year
endif
setvar _doy_days ((_doy_month-1)*304/10)+((_doy_month+2)/10)
setvar _doy_days _doy_days+(((12-_doy_month)/10)*_doy_month)
setvar _doy_ly (1/(1+(_doy_year MOD 4)))-(1/(1+(_doy_year MOD 100)))
setvar _doy_ly (_doy_ly+(1/(1+(_doy_year MOD
400))))*((7+_doy_month)/10)
setvar _doy_days _doy_days+_doy_ly+(_doy_day-1)
setvar doy_days _doy_days
echo Day of year for !_doy_month/!_doy_day/!_doy_year is !_doy_days
if bound(traceon)
showvar _doy_@
endif
deletevar _doy_@
Donna Garverick, HP-CSA Sr. System Programmer
dgarverick -at- longs -dot- com
925-210-6631 Longs Drug Stores
Come, my friends, 'Tis not too late to seek a newer world.
Tho' much is taken, much abides; and tho'
We are not now that strength which in old days
Moved earth and heaven, that which we are, we are.
"Ulysses", A. Tennyson
>>>MY opinions, not Longs Drug Stores'<<<
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
* To join/leave the list, search archives, change list settings, *
* etc., please visit http://raven.utc.edu/archives/hp3000-l.html *
|
|
|