You are here

function date_days in Date 7.2

Same name and namespace in other branches
  1. 5.2 date_api.module \date_days()
  2. 6.2 date_api.module \date_days()
  3. 6 date_api.module \date_days()
  4. 7.3 date_api/date_api.module \date_days()
  5. 7 date_api/date_api.module \date_days()

Constructs an array of days in a month.

Parameters

bool $required: (optional) If FALSE, the returned array will include a blank value. Defaults to FALSE.

int $month: (optional) The month in which to find the number of days.

int $year: (optional) The year in which to find the number of days.

Return value

array An array of days for the selected month.

1 call to date_days()
date_parts_element in date_api/date_api_elements.inc
Creates form elements for one or more date parts.

File

date_api/date_api.module, line 1392
This module will make the date API available to other modules.

Code

function date_days($required = FALSE, $month = NULL, $year = NULL) {

  // If we have a month and year, find the right last day of the month.
  if (!empty($month) && !empty($year)) {
    $date = new DateObject($year . '-' . $month . '-01 00:00:00', 'UTC');
    $max = $date
      ->format('t');
  }

  // If there is no month and year given, default to 31.
  if (empty($max)) {
    $max = 31;
  }
  $none = array(
    0 => '',
  );
  return !$required ? $none + drupal_map_assoc(range(1, $max)) : drupal_map_assoc(range(1, $max));
}