mIRC Home    About    Download    Register    News    Help

Print Thread
#38096 23/07/03 09:39 PM
Joined: Feb 2003
Posts: 13
C
Pikka bird
OP Offline
Pikka bird
C
Joined: Feb 2003
Posts: 13
If i got a variable called %startime which is set at 22:30:00 and one called %finishtime which is set at 22:31:05 how do i work out the difference between the two to show as Time: 1min 5secs

Joined: Dec 2002
Posts: 2,809
C
Hoopy frood
Offline
Hoopy frood
C
Joined: Dec 2002
Posts: 2,809
Well I can't think of an identifier that would do it for you, so basically, you have to do the math. This looks like it does the job:

alias difftime {
var %result = 0

if ($calc($gettok($2,1,58) - $gettok($1,1,58))) {
%result = $calc(%result + ($ifmatch * 3600))
}
if ($calc($gettok($2,2,58) - $gettok($1,2,58))) {
%result = $calc(%result + ($ifmatch * 60))
}
if ($calc($gettok($2,3,58) - $gettok($1,3,58))) {
%result = $calc(%result + $ifmatch)
}
return $duration($abs(%result))
}

//echo -a $difftime(22:30:00,22:31:05)
prints:
1min 5secs

Joined: Dec 2002
Posts: 1,321
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Dec 2002
Posts: 1,321
1. Easiest is to save the %starttime as the $ctime it was at the start and %finishtime at the finish. Then you can simply subtract %finishtime - %starttime, run that through $calc( ) and then get the $duration( ) of the final $calc result.
  • $duration($calc(%finishtime - %starttime))
2. Another strategy is to just use $date with the %starttime and $date with the %finishtime to run through $ctime to convert them both to ctimes, then follow the same steps as above.
  • $duration($calc($ctime($date %finishtime) - $ctime($date %starttime)))
The first way is far superior to the second for many reasons but requires a change in how the %starttime and %finishtime are stored initially. The main reason is that the $date may have changed from what it was at %starttime.


DALnet: #HelpDesk and #m[color:#FF0000]IR[color:#EEEE00]C
Joined: Jan 2003
Posts: 2,523
Q
Hoopy frood
Offline
Hoopy frood
Q
Joined: Jan 2003
Posts: 2,523
The main reason is that the $date may have changed from what it was at %starttime.

Assuming that the two $date's can only vary by one day (Commander currently stores only the hour:mins:secs, so this is a rather safe assumption):
$duration($calc(($ctime($date %finishtime) - $ctime($date %starttime) + 86400) % 86400))
would deal with the problem: if, for example, %starttime was 22:20:30 and %finishtime was 01:10:40 the script correctly outputs "2hrs 50mins 10secs".


/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com

Link Copied to Clipboard