Full error: Warning: date_timezone_set() expects parameter 1 to be DateTime, boolean given in format_date() (line 1893 of [...]/includes/common.inc).

Reproduce as follows:
Create a page View that uses the day of month in the view argument, set it display a summary if no arguments given
Go to page URL and do not give it an argument

Sample view attached.

The problem is in the views_date_sql_format() function. For mysql/mysqli, the 'd' tolken is being converted to %%d instead of %d. This causes an invalid date string to be passed to the format_date() function.

<?php 
function views_date_sql_format($format, $field, $field_type = 'int', $set_offset = NULL) {
  $db_type = db_driver();
  $field = views_date_sql_field($field, $field_type, $set_offset);
  switch ($db_type) {
    case 'mysql':
    case 'mysqli':
      $replace = array(
        'Y' => '%Y',
        'm' => '%m',
        'd' => '%%d',
        'H' => '%H',
        'i' => '%i',
        's' => '%s',
        );
      $format = strtr($format, $replace);
      return "DATE_FORMAT($field, '$format')";
    case 'pgsql':
      $replace = array(
        'Y' => 'YYYY',
        'm' => 'MM',
        'd' => 'DD',
        'H' => 'HH24',
        'i' => 'MI',
        's' => 'SS',
        );
      $format = strtr($format, $replace);
      return "TO_CHAR($field, '$format')";
  }
}?>

The example view I've given is also effected by the format_date() issue in http://drupal.org/node/894560, which is how I tripped over it :)

CommentFileSizeAuthor
#1 DayToken-914102-1.patch605 bytesdale42
argtestview.txt1.69 KBdale42

Comments

dale42’s picture

Status: Active » Needs review
StatusFileSize
new605 bytes

The patch replaces %%d with %d in mysql $replace array.

dale42’s picture

Patch reviewer may find this a useful link for understanding the token values for DATE_FORMAT:
http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#func...

dawehner’s picture

Version: 7.x-3.x-dev » 6.x-3.x-dev

This should be first fixed in 6.x

dale42’s picture

Status: Needs review » Active

I've tested the same view in Drupal 6 with both 6.x-2.x-dev and 6.x-3.x-dev and can not reproduce the error. Switching the string from %%d to %d breaks the view, so %%d would seem to be correct for Drupal 6 Views. I'm not sure what's causing the difference between 6 and 7.

dawehner’s picture

Version: 6.x-3.x-dev » 7.x-3.x-dev
Status: Active » Needs review

Ah the replacement key in d7 is ":". So "%%" does not get replaced by "%"

dawehner’s picture

Status: Needs review » Fixed

Create a page View that uses the day of month in the view argument, set it display a summary if no arguments given
Go to page URL and do not give it an argument

Please always provide a reusable export of a view. This helps so much!

Sadly i cannot reproduce it. Can you give me a working example? DOH, i'm an idiot.

This patch fixes the issue. Thanks!

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.