Executing a call to date_days(true, 6, 2009) causes the PHP warning:

Warning: date_format() expects parameter 1 to be DateTime, string given in ..../date/date_api.module on line 279

Followed by an array of integers 1-31 no matter what month is specified.

Comments

budda’s picture

The correct parameters for the date_format() call is 'string date_format ( DateTime $object , string $format )' (http://uk2.php.net/manual/en/datetime.format.php)

The date_api.module is passing a string "2009-6-01 00:00:00" as argument 2. it looks like the parameters are the wrong way round too?

Current:

$max = date_format('t', $date);

The format should be argument 2.

budda’s picture

Fixed function involves wedging a $datetime = date_create($date); in there.

<?php
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 = date_make_date($year .'-'. $month .'-01 00:00:00', 'UTC');
    $datetime = date_create($date);
    $max = date_format($datetime, '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));
}
?>

Somebody care to make a patch?

arlinsandbulte’s picture

Status: Active » Closed (won't fix)
haggins’s picture

Version: 5.x-2.x-dev » 6.x-2.4
Status: Closed (won't fix) » Active

This bug is still in the latest release. Without fix the function does not return the correct result.

Are there any reasons why you set status to "won't fix", arlinsandbulte?

iongion’s picture

Why isn't this fixed, it is just a parameters switch, change from:
date_format('t', $date);
to
date_format($date, 't');

damienmckenna’s picture

Issue summary: View changes
Status: Active » Closed (won't fix)

Unfortunately the Drupal 6 version of the Date module is no longer supported. That said, we appreciate that you took time to work on this issue. Should this request still be relevant for Drupal 7 please feel free to reopen it. Thank you.

budda’s picture

9 years pass and still it never got fixed. Crazy.