mIRC Home    About    Download    Register    News    Help

Print Thread
O
Onions
Onions
O
Code:
//var %a = $calc($ctime + ($calc(3600 - ($ctime % 3600) + 900 - 3600))) | echo -a $asctime($iif(%a < $ctime,$calc(%a + 3600),%a),hh:nn)

Is there an easier way to do this? It's purpose is to get the nearest 15 minutes past the hour, but not behind the current time.


Joined: Aug 2004
Posts: 7,168
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,168
Code:
//echo -a $+($asctime(HH),:,$iif($asctime(mm) < 15,15,$iif($v1 < 30,30,$iif($v1 < 45,45,00))))


O
Onions
Onions
O
I don't believe you got quite the gist of the script's intention. I'm not sure what that does.
however;
That went back in time, it's 18:35 and it was returning 18:15 - it was supposed to return the next xx:15

Joined: Oct 2004
Posts: 8,061
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Oct 2004
Posts: 8,061
Code:
alias timenext15 {
  var %time = $calc($ctime + 900), %hour = $asctime(%time,HH), %min = $asctime(%time,n)
  var %min = $iif(%min > 45,45,$iif(%min > 30,30,$iif(%min > 15,15,00)))
  return %hour $+ : $+ %min
}


//echo -a $timenext15

Normally, I'd just use some if/elseif/else here, but since you're using $iif, I did too.

Joined: Nov 2006
Posts: 1,552
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Nov 2006
Posts: 1,552
My two cents:
Code:
$time($calc($ctime($date $time(HH:00)) + ($time(nn) +15 - $time(nn) % 15) *60),HH:nn)


Edit: Just like Riamus2 I understood it that you want all the ":15" ":30" ":45" and ":00".
However, to have the result of your original code, you can reduce the above calculation to:
Code:
$time($calc($ctime($date $time(hh:00)) + $iif($time(nn) < 15,900,4500)),hh:nn)
or, sufficiently:
Code:
$time($calc($ctime + $iif($time(nn) > 14,3600)),hh:15)


Joined: Oct 2004
Posts: 8,061
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Oct 2004
Posts: 8,061
I like your use of the % operator. Much easier. I didn't think to use that. smile

I did think the request was for the next 15 min mark (considering the title is xx:45). Meaning :00, :15, :30, :45. But, if it's just the next xx:15 mark, then it's much easier as you've shown.

EDIT: Just a thought... rather than adding an hour and using $iif(), you can just add 45min and then display hh:15. If it's xx:14 or less, then the hour won't change, and if it's xx:15 or more, it will.

Code:
$time($calc($ctime + 2700)),hh:15)


The only question I'd have either way... should xx:15 show the current hour or the next hour? "Next" xx:15 doesn't necessarily mean not to use the current time if it's xx:15 already. It would depend on the needs of the script. For example, maybe this is to display the next time something happens that happens each hour, so it's happening "now" if you're on xx:15 or it's done and won't happen until the next xx:15. It's easy enough to change yours or mine if it shouldn't increment if you're on xx:15 already. 44min on mine or >15 on yours.

Last edited by Riamus2; 26/04/11 12:27 PM.
Joined: Aug 2004
Posts: 7,168
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,168
OK, a slight misunderstanding on my part, as well as a typo.
The misunderstanding will take a bit longer for me to work out, though I do note that two other helpers have given their suggestions.
The typo, however, is a simple change of mm to nn in my script.

Joined: Nov 2006
Posts: 1,552
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Nov 2006
Posts: 1,552
Hah, to just add 45mins didn't occur to me laugh


Link Copied to Clipboard