| www.ClassicTW.com https://mail.black-squirrel.com/ |
|
| Measuring Elapsed Time... https://mail.black-squirrel.com/viewtopic.php?f=15&t=21491 |
Page 1 of 1 |
| Author: | LoneStar [ Thu Jan 29, 2009 9:48 am ] |
| Post subject: | Measuring Elapsed Time... |
Try not to laff too hard at my attempt.. Tried to convert HH:MM into Minutes-Then and Minutes-Now, subtract the difference and convert back into HH:MM-Expired. Code: getTime $NOW_HRS "h" getTime $NOW_MIN "n" getTime $NOW_APM "a/p" Echo "**" & $NOW_HRS & ":" & $NOW_MIN & $NOW_APM if ($NOW_APM = "p") add $NOW_HRS 12 end setVar $NOW_MIN ($NOW_MIN + ($NOW_HRS * 60)) setDelayTrigger aan :qqq 60000 pause :qqq killalltriggers getTime $_HRS "h" getTime $_MIN "n" getTime $_APM "a/p" if ($_APM = "p") add $_HRS 12 end setVar $MINS ($_MIN + ($_HRS * 60)) setPrecision 0 setVar $NEW (($MINS - $NOW_MINS) / 60) setVar $NEQ (($MINS - $NOW_MINS) - $NEW) Echo "**Expired: " & $NEW & ":" & $NEQ & "**" Any ideas? |
|
| Author: | Promethius [ Thu Jan 29, 2009 1:01 pm ] |
| Post subject: | Re: Measuring Elapsed Time... |
Maybe something like the following would work, assuming a 24 hour clock time (military time): Code: # time expired # testData setVar $hourThen "12" setVar $minThen "20" getTime $hourNow "h" getTime $minNow "n" if ($minNow < $minThen) subTract $hourNow 1 add $minNow 60 end # 11 PM is 2300 military so a time of 0100 military for 1 AM would result 25 - 23 below if ($hourNow < $hourThen) add $hourNow 24 end setVar $elapsedHour ($hourNow - $hourThen) setVar $elapsedMin ($minNow - $minThen) echo ANSI_12 "*Elapsed Time " ANSI_10 $elapsedHour ANSI_12 " hour(s) " ANSI_10 $elapsedMin ANSI_12 " minute(s)**" After thinking about it for a bit, gettime returns "normal" time I believe. So the addition would be 12 instead of 24 whenever the $hourNow is less than $hourThen. |
|
| Author: | Singularity [ Thu Jan 29, 2009 1:50 pm ] |
| Post subject: | 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. |
|
| Author: | LoneStar [ Thu Jan 29, 2009 4:57 pm ] |
| Post subject: | Re: Measuring Elapsed Time... |
[quote="After thinking about it for a bit, gettime returns "normal" time I believe. So the addition would be 12 instead of 24 whenever the $hourNow is less than $hourThen.[/quote] Crazy. Tried your code (changed $hourThen to current hour: 4pm), and the line: getTime $hourNow "h" came back with a 24hour value (ie instead of '4' I got '16'). Sing... gonna have to study your solution when I get a bit more time.. looking it over, I never imagined this would be so complex. lol |
|
| Author: | Singularity [ Thu Jan 29, 2009 5:22 pm ] |
| Post subject: | Re: Measuring Elapsed Time... |
GetTime has a lot of different inputs... http://www.navhaz.com/files/script.html#CMD_26 Quote: Purpose: Retrieves the current system time, or a formatted value containing the time and/or date. Syntax: getTime var [{format}] var: A variable to hold the formatted time or date. [{format}]: The format in which to return the time/date. If this is not specified, the variable will be set to hold the current system time in its default format. Notes: This is an extemely powerful date/time formatting command. Some components of the 'format' command are: "d" : Displays the day of the month without a leading zero. "dd" : Displays the day of the month with a leading zero. "m": Displays the month without a leading zero. "mm": Displays the month with a leading zero. "yy": Displays a two digit year. "yyyy": Displays a four digit year. "h": Displays the hour without a leading zero. "hh": Displays the hour with a leading zero. "n": Displays the minute without a leading zero. "nn": Displays the minute with a leading zero. "s": Displays the second without a leading zero. "ss": Displays the second with a leading zero. "am/pm": Displays "am" or "pm" depending upon the time. "a/p": Displays "a" or "p" depending upon the time. "c": Displays the date in its system date format. "t": Displays the time in its system time format. Edit: Someone (think it was EP) told me it's a direct passthru for Delphi's DateTime command. If that's the case there are other inputs too: Links: http://www.geekzilla.co.uk/View00FF7904 ... 20581F.htm http://www.jstawski.com/archive/2008/05 ... tring.aspx Try those and see what works. |
|
| Page 1 of 1 | All times are UTC - 5 hours |
| Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group http://www.phpbb.com/ |
|