mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Feb 2003
Posts: 3,432
S
sparta Offline OP
Hoopy frood
OP Offline
Hoopy frood
S
Joined: Feb 2003
Posts: 3,432
What would be the best way to calc time? If the clock was 12:33 and i want to grab how long tme it was if the clock are 14:56 .

I using the format: $time(hh:nn)


if ($me != tired) { return } | else { echo -a Get a pot of coffee now $+($me,.) }
Joined: Oct 2012
Posts: 164
D
Vogon poet
Offline
Vogon poet
D
Joined: Oct 2012
Posts: 164
//echo -ag $duration($calc($duration(14:56) - $duration(12:33)),3)

Joined: Sep 2005
Posts: 2,881
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Sep 2005
Posts: 2,881
And from the current time to 16:30:

Code:
//echo -a $duration($calc($ctime($date 16:30) - $ctime),2)

Joined: Feb 2003
Posts: 3,432
S
sparta Offline OP
Hoopy frood
OP Offline
Hoopy frood
S
Joined: Feb 2003
Posts: 3,432
Tested both ways, no go.
Code:
//set %clock 09:02

alias test {
  return $duration($calc($ctime($date %clock) - $ctime),2) 
}

Curent time: 10:08

And what i get in return is:
-4014secs

The other code does the same thing.

;-- Edit
Now i got the code given by Deega to return a value without the - sign, but it return 2 minutes instead of 2 houers.

And now i testing the user of $ctime instead.

//set %clock $ctime
//echo -a $duration($calc($ctime - %clock))

Last edited by sparta; 04/03/13 09:28 AM.

if ($me != tired) { return } | else { echo -a Get a pot of coffee now $+($me,.) }
Joined: Oct 2012
Posts: 164
D
Vogon poet
Offline
Vogon poet
D
Joined: Oct 2012
Posts: 164
You have to work out which time is the greater, if you subtract $ctime($date 10:08) from $ctime($date 09:02) you will have a negative number, as $duration() correctly returned.

hh:nn is not good for this, 09:02 (am) looks identical to 09:02 (pm) yet they are 43200 seconds apart. Better to use HH:nn, but by far the best is to set %clock to $ctime.

Joined: Sep 2005
Posts: 2,881
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Sep 2005
Posts: 2,881
Try this:

Code:
alias timeuntil {
  var %date = $iif($ctime($date $1) > $ctime,$date,$date($calc($ctime + 86400)))
  return $duration($calc($ctime(%date $1) - $ctime),2) 
}

alias test { echo -a $timeuntil($1) }


/test 18:00


Link Copied to Clipboard