mIRC Homepage
How do i change this so instead of it saying this

It is now: 22wks 3days 9hrs 19mins 50secs until Christmas Day!!

to make it say this

It is now: 22 weeks, 3 days, 9 hours, 19 minutes and 50 seconds until Christmas Day!!

menu channel,query {
Countdown
.Birthday
..Say
...To $active:{ //say 0,2*4,2§§0*13~0*6§§0*0 It's now: $duration($calc($ctime(february 20 2006 12:00) - $ctime)) until my birthday!! 0,2*4,2§§0*13~0*6§§0* }
...To Self:{ //echo 0,2*4,2§§0*13~0*6§§0*0 It's now: $duration($calc($ctime(february 20 2006 12:00) - $ctime)) until my birthday!! 0,2*4,2§§0*13~0*6§§0* }
.Christmas Day
..Say
...To $active:{ //say 0,4 *** 0,10 It is now: $duration($calc($ctime(december 25 2005 00:00) - $ctime)) until Christmas Day!! 0,4 ***  }
...To Self:{ //echo 0,2*4,2§§0*13~0*6§§0*0 It's now: $duration($calc($ctime(december 25 2005 00:00) - $ctime)) until Christmas Day!! 0,2*4,2§§0*13~0*6§§0* }
.New Year's Day
..Say
...To $active:{ //say 0,2*4,2§§0*13~0*6§§0*0 It's now: $duration($calc($ctime(january 1 2006 00:00) - $ctime)) until year 2006!! 0,2*4,2§§0*13~0*6§§0* }
...To Self:{ //echo 0,2*4,2§§0*13~0*6§§0*0 It's now: $duration($calc($ctime(january 1 2006 00:00) - $ctime)) until year 2006!! 0,2*4,2§§0*13~0*6§§0* }
}
Might be an easier way, but you can use $replace...
Code:
$replace($duration(_____),wks,$chr(32) $+ weeks $+ $chr(44),days,$chr(32) $+ days $+ $chr(44),hrs,$chr(32) $+ hours $+ $chr(44),mins,$chr(32) $+ minutes and,secs,$chr(32) $+ seconds)


Just stick your $duration information into there.
Cool thanks works great, i bet the only way around the whole script on the year part is manually editing things to next year and so on?
Noticed a problem, if there is only 1 hour left it won't show as in hour, but hr, how do i change that, plus not sure if minute is ok yet
Ok, I didn't think about that 1's. Here you go.

Code:
$replacex($duration(_____),wks,$chr(32) $+ weeks $+ $chr(44),days,$chr(32) $+ days $+ $chr(44),hrs,$chr(32) $+ hours $+ $chr(44),mins,$chr(32) $+ minutes and,secs,$chr(32) $+ seconds,wk,$chr(32) $+ weeks $+ $chr(44),hr,$chr(32) $+ hour $+ $chr(44),min,$chr(32) $+ minute and,sec,$chr(32) $+ second)


Just as a note... this isn't perfect. If you have 0 seconds, then you're left with something like:

4 hours, 5 minutes and

I'm not quite sure how to easily make the "and" either be there or not depending on if there are any seconds. Also, note that if all you have are weeks or hours (only one item), you'll end in a comma like this:

1 week,

This is the same issue as with the "and".

Granted, these aren't going to be seen too often, but they are there.

Now that I think of it, you might try this:

Code:
    var %duration $duration(___)
    var %weeks $iif($gettok($gettok(%duration,1,119),-1,32) isnum,$gettok($gettok(%duration,1,119),-1,32),$null)
    var %days $iif($gettok($gettok(%duration,1,100),-1,32) isnum,$gettok($gettok(%duration,1,100),-1,32),$null)
    var %hours $iif($gettok($gettok(%duration,1,104),-1,32) isnum,$gettok($gettok(%duration,1,104),-1,32),$null)
    var %minutes $iif($gettok($gettok(%duration,1,109),-1,32) isnum,$gettok($gettok(%duration,1,109),-1,32),$null)
    var %seconds $iif($gettok($mid($gettok(%duration,1,101),-3,2),-1,32) isnum,$gettok($mid($gettok(%duration,1,101),-3,2),-1,32),$null)

    if (%weeks) {
      if (%weeks > 1) {
        set %time %weeks weeks
      }
      else { set %time %weeks week }
      if ((%days && %hours) || (%days && %minutes) || (%days && %seconds) || (%hours && %minutes) || (%hours && %seconds) || (%minutes && %seconds)) {
        set %time %time $+ $chr(44)
      }
      elseif (%days || %hours || %minutes || %seconds) {
        set %time %time and
      }
    }

    if (%days) {
      if (%days > 1) {
        set %time %time %days days
      }
      else { echo -a Test2 | set %time %time %days day }
      if ((%hours && %minutes) || (%hours && %seconds) || (%minutes && %seconds)) {
        set %time %time $+ $chr(44)
      }
      elseif (%hours || %minutes || %seconds) {
        set %time %time and
      }
    }

    if (%hours) {
      if (%hours > 1) {
        set %time %time %hours hours
      }
      else { set %time %time %hours hour }
      if (%minutes && %seconds) {
        set %time %time $+ $chr(44)
      }
      elseif (%minutes || %seconds) {
        set %time %time and
      }
    }

    if (%minutes) {
      if (%minutes > 1) {
        set %time %time %minutes minutes
      }
      else { set %time %time %minutes minute }
      if (%seconds) {
        set %time %time and
      }
    }

    if (%seconds) {
      if (%seconds > 1) {
        set %time %time %seconds seconds
      }
      else { set %time %time %seconds second }
    }

    echo -a %time
    unset %time


This large code should do everything correctly no matter what amount of time there is. Stick it into whatever event you need it in, or as an alias.

Just replace the echo line with whatever kind of output you want instead of echo.

If you have problems, let me know.
could you add that long code you made into the script for me please im confused on the best place for it sorry
Code:
;usage $duration2(x) same as $duration(x) but worded out as speced.
alias duration2 {
  var %duration = $replace($duration($1),$+(s,$chr(32)),$+(s,$chr(44),$chr(32)),sec,$+($chr(32),second),min,$+($chr(32),minute),hr,$+($chr(32),hour),day,$+($chr(32),day),wk,$+($chr(32),week))
  if ($numtok(%duration,32) > 2) { var %duration = $deltok(%duration,-3-,32) $gettok($gettok(%duration,-3,32),1,44) and $gettok(%duration,-2-,32) }
  return %duration
}


I compacted it a little smile

changes "s " to "s, " (last word wont get changed as no space)
changes "sec" to " second" same for "min" "hr" "day" "wk"
checks if i need the " and " and removes the , and adds the " and "

* I must admit i didnt check it against a large number of values, but it seemed to work ok.
So instead of putting in $duration($calc($ctime(february 20 2006 12:00) - $ctime)) i just put in /alias duration2?
no

$duration2($calc($ctime(february 20 2006 12:00) - $ctime))
seems to be a double comma , between days and hours
Interesting. I hadn't considered it that way. smile

Now I feel stupid. It was so easy. Heh.
<Did you know?> It is 30 weeks, 3 days,, 9 hours, 46 minutes and 13 seconds until my next birthday!! <20th February>

see a double comma ,
//echo -a $duration($calc($ctime(february 20 2006 12:00) - $ctime(22/07/2005 2:13:47)))  $duration2($calc($ctime(february 20 2006 12:00) - $ctime(22/07/2005 2:13:47))) 
30wks 3days 9hrs 46mins 13secs 30 weeks, 3 days, 9 hours, 46 minutes and 13 seconds

I have to assume you have altetred something. I cant reproduce at all what you say you got.

You need to supply the code you are using to get this result, and the time/date stamp of the moment its run.
.Birthday:{ //say 0,4 <Did you know?> 0,2 It is $replace($duration2($calc($ctime(february 20 2006 12:00) - $ctime)),wks,$chr(32) $+ weeks $+ $chr(44),days,$chr(32) $+ days $+ $chr(44),hrs,$chr(32) $+ hours $+ $chr(44),mins,$chr(32) $+ minutes and,secs,$chr(32) $+ seconds) until my next birthday!! 0,3 <20th February>  }


haven't touched a anything except the $duration2
omg, dump all that replace stuff, the $duration2 works just like $duration, BUT it outputs its result just like how you wanted.


...Birthday:{ say 0,4 <Did you know?> 0,2 It is $duration2($calc($ctime(february 20 2006 12:00) - $ctime)) until my next birthday!! 0,3 <20th February>  }

PS: the SAY doesnt need the // you only need // or / when typing a command in on the text line.
Sorted it now although it doesn't put a comma on the day part

0,4 <><><> 0,10 It is now: 22 weeks, 1 day 10 hours, 27 minutes and 8 seconds until Christmas Day!! 0,4 <><><> 

it does if it said days

hope i'm not being a pain frown
© mIRC Discussion Forums