mIRC Home    About    Download    Register    News    Help

Print Thread
#12404 22/02/03 12:59 PM
Joined: Feb 2003
Posts: 37
D
druiddk Offline OP
Ameglian cow
OP Offline
Ameglian cow
D
Joined: Feb 2003
Posts: 37
//echo -s Now: $date $asctime(HH:nn:ss) | echo -s Time since 22/02/2003 13:28:32: $duration($ctime(22/2/2003 13:28:32))

Gives me output:
Now: 22/02/2003 14:00:50
Time since 22/02/2003 13:28:32: 1729wks 2days 12hrs 28mins 32secs

What am I doing wrong here?

Joined: Dec 2002
Posts: 2,962
S
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 2,962
$duration($ctime(22/2/2003 13:28:32)) - is returning the time between the epoch (Jan 1, 1970) and that date given. You want $duration($calc($ctime - $ctime(22/2/2003 13:28:32))).


Spelling mistakes, grammatical errors, and stupid comments are intentional.
Joined: Dec 2002
Posts: 332
C
Fjord artisan
Offline
Fjord artisan
C
Joined: Dec 2002
Posts: 332
to get the current time you should use $time for instance like this

$time(mmm-dd-hh:nntt)

will return

Feb-22-07:06am

i dont exactly see what you are doing in the second half ? what do you want it to return ?

Joined: Feb 2003
Posts: 37
D
druiddk Offline OP
Ameglian cow
OP Offline
Ameglian cow
D
Joined: Feb 2003
Posts: 37
Cheech: Starbucks solved the problem :-)

I wanted it to tell me how long passed since the date + time entered in :P

Joined: Dec 2002
Posts: 1,321
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Dec 2002
Posts: 1,321
I wrote a script a while ago (which you can probably tell by reading the script and its scripting style - I'll just have to go back one of these days and clean it up some) that extends duration's output to Years Months Days Hours Minutes Seconds that can be found here. Feel free to shoot holes in it, as I never really tested it all that much, though I haven't noticed any problems with it yet.

$ymdhns(seconds[,N])
Returns the specified number of seconds in a yeah/month/day/hour/minute/second format.

The N parameter is optional. If N = 2, the result does not include the seconds value. If N = 3, the result is returned in a colon-tokenized value in the form yy:mm:dd:hh:nn:ss, with leading zero-values truncated. If N = 4, the leading zero-values are not truncated.
Code:

alias ymdhns {
 
  if ($int($1) > $ctime) {
    echo $color(ctcp) -ati2 * Duration out of range
    halt
  }
  var %:  = 00:00:00:00:00:00
  var %nt = $asctime($ctime,yyyy mm dd HH nn ss)
  var %st = $asctime($calc($ctime - $int($1)),yyyy mm dd HH nn ss)
 
  var %ns = $gettok(%nt,6,32), %ss = $gettok(%st,6,32)
  var %nn = $gettok(%nt,5,32), %sn = $gettok(%st,5,32)
  var %nh = $gettok(%nt,4,32), %sh = $gettok(%st,4,32)
  var %nd = $gettok(%nt,3,32), %sd = $gettok(%st,3,32)
  var %nm = $gettok(%nt,2,32), %sm = $gettok(%st,2,32)
  var %ny = $gettok(%nt,1,32), %sy = $gettok(%st,1,32)
  if (%ns < %ss) {
    dec %nn
    inc %ns 60
  }
  %: = $puttok(%:,$right($+(00,$calc(%ns - %ss)),2),6,58)
  if (%nn < %sn) {
    dec %nh
    inc %nn 60
  }
  %: = $puttok(%:,$right($+(00,$calc(%nn - %sn)),2),5,58)
  if (%nh < %sh) {
    dec %nd
    inc %nh 24
  }
  %: = $puttok(%:,$right($+(00,$calc(%nh - %sh)),2),4,58)
  if (%nd < %sd) {
    dec %nm
 
    ;  Work out how many days to "borrow"
    if ($istok(1:3:5:7:8:10:12,%sm,58)) inc %nd 31
    elseif ($istok(4:6:9:11,%sm,58)) inc %nd 30
    elseif (($calc(%sy % 400) == 0) || $&
      (($calc(%sy % 4) == 0) && ($calc(%sy % 100) != 0))) inc %nd 29
    else inc %nd 28
 
  }
  %: = $puttok(%:,$right($+(00,$calc(%nd - %sd)),2),3,58)
  if (%nm < %sm) {
    dec %ny
    inc %nm 12
  }
  %: = $puttok(%:,$right($+(00,$calc(%nm - %sm)),2),2,58)
  %: = $puttok(%:,$right($+(00,$calc(%ny - %sy)),2),1,58)
  if ($2 == 4) return %:
  if ($2 == 3) {
    ;  Trim off leading 00 tokens
    while ($gettok(%:,1,58) == 00) %: = $deltok(%:,1,58)
    ;  Trim off any remaining leading 0's
    if ($left(%:,1) == 0) return $right(%:,-1)
    return %:
  }
  var %s
  if (($gettok(%:,1,58)) && ($gettok(%:,1,58) > 0)) {
    %s = $calc($ifmatch + 0) $iif($ifmatch == 1,year,years)
  }
  if (($gettok(%:,2,58)) && ($gettok(%:,2,58) > 0)) {
    %s = %s $calc($ifmatch + 0) $iif($ifmatch == 1,month,months)
  }
  if (($gettok(%:,3,58)) && ($gettok(%:,3,58) > 0)) {
    %s = %s $calc($ifmatch + 0) $iif($ifmatch == 1,day,days)
  }
  if (($gettok(%:,4,58)) && ($gettok(%:,4,58) > 0)) {
    %s = %s $calc($ifmatch + 0) $iif($ifmatch == 1,hour,hours)
  }
  if (($gettok(%:,5,58)) && ($gettok(%:,5,58) > 0)) {
    %s = %s $calc($ifmatch + 0) $iif($ifmatch == 1,minute,minutes)
  }
  if ($2 == 2) return %s
  if (($gettok(%:,6,58)) && ($gettok(%:,6,58) > 0)) {
    %s = %s $ifmatch $iif($ifmatch == 1,second,seconds)
  }
  return %s
}

//echo -a * $ymdhns($calc($ctime(2003/12/25) - $ctime))
* 9 months 26 days 22 hours 19 minutes 38 seconds

//echo -a * $ymdhns($calc($ctime(2003/12/25) - $ctime), 1)
* 9 months 26 days 22 hours 19 minutes 28 seconds

//echo -a * $ymdhns($calc($ctime(2003/12/25) - $ctime), 2)
* 9 months 26 days 22 hours 19 minutes

//echo -a * $ymdhns($calc($ctime(2003/12/25) - $ctime), 3)
* 9:26:22:19:23


DALnet: #HelpDesk and #m[color:#FF0000]IR[color:#EEEE00]C

Link Copied to Clipboard