alias fmtdur {
; Usage: $fmtdur(secs [, format])
; Formatting: [y year] [m month] [w week] [d day] [h hour] [n minute] [s second] [u units]
; Using the same character consecutively will zeropad that unit to the given length (ie. n = 7, nnn = 007)
; Doubling the u character will cause it to use the full format (ie. nu = 6mins, nuu = 6minutes)
; Uppercase U characters will capitalize units.
var %fmt = $iif($2,$2,wu du hu nu su), %secs = $int($1), %count = $regex(fmtdur, %fmt, /(([^ymwdhns]*)(y+|m+|w+|d+|h+|n+|s+)([^ymwdhnsUu]*)([Uu]*))/g)
var %yrs, %mnths, %wks, %days, %hrs, %mins, %i = 1, %fmtchars, %unitchars, %durstr, %amount, %units
if (y isincs %fmt) { %yrs = $int($calc(%secs / 31557600)) | %secs = $calc(%secs % 31557600) }
if (m isincs %fmt) { %mnths = $int($calc(%secs / 2629800)) | %secs = $calc(%secs % 2629800) }
if (w isincs %fmt) { %wks = $int($calc(%secs / 604800)) | %secs = $calc(%secs % 604800) }
if (d isincs %fmt) { %days = $int($calc(%secs / 86400)) | %secs = $calc(%secs % 86400) }
if (h isincs %fmt) { %hrs = $int($calc(%secs / 3600)) | %secs = $calc(%secs % 3600) }
if (n isincs %fmt) { %mins = $int($calc(%secs / 60)) | %secs = $calc(%secs % 60) }
while %i <= $calc(%count * 5) {
%fmtchars = $regml(fmtdur, $calc(%i + 2))
%unitchars = $regml(fmtdur, $calc(%i + 4))
%amount = $charpad($replace($left(%fmtchars, 1),y,%yrs,m,%mnths,w,%wks,d,%days,h,%hrs,n,%mins,s,%secs), $len(%fmtchars), 0)
if (u isin %unitchars) {
if ($len(%unitchars) == 1) %units = $replacex($left(%fmtchars,1),y,yr,m,mth,w,wk,d,dy,h,hr,n,min,s,sec)
else %units = $replacex($left(%fmtchars,1),y,year,m,month,w,week,d,day,h,hour,n,minute,s,second)
if (%amount != 1) %units = $+(%units, s)
if (U isincs %unitchars) %units = $+($upper($left(%units,1)), $right(%units,-1))
}
else %units = $null
%durstr = $+($left(%durstr, -1), $regml(fmtdur, $calc(%i + 1)), %amount, $regml(fmtdur, $calc(%i + 3)), %units, x))
inc %i 5
}
return $left(%durstr, -1)
}
on *:text:!agedif*:*:{
if !$2 || !$3 { .msg $nick Sorry, I can't find a birthday for no one }
elseif !$readini(dob.ini,dob,$2) { .msg $nick Sorry, I can't find a birthday for $2 }
elseif !$readini(dob.ini,dob,$3) { .msg $nick Sorry, I can't find a birthday for $3 }
elseif $readini(dob.ini,dob,$2) == $readini(dob.ini,dob,$3) { .msg $nick $2 & $3 have the same birthdays }
else {
var %year.1 = $right($readini(dob.ini,dob,$2)), %year.2 = $right($readini(dob.ini,dob,$3))
while %year.1 < 1970 {
if $calc(%year.1 / 4) == $int($calc(%year.1 / 4)) { inc %dob.1 86400 }
inc %year.1
}
while %year.2 < 1970 {
if $calc(%year.2 / 4) == $int($calc(%year.2 / 4)) { inc %dob.2 86400 }
inc %year.2
}
inc %dob.1 $ctime($+($left($readini(dob.ini,dob,$2),-4),1970,$chr(32),00:00:00))
inc %dob.2 $ctime($+($left($readini(dob.ini,dob,$3),-4),1970,$chr(32),00:00:00))
}
if %dob.1 > %dob.2 {
.msg $nick $2 is $fmtdur($calc(%dob.1 - %dob.2),yruu mthuu wkuu dyuu) older than $3
}
else {
.msg $nick $3 is $fmtdur($calc(%dob.2 - %dob.1),yruu mthuu wkuu dyuu) older than $2
}
}