mIRC Home    About    Download    Register    News    Help

Print Thread
changing this $duration into different settings #125660 20/07/05 02:42 PM
Joined: Dec 2002
Posts: 174
K
Kev_Uk Offline OP
Vogon poet
OP Offline
Vogon poet
K
Joined: Dec 2002
Posts: 174
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,20*13~0*60*0 It's now: $duration($calc($ctime(february 20 2006 12:00) - $ctime)) until my birthday!! 0,2*4,20*13~0*60* }
...To Self:{ //echo 0,2*4,20*13~0*60*0 It's now: $duration($calc($ctime(february 20 2006 12:00) - $ctime)) until my birthday!! 0,2*4,20*13~0*60* }
.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,20*13~0*60*0 It's now: $duration($calc($ctime(december 25 2005 00:00) - $ctime)) until Christmas Day!! 0,2*4,20*13~0*60* }
.New Year's Day
..Say
...To $active:{ //say 0,2*4,20*13~0*60*0 It's now: $duration($calc($ctime(january 1 2006 00:00) - $ctime)) until year 2006!! 0,2*4,20*13~0*60* }
...To Self:{ //echo 0,2*4,20*13~0*60*0 It's now: $duration($calc($ctime(january 1 2006 00:00) - $ctime)) until year 2006!! 0,2*4,20*13~0*60* }
}

Re: changing this $duration into different settings #125661 20/07/05 02:51 PM
Joined: Oct 2004
Posts: 8,330
Riamus2 Offline
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
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.


Invision Support
#Invision on irc.irchighway.net
Re: changing this $duration into different setting #125662 21/07/05 02:30 AM
Joined: Dec 2002
Posts: 174
K
Kev_Uk Offline OP
Vogon poet
OP Offline
Vogon poet
K
Joined: Dec 2002
Posts: 174
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?

Re: changing this $duration into different setting #125663 21/07/05 10:30 AM
Joined: Dec 2002
Posts: 174
K
Kev_Uk Offline OP
Vogon poet
OP Offline
Vogon poet
K
Joined: Dec 2002
Posts: 174
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

Re: changing this $duration into different setting #125664 21/07/05 02:23 PM
Joined: Oct 2004
Posts: 8,330
Riamus2 Offline
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
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.


Invision Support
#Invision on irc.irchighway.net
Re: changing this $duration into different setting #125665 21/07/05 02:59 PM
Joined: Dec 2002
Posts: 174
K
Kev_Uk Offline OP
Vogon poet
OP Offline
Vogon poet
K
Joined: Dec 2002
Posts: 174
could you add that long code you made into the script for me please im confused on the best place for it sorry

Re: changing this $duration into different setting #125666 21/07/05 03:15 PM
Joined: Sep 2003
Posts: 4,230
D
DaveC Offline
Hoopy frood
Offline
Hoopy frood
D
Joined: Sep 2003
Posts: 4,230
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.

Re: changing this $duration into different setting #125667 21/07/05 03:25 PM
Joined: Dec 2002
Posts: 174
K
Kev_Uk Offline OP
Vogon poet
OP Offline
Vogon poet
K
Joined: Dec 2002
Posts: 174
So instead of putting in $duration($calc($ctime(february 20 2006 12:00) - $ctime)) i just put in /alias duration2?

Re: changing this $duration into different setting #125668 21/07/05 03:34 PM
Joined: Sep 2003
Posts: 4,230
D
DaveC Offline
Hoopy frood
Offline
Hoopy frood
D
Joined: Sep 2003
Posts: 4,230
no

$duration2($calc($ctime(february 20 2006 12:00) - $ctime))

Re: changing this $duration into different setting #125669 21/07/05 03:49 PM
Joined: Dec 2002
Posts: 174
K
Kev_Uk Offline OP
Vogon poet
OP Offline
Vogon poet
K
Joined: Dec 2002
Posts: 174
seems to be a double comma , between days and hours

Re: changing this $duration into different setting #125670 21/07/05 03:54 PM
Joined: Oct 2004
Posts: 8,330
Riamus2 Offline
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
Interesting. I hadn't considered it that way. smile

Now I feel stupid. It was so easy. Heh.


Invision Support
#Invision on irc.irchighway.net
Re: changing this $duration into different setting #125671 22/07/05 02:16 AM
Joined: Dec 2002
Posts: 174
K
Kev_Uk Offline OP
Vogon poet
OP Offline
Vogon poet
K
Joined: Dec 2002
Posts: 174
<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 ,

Re: changing this $duration into different setting #125672 22/07/05 10:11 AM
Joined: Sep 2003
Posts: 4,230
D
DaveC Offline
Hoopy frood
Offline
Hoopy frood
D
Joined: Sep 2003
Posts: 4,230
//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.

Re: changing this $duration into different setting #125673 22/07/05 11:10 AM
Joined: Dec 2002
Posts: 174
K
Kev_Uk Offline OP
Vogon poet
OP Offline
Vogon poet
K
Joined: Dec 2002
Posts: 174
.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

Re: changing this $duration into different setting #125674 22/07/05 11:16 AM
Joined: Sep 2003
Posts: 4,230
D
DaveC Offline
Hoopy frood
Offline
Hoopy frood
D
Joined: Sep 2003
Posts: 4,230
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.

Re: changing this $duration into different setting #125675 22/07/05 01:34 PM
Joined: Dec 2002
Posts: 174
K
Kev_Uk Offline OP
Vogon poet
OP Offline
Vogon poet
K
Joined: Dec 2002
Posts: 174
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

Last edited by Kev_Uk; 22/07/05 01:37 PM.