This was a request I done on another forum,
but figured I would post it here since I haven't posted in a while.
About:
This will add a number of days to the date given.
Syntax: $calcdate(DATE,ADD)
where date is in the format of dd/mm/yy
where add is the number of days to add to DATE
Examples:
//echo -a $calcdate(24/12/2010,5)
returns: 29/12/2010
//echo -a $calcdate(24/12/2010,10)
returns: 03/01/2011
//echo -a $calcdate(24/12/2010,100)
returns: 31/03/2011
This can also be used in scripts,
one example would be game scripts.
A game where you can't collect an item for X number of days.
msg $nick You can collect this item again on: $calcdate($date,X)
Or games which allow users to gain levels after X amount of days:
msg $nick You will reach level X on: $calcdate($date,X)
Notes:
This will only support leap years up to 2020, after that ill be retired from scripting, so fix it yourself.
;====================================
; ===================================
;
; $calcdate(DATE,ADD) Identifier
;
; Made By PuNkTuReD
; http://www.sassirc.com
;
; ===================================
;====================================
alias calcdate {
var %d1 = $gettok($$1,1,47), %m1 = $gettok($$1,2,47), %y1 = $gettok($$1,3,47), %add = $$2
var %by = $iif(%m1 == 02, $iif($istok(2012 2016 2020,%y1,32),29,28),$iif($istok(01 03 05 07 08 10 12,%m1,32),31,30))
if ($calc(%d1 + %add) > %by) {
var %over = $calc(%d1 + %add)
while (%over > %by) {
var %d1 = $calc(%over - %by), %m1 = $calc(%m1 + 01)
if (%m1 == 13) { var %y1 = $calc(%y1 + 01), %m1 = $calc(%m1 - 12) }
dec %over %by
}
}
else { var %d1 = $calc(%d1 + %add) }
var %d1 = $iif($len(%d1) == 1,$+(0,%d1),%d1)
var %m1 = $iif($len(%m1) == 1,$+(0,%m1),$iif($len(%m1) == 3,$right(%m1,2),%m1))
return $+(%d1,$chr(47),%m1,$chr(47),%y1)
}
ProIcons, if by 'a few' you mean 27 years from now! it is a near certainty that, by that time, the problem of representing dates decades, centuries, and even millennia into the future will be non-existent.
this particular snippet handles the input as a string rather than as a date (in that it doesn't use any date related functions), thus it isn't constrained as it would be if it were coded as such:
alias calcdate return $asctime($calc($ctime($1) + 86400 * $2), dd/mm/yyyy)
this, while correctly supporting leap years, doesn't handle dates past 19/01/2038.