/**
 * Determines the number of days at a specified month/year.
 *
 * @param  int The month
 * @param  int The year
 * @return int Number of days
 *
 * @author Former03 GmbH :: Florian Lippert <*****@*****.**>
 */
function getDaysForMonth($month, $year)
{
    if ((int) $month > 12) {
        $year += (int) ($month / 12);
        $month = $month % 12;
    }
    if ((int) $month == 0) {
        $month = 12;
    }
    $months = array(1 => 31, 2 => 28, 3 => 31, 4 => 30, 5 => 31, 6 => 30, 7 => 31, 8 => 31, 9 => 30, 10 => 31, 11 => 30, 12 => 31);
    if (getDaysForYear($month, $year) == 366) {
        $months[2] = '29';
    }
    return $months[intval($month)];
}
Example #2
0
 /**
  * Due to the weirdness in our calendar we need a special
  * method for gathering the number days in an interval.
  *
  * @param int    Length of interval
  * @param string Type of interval, might be 'd' for day,'m' for month or 'y' for year
  * @param array  Date when service began, in array form: array( 'd' => int, 'm' => int, 'y' => int )
  *
  * @return int Number of days in the interval
  *
  * @author Former03 GmbH :: Florian Lippert <*****@*****.**>
  */
 public function getDaysForInterval($interval_length, $interval_type, $service_date_begin_array)
 {
     $returnval = 0;
     switch ($interval_type) {
         case 'y':
             for ($i = 1; $i <= $interval_length; ++$i) {
                 $returnval += getDaysForYear((int) $service_date_begin_array['m'], (int) $service_date_begin_array['y'] + ($i - 1));
             }
             break;
         case 'm':
             for ($i = 1; $i <= $interval_length; ++$i) {
                 $returnval += getDaysForMonth((int) $service_date_begin_array['m'] + ($i - 1), (int) $service_date_begin_array['y']);
             }
             break;
         case 'd':
         default:
             $returnval = $interval_length;
             break;
     }
     return $returnval;
 }