$calcdate() identifier

By PuNkTuReD on Dec 24, 2010

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)
}

Comments

Sign in to comment.
ProIcons   -  Dec 25, 2010

Well about the end of the world Punktured at 2013 i will be on a sunny beach with 2 chicks :D just to know :PpPp

 Respond  
IllogicTC   -  Dec 25, 2010

Aw man, I was looking at this script and going to post a much shorter code. Then I scroll down to the bottom and jaytea already did it.

 Respond  
jaytea   -  Dec 24, 2010

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.

 Respond  
PuNkTuReD   -  Dec 24, 2010

ok edited. now supports leap years up until 2020

if ($exists($world) && $date(yyyy) == 2020) { $fix_yourself(Im Retired) }
 Respond  
PuNkTuReD   -  Dec 24, 2010

ok ill add the next 5 leap years in, bbl.
well hey, if your a superstitous type, the worlds gnna end in 2012 anyway.

ok so im lazy, i only added 3.

 Respond  
ProIcons   -  Dec 24, 2010

Well the 32bit Operating Systems Clocks, will stop in a few years? maybe?:P sooo a quick fix would be nice:D

 Respond  
PuNkTuReD   -  Dec 24, 2010

well, for that, i could implement a quick fix, but i would like to think that in 100 years people would still be using mirc, so i wanna add a fix which will support allllll years till the end of time.

 Respond  
ProIcons   -  Dec 24, 2010

Notes:
I know this doesn't currently support leap years. (But next year isn't a leap year, so I have plenty of time to update.)

9/10 Nice job ;)

 Respond  
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.