elapsedTime - handler for returning time strings
elapsedTime - handler for returning time strings
- Subject: elapsedTime - handler for returning time strings
- From: Richard Morton <email@hidden>
- Date: Mon, 7 Jan 2002 10:39:52 +1100
Greetings,
I recently needed something that would take a seconds value and return
the time in hours, minutes & seconds. I couldn't find anything that
suited, so...
As written it returns minutes & seconds if the time is under an hour,
includes hours if it's less than a day and includes days if necessary.
It can be easily adjusted to return the extra strings if required. It
will accept real numbers as long as they're whole (is there a specific
name for numbers like that?) and works for values from 0 up to one
second short of 100 days. I will admit that I have not personally
tested it for every number in that range.
It has two line breaks, marked [Option-L], some lines may also get hard
wrapped...
-- elapsedTime -- Richard Morton 2001-2002 --
-- pass a value in the range 0-8639999 or 0.0-8.639999E+6
-- and a separator character; returns string
on elapsedTime from secondTime against s
tell secondTime to ,
if it < 3600 then -- an hour
set iRes to "" -- to return empty hour string set to -> "00" & s
set mFac to it
else if it < 86400 then -- a day
set iRes to (text -2 thru -1 of ("0" & (it div 3600))) & s -- hours
set mFac to it mod 3600
else -- a long time
set iRes to (text -2 thru -1 of ("0" & (it div 86400))) &
s & [Option-L]
(text -2 thru -1 of ("0" & ((it mod 86400) div
3600))) & s -- days & hours
set mFac to (it mod 86400) mod 3600
end if
return iRes & (text -2 thru -1 of ("0" & (mFac div 60))) & s &
[Option-L]
(text -2 thru -1 of ("0" & ((mFac mod 60) as integer))) --
minutes & seconds
end elapsedTime
-- -- --
Hopefully Nigel will let us know if it's not fast enough...
Cheers,
Richard Morton