code:
BREAK ON? "Hit [Enter] for start time snapshot" ?
Get $
$Start = @Time
? "$$Start = " + $Start
? "Hit [Enter] for end time snapshot" $
Get $
$End = @Time
? "$$End = " + $End
; convert times to seconds.
$startsecs=val(substr($start, 1, 2))*3600 + val(substr($start, 4, 2))*60 + val(substr($start, 7, 2))
? "$$Startsecs = " + $Startsecs + " seconds from midnight" ?
$endsecs=val(substr($end, 1, 2))*3600 + val(substr($end, 4, 2))*60 + val(substr($end, 7, 2))
? "$$Endsecs = " + $Endsecs + " seconds from midnight" ?
; subtract start from end
$diffsecs=$endsecs-$startsecs
? "$$Diffsecs = " + $Diffsecs + " seconds"
; convert difference to HH:MM:SS
$hours=$diffsecs/3600
$minutes=($diffsecs-($hours*3600))/60
$seconds=($diffsecs-($hours*3600)-($minutes*60))
; convert the numbers to strings and add leading zeros if required
if $hours<10 $hours="0$hours" else $hours="$hours" endif
if $minutes<10 $minutes="0$minutes" else $minutes="$minutes" endif
if $seconds<10 $seconds="0$seconds" else $seconds="$seconds" endif
; create string
$diff=$hours+":"+$minutes+":"+$seconds
? "$$Diff = " + $Diff + " in HH:MM:SS" ?
Get $
get $
code:
Break Onfunction abs($Expr)
;returns the absolute value of a number
$Expr=0+$Expr
if $Expr<0
$Expr=-1*$Expr
endif
$abs=$Expr
endfunction
function Mod($dividend, $divisor)
;Modulus Function
$dividend=0+$dividend
$divisor=0+$divisor
$mod=$dividend-(($dividend/$divisor)*$divisor)
endfunction
function SerialTime($TorS)
; Syntax: SerialTime(Time | Serial)
; Where Time is a time string in HH:MM[:SS] format or
; Serial is a time serial number (seconds since midnight) 1 - 86399
; If Time is supplied, SerialTime will return the seconds since midnight.
; If seconds since midnight is supplied, SerialTime will return a time.
; DEPENDENCIES: word(), abs(), mod()
dim $Hours, $Minutes, $Seconds, $Serial, $Error
$Error = 0
if instr($TorS,":") ; Time supplied
$TorS = "" + $TorS ; Cast to string
if len($TorS) > 4 and len($TorS) < 9
$Hours = 0 + word($TorS,1,":") ; Hours as integer for calculation
if $Hours > 23 $Error = 1 endif
$Minutes = 0 + word($TorS,2,":") ; Minutes as integer for calculation
if $Minutes > 59 $Error = 1 endif
$Seconds = 0 + word($TorS,3,":") ; Seconds as integer for calculation
if $Seconds > 59 $Error = 1 endif
$Serial = ($Hours * 3600) + ($Minutes * 60) + $Seconds
if $SerialTime > 86399 $Error = 1 endif
if $Error
$SerialTime = "-1" ; Error
else
$SerialTime = "" + $Serial ; Return as string
endif
else
$SerialTime = "-1" ; Error
endif
else ; Seconds supplied
$TorS = 0 + $TorS ; Cast to integer for calculation
if $TorS <= 86399 and $TorS >= 0
$Hours = $TorS / 3600
$TorS = $TorS - ($Hours * 3600)
$Hours = "" + $Hours
$Hours = substr("00",1,2 - len($Hours)) + $Hours
$Minutes = $TorS / 60
$TorS = $TorS - ($Minutes * 60)
$Minutes = "" + $Minutes
$Minutes = substr("00",1,2 - len($Minutes)) + $Minutes
$Seconds = "" + $TorS
$Seconds = substr("00",1,2 - len($Seconds)) + $Seconds
$SerialTime = $Hours + ":" + $Minutes + ":" + $Seconds ; Return as string
else
$SerialTime = "-1" ; Error
endif
endif
endfunction
function Word($strStr, $intWrdNum, optional $strWS)
; Syntax: Word("string",number, ["white space characters"])
; Word number may be negative, in which case, words will be counted
; from the right of the string. I.e. -1 will return the last word in the string.
dim $intWrdCtr, $intLen, $intStart, $intFinish, $intStep
dim $strWord
$strStr = "" + $strStr
$intWrdNum = 0 + $intWrdNum
$strWS = "" + $strWS
$intLen = len($strStr)
$intWrdCtr = 0
if $strWS = "" ; $strWS is a string containing "white space" chars
$strWS = " ," ; Contains tab, space, comma
endif
if $intWrdNum > 0 ; Setup to parse string forward
$intStart = 1
$intFinish = $intLen
$intStep = 1
else ; Setup to parse string backward
$intStart = $intLen
$intFinish = 1
$intStep = -1
endif
if $strStr = "" or $intWrdNum = 0
$strWord = ""
else
for $intCtr = $intStart to $intFinish step $intStep
if instr($strWS,substr($strStr,$intCtr,1)) ; if whitespace
while instr($strWS,substr($strStr,$intCtr,1)) and ($intCtr <= $intLen) ; skip it
$intCtr = $intCtr + $intStep
loop
else ; if non-whitespace
$intWrdCtr = $intWrdCtr + 1 ; increment word counter
if $intWrdCtr = abs($intWrdNum) ; requires "ABS()" UDF
; If this is the correct word number, extract it to $strWrd
while not instr($strWS,substr($strStr,$intCtr,1)) and ($intCtr <= $intLen)
; Extract it in the right order!
if $intStep = 1
$strWord = $strWord + substr($strStr,$intCtr,1)
else
$strWord = substr($strStr,$intCtr,1) + $strWord
endif
$intCtr = $intCtr + $intStep
loop
else
; otherwise, skip the word
while not instr($strWS,substr($strStr,$intCtr,1)) and ($intCtr <= $intLen)
$intCtr = $intCtr + $intStep
loop
endif
endif
; "Undo" last manual increment/decrement
$intCtr = $intCtr - $intStep
next
endif
$Word = $strWord ; Return the word, if found
endfunction
? "Hit [Enter] for start time snapshot" ?
Get $
? "@@Time = " + @TIME
$Start = SerialTime(@Time)
? "$$Start = " + $Start + " seconds from midnight" ?
? "Hit [Enter] for end time snapshot" $
Get $
$End = SerialTime(@Time)
? "$$End = " + $End + " seconds from midnight" ?
? "Hit [Enter] for difference from Start to End" $
Get $
$Diff = SerialTime(Val($End) - Val($Start))
? "$$Diff = " + $Diff + " seconds"
Get $
So, with a time snapshot at the start and another one at the end, the difference can be calculated and displayed.
I guess if greater precision is needed, then @TICKS could be incorporated as well.