rendered paste bodyage {
;--------------------------------------------------------
; Set this to your birthdate in dd/mm/yyyy format:
;
var %birthdate 09/10/1991
;
;--------------------------------------------------------
var %age = $agex(%birthdate)
var %out = Im %age years old;
var %next_age = $calc($floor(%age) +1)
var %next_bd = $gettok($next_bd(%birthdate),1-2,32)
say %out Ill turn %next_age in $+(%next_bd,.)
}
; $agex(dd/mm/yyyy) - returns an exact Gregorian calendar
; age, based on the specified birthdate.
agex {
var %foo = $+($gettok($$1,1,47),/,$gettok($1,2,47),/)
var %bar = $date(yyyy), %bdays, %mn 00:00:00
var %bday = $+(%foo,%bar), %lastbd $+(%foo,$calc(%bar -1))
if ($$ctime(%bday %mn) <= $ctime) { %lastbd = %bday
%bday = $+(%foo,$calc(%bar +1)) }
%foo = $calc($ctime(%bday %mn) - $ctime)
%bar = $calc($ctime(%bday %mn) - $ctime(%lastbd %mn))
%bdays = $calc($ctime(%lastbd %mn) - $$ctime($1 %mn))
%bdays = $round($calc(%bdays / 31556952),0)
return $calc(%bdays + (1- %foo / %bar))
}
; $next_bd(dd/mm) - returns time left to the next birthday,
; based on the specified date.
next_bd {
var %tmp = $gettok($$1,1-2,47)
var %next_bd = $+(%tmp,/,$date(yyyy))
if ($ctime(%next_bd) <= $ctime) {
%next_bd = $+(%tmp,/,$calc($date(yyyy) +1))
} | %next_bd = %next_bd 00:00:00
var %delta = $calc($ctime(%next_bd) - $ctime)
return $duration(%delta)
}