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

  1. <?php
  2. /**
  3.  * Age Action for Wikka Wiki (http://wikkawiki.org/AgeAction)
  4.  *
  5.  * Usage:
  6.  *      {{age}} - Displays usage
  7.  *      {{age bYear="####" bMonth="##" bDay="##"}}  - Calculates current age based on date function
  8.  *      {{age bYear="####" bMonth="##" bDay="##"
  9.  *        dYear="####" dMonth="##" dDay="##"}}      - Calculates age based on death day
  10.  *
  11.  * Version 0.1
  12.  * @input   int $bYear    Mandatory: Birth/Start year
  13.  * @input   int $bMonth   Mandatory: Birth/Start month
  14.  * @input   int $bDay     Mandatory: Birth/Start day
  15.  * @input   int $dYear    Optional: Death/End year
  16.  * @input   int $dMonth   Optional: Death/End month
  17.  * @input   int $dDay     Optional: Death/End day
  18.  * @output  int $age      The age provided by either
  19.  *                        current date - birth/start date or death/end date - birth/start date
  20.  * @uses    Wakka::ReturnSafeHTML()
  21.  * @todo    Add Death/End Date calculations      
  22.  *
  23.  * Changelog
  24.  *  0.1     Initial revision  
  25.  */
  26.  
  27. // Get the Birth/Start dates
  28. $bYear = (int)trim($this->htmlspecialchars_ent($vars['byear']));
  29. $bMonth = (int)trim($this->htmlspecialchars_ent($vars['bmonth']));
  30. $bDay = (int)trim($this->htmlspecialchars_ent($vars['bday']));
  31.  
  32. // Get the Death/End Dates
  33. $dYear = (int)trim($this->htmlspecialchars_ent($vars['dyear']));
  34. $dMonth = (int)trim($this->htmlspecialchars_ent($vars['dmonth']));
  35. $dDay = (int)trim($this->htmlspecialchars_ent($vars['dday']));
  36.  
  37.  
  38. $day=(empty($day))?'1':$day;
  39.  
  40. list($this_year, $this_month, $this_day) = explode(' ',date('Y n j'));
  41. $age = $this_year - $bYear;
  42.  
  43. if ($bMonth>$this_month||($this_month==$bMonth&&$this_day<$bDay)) {
  44.     $age--;
  45.     }
  46.  
  47. echo $this->ReturnSafeHTML($age);
  48. ?>
There is one comment on this page. [Display comment]
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki