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 :)
| Comment | File | Size | Author |
|---|---|---|---|
| #1 | DayToken-914102-1.patch | 605 bytes | dale42 |
| argtestview.txt | 1.69 KB | dale42 |
Comments
Comment #1
dale42The patch replaces %%d with %d in mysql $replace array.
Comment #2
dale42Patch 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...
Comment #3
dawehnerThis should be first fixed in 6.x
Comment #4
dale42I'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.
Comment #5
dawehnerAh the replacement key in d7 is ":". So "%%" does not get replaced by "%"
Comment #6
dawehnerPlease 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!