Wiki source for AgeAction


Show raw source

=====Age Action=====

I haven't seen any actions out there that are useful for determining the age of something provided the start day, month, and year. I'm using this a temporary holding place while I clean up my code and improve some functionality.

This code doesn't quite work yet, but you can see what I'm planning on doing.

=====Source=====
%%(php;1)
<?php
/**
* Age Action for Wikka Wiki (http://wikkawiki.org/AgeAction)
*
* Usage:
* {{age}} - Displays usage
* {{age bYear="####" bMonth="##" bDay="##"}} - Calculates current age based on date function
* {{age bYear="####" bMonth="##" bDay="##"
* dYear="####" dMonth="##" dDay="##"}} - Calculates age based on death day
*
* Version 0.1
* @input int $bYear Mandatory: Birth/Start year
* @input int $bMonth Mandatory: Birth/Start month
* @input int $bDay Mandatory: Birth/Start day
* @input int $dYear Optional: Death/End year
* @input int $dMonth Optional: Death/End month
* @input int $dDay Optional: Death/End day
* @output int $age The age provided by either
* current date - birth/start date or death/end date - birth/start date
* @uses Wakka::ReturnSafeHTML()
* @todo Add Death/End Date calculations
*
* Changelog
* 0.1 Initial revision
*/

// Get the Birth/Start dates
$bYear = (int)trim($this->htmlspecialchars_ent($vars['byear']));
$bMonth = (int)trim($this->htmlspecialchars_ent($vars['bmonth']));
$bDay = (int)trim($this->htmlspecialchars_ent($vars['bday']));

// Get the Death/End Dates
$dYear = (int)trim($this->htmlspecialchars_ent($vars['dyear']));
$dMonth = (int)trim($this->htmlspecialchars_ent($vars['dmonth']));
$dDay = (int)trim($this->htmlspecialchars_ent($vars['dday']));


$day=(empty($day))?'1':$day;

list($this_year, $this_month, $this_day) = explode(' ',date('Y n j'));
$age = $this_year - $bYear;

if ($bMonth>$this_month||($this_month==$bMonth&&$this_day<$bDay)) {
$age--;
}

echo $this->ReturnSafeHTML($age);
?>
%%
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki