示例#1
0
function compare_month_gap($first_date, $second_date, $monthgap)
{
    // checks gap in months between two dates (to check for birth less than X months after wedding)
    include_once CMS_ROOTPATH . 'include/calculate_age_cls.php';
    $process_date = new calculate_year_cls();
    // take care of combined julian/gregorian dates (1678/9)
    if (strpos($first_date, '/') > 0) {
        $temp = explode('/', $first_date);
        $first_date = $temp[0];
    }
    if (strpos($second_date, '/') > 0) {
        $temp = explode('/', $second_date);
        $second_date = $temp[0];
    }
    $first_date = strtoupper($first_date);
    // $process_date->search_month uses upppercase months: DEC, FEB
    $second_date = strtoupper($second_date);
    $year1 = $process_date->search_year($first_date);
    $month1 = $process_date->search_month($first_date);
    $day1 = $process_date->search_day($first_date);
    $year2 = $process_date->search_year($second_date);
    $month2 = $process_date->search_month($second_date);
    $day2 = $process_date->search_day($second_date);
    if ($year1 and $year2 and $month1 and $month2) {
        if ($year1 == $year2) {
            // dates in same year - we can deduct month1 from month2
            if ($month2 - $month1 < $monthgap) {
                return $month2 - $month1;
            } else {
                return false;
            }
        } elseif ($year1 + 1 == $year2) {
            // consecutive years
            if (12 - $month1 + $month2 < $monthgap) {
                return 12 - $month1 + $month2;
            } else {
                return false;
            }
        } else {
            return false;
        }
    } else {
        return false;
    }
    // insufficient data
}