
Re: Measuring Elapsed Time...
You're talking about an absolute time function. To do that, at least when working w/ years, you need an Epoc. Here's a function I wrote a long time ago that does similar, you can probably convert it to your needs.
Code:
:convert_timestamp
# Converts this format:
# 9/13/2005 12:09:39 AM
setVar $timestamp_result 0
getWord $timestamp $date 1
getWord $timestamp $time 2
getWord $timestamp $ampm 3
replaceText $date "/" " "
replaceText $time ":" " "
getWord $date $date_month 1
getWord $date $date_day 2
getWord $date $date_year 3
getWord $time $time_hour 1
getWord $time $time_min 2
getWord $time $time_sec 3
# Compensate for midnight and noon
if ($time_hour = "12")
setVar $time_hour 0
end
# Add 12 for PM
if ($ampm = "PM")
add $time_hour 12
end
# Figure seconds in today.
setVar $these_seconds ($time_hour*3600) + ($time_min*60) + $time_sec
# Figure days from months...
if ($date_month = 1)
setVar $days_offset 0
elseif ($date_month = 2)
setVar $days_offset 31
elseif ($date_month = 3)
setVar $days_offset 59
elseif ($date_month = 4)
setVar $days_offset 90
elseif ($date_month = 5)
setVar $days_offset 120
elseif ($date_month = 6)
setVar $days_offset 151
elseif ($date_month = 7)
setVar $days_offset 181
elseif ($date_month = 8)
setVar $days_offset 212
elseif ($date_month = 9)
setVar $days_offset 243
elseif ($date_month = 10)
setVar $days_offset 273
elseif ($date_month = 11)
setVar $days_offset 304
elseif ($date_month = 12)
setVar $days_offset 334
end
setVar $days_offset (($days_offset+$date_day)-1)
setVar $leapyear_test ($date_year/4)
setVar $leapy ($leapyear_test*4)
if ($leapy = $date_year)
# It didn't round, is it a leap year?
setVar $leapyear_test ($date_year / 100)
setVar $leapy ($leapyear_test*100)
# Not an even century...
if ($leapy <> $date_year)
if ($date_month >= 3)
# March or later...
add $days_offset 1
end
end
end
# Hehe, Tradewars epoch?
subtract $date_year 2002
# Figure the number of days up to this year...
setVar $year_offset ($date_year-1)
setVar $year_offset ($year_offset*36500)
setVar $year_offset ($year_offset/100)
# Add up both this year and previous years...
setVar $total_days ($year_offset+$days_offset)
# 24 hours per day. 60 minutes per hour. 60 seconds per minute.
setVar $total_seconds (($total_days*86400)+$these_seconds)
# Handle negatives...
if ($total_seconds < 1)
setVar $total_seconds 0
end
# Output result
setVar $timestamp_result $total_seconds
return
Gives the number of seconds that has elapsed from the Epoc to the timestamp.
Edit: If you don't factor in the date then an HH:MM calculation will fail at midnight. So you pretty much have to do the entire thing in order to be accurate.