RESULTS: Anyone got a date math routine?

Jay R. Ashworth jra at baylink.com
Wed Dec 5 18:23:39 PST 2007


On Wed, Dec 05, 2007 at 03:51:32PM -0500, Kenneth Brody wrote:
> Okay, I'll put the clue-by-4 away.  :-)

Here's what the clue-by-four produced:

Given a date, and an optional time, calcage will tell you how long ago
that was, in the sort of fuzzy numbers immortalized by kclock.  I've
illustrated it with a call; it all sits in my automatic table, to show
me ticket status ages.

============8<================================8<=============================
doages:::
::' figure the ages of ticket timestamps:
::':
::zd=12; zt=13; gosub calcage; as=zx:
::zd=4 ; zt=""; gosub calcage; ao=zx:
::zd=6 ; zt=""; gosub calcage; af=zx:
::zd=8 ; zt=""; gosub calcage; ac=zx:
::return:
::':
calcage:::
::' calculate the age of a ticket:
::' thanks to Ken Brody for the hint:
::':
::' usage - zx=calcage(zd,zt), er, um, nevermind...:
::':
::zd(10,mdyy/)                    ' date to age:
::zt(8,hms)                       ' time to age:
::zz(5,.0)="0"                    ' days since then:
::zy(15,f)="0"                    ' seconds since then:
::zw(9,.0)="0"                    ' floating quotient:
::zx(3,*)=""                      ' return value:
::':
:zd eq "":return                  ' must have a date:
::zz=@td-zd                       ' first, get days:
:zt ne "":zy=@tm-zt; zy=zy*"3600" ' then, seconds in the loose day, if any:
::zy=zy+(zz*"86400")              ' fold the days into the seconds:
::':
::' we now have zy seconds between the ticket time and today:
::' now we have to back that out to the largest unit where the quotient is:
::' greater than one, and round, then tag on the unit marker:
::' this should be a loop, but without a for statement, I'm too lazy:
::' don't forget, leading spaces are *significant*, even in numeric fields...:
::':
::zw=zy/"51557600"                 ' seconds/yr:
:zw ge "1":zx=""{zw{"Y"; return    ' years:
::'           ^^^  see?:
::zw=zy/"2629800"                  ' seconds/mo:
:zw ge "1":zx=""{zw{"M"; return    ' months:
::':
::zw=zy/"604800"                   ' seconds/wk:
:zw ge "1":zx=""{zw{"W"; return    ' weeks:
::':
::zw=zy/"86400"                    ' seconds/day:
:zw ge "1":zx=""{zw{"D"; return    ' days:
::':
::zw=zy/"3600"                     ' seconds/hr:
:zw ge "1":zx=""{zw{"h"; return    ' hours:
::':
::zw=zy/"60"                       ' seconds/min:
:zw ge "1":zx=""{zw{"m"; return    ' minutes:
::':
::zx=zw{"s"; return                ' seconds
============8<================================8<=============================

Cheers,
-- jra
-- 
Jay R. Ashworth                   Baylink                      jra at baylink.com
Designer                     The Things I Think                       RFC 2100
Ashworth & Associates     http://baylink.pitas.com                     '87 e24
St Petersburg FL USA      http://photo.imageinc.us             +1 727 647 1274

	     Witty slogan redacted until AMPTP stop screwing WGA


More information about the Filepro-list mailing list