You are here

function date_calc_weeks_in_month in Date 6.2

Same name and namespace in other branches
  1. 5.2 date_php4/date_php4_calc.inc \date_calc_weeks_in_month()
  2. 6 date_php4/date_php4_calc.inc \date_calc_weeks_in_month()

Returns the number of rows on a calendar month. Useful for determining the number of rows when displaying a typical month calendar.

Parameters

int $month: The month.

int $year: The 4 digit year. Do not add leading 0's for years prior to 1000.

Return value

int The number of weeks the month has.

1 call to date_calc_weeks_in_month()
date_calc_get_calendar_month in date_php4/date_php4_calc.inc
Return a set of arrays to construct a calendar month for the given date.

File

date_php4/date_php4_calc.inc, line 700

Code

function date_calc_weeks_in_month($month = 0, $year = 0) {
  if (empty($year)) {
    $year = date_calc_get_year();
  }
  if (empty($month)) {
    $month = date_calc_get_month();
  }
  $FDOM = date_calc_first_of_month_weekday($month, $year);
  if (variable_get('date_first_day', 1) == 1 && $FDOM == 0) {
    $first_week_days = 7 - $FDOM + variable_get('date_first_day', 1);
    $weeks = 1;
  }
  elseif (variable_get('date_first_day', 1) == 0 && $FDOM == 6) {
    $first_week_days = 7 - $FDOM + variable_get('date_first_day', 1);
    $weeks = 1;
  }
  else {
    $first_week_days = variable_get('date_first_day', 1) - $FDOM;
    $weeks = 0;
  }
  $first_week_days %= 7;
  return ceil((date_calc_days_in_month($month, $year) - $first_week_days) / 7) + $weeks;
}