mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Jan 2007
Posts: 280
Fjord artisan
OP Offline
Fjord artisan
Joined: Jan 2007
Posts: 280
Hi,

I've got this 'duration' script, which tells me how many months me and my boyfriend are together. But I've got a small issue.

I've edited it so it would put a , after each time thing (hour, minute, second etc.). So that would be: blablabla 3 hours, 25 minutes, 23 seconds.

But the problem is, it'll only add a , when the duration is more than 1 (> 1). When it's less than 1, or equal to 1, it wont add a , and I can't get this fixed.

Code:
alias richloe { 
  var %richloe = $dur($calc($ctime - $ctime(%richloe))) 
  msg $chan ricoenchloƫ
  msg $chan They are together for %richloe $+ . Isn't that amazing!?
} 

alias -l dur { %a = $1 | return $iif(!%a,0secs,$s(31536000, $chr(32) year) $s(2628000.0288, $chr(32) month) $s(604800, $chr(32) week) $s(86400, $chr(32) day) $s(3600, $chr(32) hour) $s(60, $chr(32) minute) $s(1, $chr(32) second)) }

alias -l s { 
  %b = $int($calc(%a /$1))
  %a = %a % $1 
  if (%b && %c) {
    return %b $+ $2 $+ $iif(%b > 1,s $+ $chr(44) $+ ) 
  }
}


The variable %richloe has been set as: %richloe April 16 2010 13:11:00



Also, after 'minutes' it should add a 'and' in stead of a , (so, 22 hours, 23 minutes AND 45 seconds)

Any help?

Last edited by DuXxXieJ; 27/04/11 02:51 PM.

Squee whenever a squee squee's. Squee whenever a squee does not squee.
Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
I have a $DateXpander identifier that would display your months and years accurately based on number of days in the month and handles leap years as well. The output format can be adjusted through it as well. Up to you if you'd like to take a look at it.

* For these example, 32480239 is $calc($ctime - $ctime(%richloe))

Input: //echo -a $datexpander(32480239)
Output: 1 year, 1 week, 3 days, 22 hours, 17 minutes, and 19 seconds

As you can see, that auto-hides anything that is 0. You can force the display like this:

Input: //echo -a $datexpander(32480239,ymwdhns)
Output: 1 year, 0 months, 1 week, 3 days, 22 hours, 17 minutes, and 19 seconds

Various formats can be easily handled, such as only displaying the total number of days:

Input: //echo -a $datexpander(32480239,d)
Output: 375 days

Or changing the output format:

Input: //echo -a $datexpander(32480239,03d04h05n06s)
Output: 375 days, 22 hours, 17 minutes, and 19 seconds

Just as some examples of what it can do.


Invision Support
#Invision on irc.irchighway.net
Joined: Jan 2007
Posts: 280
Fjord artisan
OP Offline
Fjord artisan
Joined: Jan 2007
Posts: 280
That looks realy nice! I was searching for something like that, especially the (numbers,d) //days.

I would love to take a look at it!



Squee whenever a squee squee's. Squee whenever a squee does not squee.
Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
The link will take you to where you can get it. There are also some more examples and explanations in the description and comments there. If you have questions, just let me know here or in PM.

The nice thing is that if you go from Feb 1 to Mar 1, it counts as a month rather than 28 or 29 days, and if you go from Mar 1 to Apr 1, it also counts as a month. So it's very accurate without just using the average number of days per month in the calculations. It's the same thing for leap years... Jan 1 2012 to Jan 1 2013 is a year, and so is Jan 1 2011 to Jan 1 2012 even though there is one more day in 2012.


Invision Support
#Invision on irc.irchighway.net
Joined: Jan 2007
Posts: 280
Fjord artisan
OP Offline
Fjord artisan
Joined: Jan 2007
Posts: 280
Hi,

I just found a (perhaps?) small bug. When converting a date with a year which is older than 41 years it wont count anymore.

Well, actually.. I've got a 'addage' script so people add their age by .addage September 5 1990 etc.

But when adding an age (for test) with year 1889, it should say 141 years but it says 41 years. When adding an age with year 1100 it also says 41.

Any fix? frown


Squee whenever a squee squee's. Squee whenever a squee does not squee.
Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
What specific data are you sending to the datexpander identifier?

//echo -a $datexpander(8976546512)
284 years, 5 months, 1 week, 6 days, 5 hours, 8 minutes, and 32 seconds

Keep in mind that $ctime() doesn't work for before 00:00:00 GMT, January 1, 1970 if you're using that in your addage script.


Invision Support
#Invision on irc.irchighway.net

Link Copied to Clipboard