mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Dec 2004
Posts: 14
D
dJabba Offline OP
Pikka bird
OP Offline
Pikka bird
D
Joined: Dec 2004
Posts: 14
Hey

im redoing my TeeTimer addon atm, and want to build in the function to activate at a specific clock aswell. Now for that i need a function to calculate how many seconds there are until that specific clock, until now i came up with this one and it works as supposed to, but is there maybe a simpler way?
im sure there is ... i have always been bad to the things that include $ctime and $asctime etc...

Code:
;Usage: //echo -a $teetimerV2.timeuntil(13:00)
;Would calculate the amount of seconds until its 13 o'clock next time.

ALIAS teetimerV2.timeuntil {
  var %then = $1
  var %fixmins = $iif($gettok(%then,2,58) == 00,60,$v1)
  var %fixhour = $iif($gettok(%then,1,58) == 00,24,$v1)
  tokenize 32 $asctime(HH nn ss)
  var %secs = $calc(60 - $3)
  var %mins = $calc(%fixmins - ($2 +1))
  var %hour = $calc(%fixhour - ($1 +1))
  if (- isin %hour) set %hour $calc(24 %hour)
  ;echo -s Then: %then FixMins: %fixmins FixHour: %fixhour
  var %minssecs = $calc(%mins *60)
  var %hoursecs = $calc(%hour *3600)
  var %totalsecs = $calc(%hoursecs + %minssecs + %secs)
  return %totalsecs
  ;echo -s Hour: %hour -- Mins: %mins -- Secs: %secs ----- Total secs: %totalsecs
}


- dJabba
Joined: Dec 2004
Posts: 14
D
dJabba Offline OP
Pikka bird
OP Offline
Pikka bird
D
Joined: Dec 2004
Posts: 14
solved it, KathY on mirc.net helped me out with a much simpler version, thanks anyway for your interest. (btw, there is an error in the above code, just noticed - so i dont recon you use it smile)


- dJabba
Joined: Oct 2005
Posts: 1,741
G
Hoopy frood
Offline
Hoopy frood
G
Joined: Oct 2005
Posts: 1,741
I started working on this, but I don't have time to finish it. You might have some use for the code I have made so far. It allows the target time to be in 12- or 24-hour format. The %t.hour and %t.min variables carry the target time in 24-hour format at the end of the alias.

Code:
alias TeeTimer {
  ; $1 = target time (eg 13:00 or 1:00p or 1:00pm)
  if (!$regex(TT,$1,/^(?:(1?\d|2[0-3]):([0-5]\d)|([1-9]|1[0-2]):([0-5]\d)([ap])m?)$/iS)) return Invalid parameter: $1
  var %t.hour = $regml(TT,1), %t.min = $regml(TT,2)
  if ((p isin $regml(TT,3)) && (%t.hour isnum 1-11)) inc %t.hour 12
  elseif ((a isin $regml(TT,3)) && (%t.hour == 12)) inc %t.hour 12
  %t.hour = $calc(%t.hour % 24)

  echo -a Target Time: %t.hour H, %t.min M, 00 S
;*** Continue code here ***
}


-genius_at_work

Last edited by genius_at_work; 11/06/06 05:47 PM.
Joined: Sep 2003
Posts: 4,230
D
Hoopy frood
Offline
Hoopy frood
D
Joined: Sep 2003
Posts: 4,230
Assuming you have already validated $1 to being the time in HH:nn or HH:nn:ss correctly you could just use
$calc((($ctime($date $1) - $ctime) + 86400) % 86400)


Link Copied to Clipboard