Changed average age from now to start of event

This commit is contained in:
2013-10-02 15:57:20 +10:00
parent bb5dc7322e
commit ed2ca13ae8
2 changed files with 37 additions and 13 deletions

View File

@@ -269,7 +269,7 @@ function _booking_convert_ts($timestamp)
/**
* Helper function to ensure timestamp is converted to correct local time
* Helper function to calculate the timestamp corresponding with the DOB requirements
*/
function _booking_max_dob_ts()
{
@@ -278,6 +278,22 @@ function _booking_max_dob_ts()
return mktime(12, 0, 0, $max_dob_matches[2], $max_dob_matches[3], $max_dob_matches[1]);
}
/**
* Helper function to calculate the average age in days, months and years at the start of the event
*/
function _booking_avg_age($sum, $count, $reference_ts)
{
global $event;
//calculate the average age timestamp
$average = $sum / $count;
//get the difference between now and the average timestamp
$average_date = _booking_convert_ts(floor($average));
$now_date = _booking_convert_ts(floor($reference_ts));
$difference = $average_date->diff($now_date);
//convert the difference into english
return $difference->y . " years, " . $difference->m . " months, " . $difference->d . " days";
}
function _date_range_to_string($date_start, $date_end) {
$start = _booking_split_date($date_start);
$end = _booking_split_date($date_end);