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:
parent
8d70868be6
commit
b8b42b0cce
1 changed files with 25 additions and 0 deletions
25
functions/smarty/function.age.php
Normal file
25
functions/smarty/function.age.php
Normal 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;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
Loading…
Add table
Add a link
Reference in a new issue