$start,'date'=>$start,'end'=>$period_end,'prorate'=>1); # Monthly case 1: $inc_months = 1; break; # Quarterly case 2: # @todo Make this configurable. $strict = TRUE; $inc_months = 3; break; # Half Yearly case 3: # @todo Make this configurable. $strict = TRUE; $inc_months = 6; break; # Yearly case 4: $inc_months = 12; break; # Biennial case 5: $inc_months = 24; break; # Triennial case 6: $inc_months = 36; break; default: return FALSE; } // If workout a day of week we calculate to. if (is_null($weekday)) $weekday = date('d',$start); $used_months = 0; if ($strict && $type > 0 && $type < 5) $used_months = $inc_months-(($inc_months-(date('n',$start)%$inc_months))%$inc_months+1); $d = mktime(0,0,0,date('m',$start)-$used_months,$weekday,date('y',$start)); if ($d <= $start) $period_start = $d; else $period_start = mktime(0,0,0,date('m',$d)-1-$used_months,$weekday,date('y',$d)); $period_end = mktime(0,0,0,date('m',$period_start)+$inc_months,$weekday,date('y',$period_start)); $total_time = $period_end-$period_start; $remain_time = $period_end-$start; $used_time = $start-$period_start; // Change our end date to the day before $period_end -= 86400; $return = array( 'start'=>$period_start, 'date'=>$start, 'end'=>$period_end, 'weekday'=>$weekday, 'prorata'=>round($remain_time/$total_time,$precision), 'total_time'=>sprintf('%3.1f',$total_time/86400), 'remain_time'=>sprintf('%3.1f',$remain_time/86400), 'used_time'=>sprintf('%3.1f',$used_time/86400)); // @todo Use the configured data format if ($df) foreach (array('start','date','end') as $key) $return[$key] = date('Y-m-d',$return[$key]); return $return; } } ?>