View unanswered posts | View active topics It is currently Thu Mar 28, 2024 3:12 am



Reply to topic  [ 1 post ] 
 Time lapse subroutine for seconds past or formatted duration 
Author Message
Chief Warrant Officer
User avatar

Joined: Sat Feb 27, 2016 1:01 am
Posts: 193
Location: Molon Labe
Unread post Time lapse subroutine for seconds past or formatted duration
Here is a handy subroutine to either get the seconds past or to print out a readable period of time (this includes additional code for testing purposes):

Sample output:

Code:
Unformatted seconds passed: 216094

Formatted  time passed: 2 Days, 12 Hrs, 1 Min, 34 Secs



Code:
#  Return total seconds by default using Boolean value.  0 for seconds or 1 for readable duration:
setVar $_MARKTIME_FORMAT 0

#  ...

goSub :TIMESTAMP
setVar $start_time $_TIMESTAMP


#  e.g., test time lapse...  (Note TWX appears to internally round  the value up to the nearest full second.)
setDelayTrigger 1 :TEST_DURATION 8500
pause


:TEST_DURATION
killTrigger 1
goSub :TIMESTAMP
setVar $end_time $_TIMESTAMP
goSub :MARKTIME


echo "** Unformatted seconds passed: " $_MARKTIME "**"

setVar $_MARKTIME_FORMAT 1
goSub :MARKTIME

echo "** Formatted  time passed: " $_MARKTIME "**"

halt


:TIMESTAMP
#  Returns a timestamp decimal value.
getTime $_DATE mm:dd:yyyy
getTime $_TIME hh:nn:ss
replaceText $_DATE ":" "/"

setVar $date_time $_DATE & " " & $_TIME
format $date_time $_TIMESTAMP STRTODATETIME

return

:MARKTIME
#  Returns a readable format based upon the seconds lapsed.  This function is accurate only to the hole second.
setVar $_MARKTIME ""
setVar $days 0
setVar $hrs 0
setVar $mins 0

setPrecision 20
setVar $secs (($end_time-$start_time)*86400)
setPrecision 0
round $secs 0

if ($_MARKTIME_FORMAT = 1)
if ($secs > 59)
  setVar $mins ($secs/60)
  setVar $secs ($secs-(60*$mins))
end
if ($mins > 59)
  setVar $hrs ($mins/60)
  setVar $mins ($mins-(60*$hrs))
end
if ($hrs > 23)
  setVar $days ($hrs/24)
  setVar $hrs ($hrs-(24*$days))
end
if ($days > 0)
  format $days $format NUMBER
  stripText $format ".00"
  if ($days > 1)
   setVar $days $format & " Days"
  else
   setVar $days $format & " Day"
  end
  if ($hrs <> 0) OR ($mins <> 0) OR ($secs <> 0)
   setVar $days $days & ", "
  end
end
if ($hrs > 0)
  if ($hrs > 1)
   setVar $hrs $hrs & " Hrs"
  else
   setVar $hrs $hrs & " Hr"
  end
  if ($mins <> 0) OR ($secs <> 0)
   setVar $hrs $hrs & ", "
  end
end
if ($mins > 0)
  if ($mins > 1)
   setVar $mins $mins & " Mins"
  else
   setVar $mins $mins & " Min"
  end
  if ($secs <> 0)
   setVar $mins $mins & ", "
  end
end
if ($secs > 0)
  if ($secs > 1)
   setVar $secs $secs & " Secs"
  else
   setVar $secs $secs & " Sec"
  end
end
if ($days <> 0)
  setVar $_MARKTIME $days
end
if ($hrs <> 0)
  setVar $_MARKTIME $_MARKTIME & $hrs
end
if ($mins <> 0)
  setVar $_MARKTIME $_MARKTIME & $mins
end
if ($secs <> 0)
  setVar $_MARKTIME $_MARKTIME & $secs
end

else
setVar $_MARKTIME $secs
end

setVar $_MARKTIME_FORMAT 0

return


halt

_________________
The object of life is not to be on the side of the majority, but to escape finding one’s self in the ranks of the insane.” — Marcus Aurelius

TWX Proxy Reference Online


Thu May 05, 2016 11:53 am
Profile ICQ
Display posts from previous:  Sort by  
Reply to topic   [ 1 post ] 

Who is online

Users browsing this forum: No registered users and 19 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by STSoftware.