Added a new smarty function.

git-svn-id: http://svn.cleancode.org/svn/pickles@116 4d10bc64-7434-11dc-a737-d2d0f8310089
This commit is contained in:
Josh Sherman 2009-05-10 03:28:53 +00:00
parent 8d70868be6
commit b8b42b0cce

View file

@ -0,0 +1,25 @@
<?php
function smarty_function_age($params, &$smarty) {
if (empty($params['dob'])) {
$smarty->trigger_error('assign: missing \'dob\' parameter');
}
else {
// Breaks the date apart
list($dob_year, $dob_month, $dob_day) = split('-', $params['dob'], 3);
// Determines the age regardless of the day
$age = date('Y') - $dob_year;
// If today's month day is less than the dob decrement
if (date('md') < $dob_month . $dob_day) {
$age--;
}
return $age;
}
}
?>