mIRC Home    About    Download    Register    News    Help

Print Thread
$calc() / $duration() question #240842 02/03/13 12:30 PM
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,.) }
Re: $calc() / $duration() question [Re: sparta] #240843 02/03/13 01:18 PM
Joined: Oct 2012
Posts: 164
D
Deega Offline
Vogon poet
Offline
Vogon poet
D
Joined: Oct 2012
Posts: 164
//echo -ag $duration($calc($duration(14:56) - $duration(12:33)),3)

Re: $calc() / $duration() question [Re: sparta] #240847 02/03/13 04:08 PM
Joined: Sep 2005
Posts: 2,881
H
hixxy Offline
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)

Re: $calc() / $duration() question [Re: hixxy] #240881 04/03/13 09:11 AM
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,.) }
Re: $calc() / $duration() question [Re: sparta] #240884 04/03/13 02:56 PM
Joined: Oct 2012
Posts: 164
D
Deega Offline
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.

Re: $calc() / $duration() question [Re: sparta] #240888 04/03/13 06:14 PM
Joined: Sep 2005
Posts: 2,881
H
hixxy Offline
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