Drupal 7 beta 2, dev snapshots of CCK, Views, Date, Calendar, Context. PHP 5.2.10 on MAMP.

Without adding any content, I added the Calendar and Upcoming blocks to the sidebar, then the following errors started showing:

Warning: date_create() expects parameter 2 to be DateTimeZone, string given in date_api_filter_handler->default_value() (line 347 of /sites/all/modules/contrib/date/includes/date_api_filter_handler.inc).
Warning: date_format() expects parameter 1 to be DateTime, boolean given in date_api_filter_handler->default_value() (line 349 of /sites/all/modules/contrib/date/includes/date_api_filter_handler.inc).

Reading through the code, the first error leads to the second one:


      // For PHP 5.2+, take advantage of any strings that native PHP 
      // date_create() can handle. For older versions use strtotime().
      if (version_compare(PHP_VERSION, '5.2', '<')) {
        $now = strtotime($default_option . ' UTC');
        $date = date_create("@$now", timezone_open('UTC'));
      }
      else {
        $date = date_create($default_option, date_default_timezone());
      }
      $default_date = date_format($date, DATE_FORMAT_DATETIME);

First off, if PHP 5.2 is now the base requirement then the IF statement could be reduced to:

      $date = date_create($default_option, date_default_timezone());

The date_create() function requires the second argument to be a DateTimeZone object, but date_default_timezone() returns a string. The suggested fix is to use date_default_timezone_object() instead.

CommentFileSizeAuthor
#2 date-n969344.patch1.26 KBdamienmckenna

Comments

damienmckenna’s picture

Title: date_api_filter_handler->get_query_fields() calls date_default_timezone(), not date_default_timezone_object() » date_api_filter_handler->default_value() calls date_default_timezone(), not date_default_timezone_object()

Corrected the method name that has the actual bug.

damienmckenna’s picture

Status: Active » Needs review
StatusFileSize
new1.26 KB

A patch that applies the suggested changes above.

karens’s picture

Status: Needs review » Fixed

Fixed. Thanks!

Status: Fixed » Closed (fixed)

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