According to mikeryan's will (in #1021076: Support for date module in Drupal 7), this is a new issue about date migration.

Did you encounter the following error for any of your tests ? If so, how did you get rid of them?
date_timezone_set() expects parameter 1 to be DateTime, boolean given File common.inc, line 1905
The only time your code seem to call date_timezone_set is in date.test file, but it is called indeed in common.inc inside format_date function with :

<?php
function format_date($timestamp, $type = 'medium', $format = '', $timezone = NULL, $langcode = NULL) {
... (no modification of $timestamp value)
  // Create a DateTime object from the timestamp.
  $date_time = date_create('@' . $timestamp);
  // Set the time zone for the DateTime object.
  date_timezone_set($date_time, $timezones[$timezone]);
...
}
?>

Moreover, don't you think the following piece of code (around line #100) of date.inc is problematic in that way ?

<?php
public function prepare($entity, array $field_info, array $instance, array $values) {
..
 // Work from a timestamp
      $from = MigrationBase::timestamp($from);
      if ($to) {
        $to = MigrationBase::timestamp($to);
      }

      // What does the destination field expect?
      switch ($field_info['type']) {
        case 'datestamp':
          // Already done
          break;
        case 'datetime':
          // YYYY-MM-DD HH:MM:SS
          $from = format_date($from, 'custom', 'Y-m-d H:i', $timezone);
          if ($to) {
            $to = format_date($to, 'custom', 'Y-m-d H:i', $timezone);
          }
          break;
        case 'date':
          // ISO date: YYYY-MM-DDTHH:MM:SS
          $from = format_date($from, 'custom', 'Y-m-d\TH:i', $timezone);
          if ($to) {
            $to = format_date($to, 'custom', 'Y-m-d\TH:i', $timezone);
          }
          break;
        default:
          break;
      }
?>

Indeed, if($to == TRUE), $to = MigrationBase::timestamp($to) = (is_numeric($to) ? $to) = $to = TRUE, and so on each time
I tried with if(isset($to)) but it didn't change anything for me.

Comments

FrequenceBanane’s picture

Okay, sorry. I had messed up my migration with a $current_row->c_datestart = array($current_row->c_datestart, $current_row->c_dateend , 1 , '|'); I had forgotten to remove.

With if(isset($to)) it works perfectly for me. Since the parts of the code I pointed out still don't make sens to me, I will stay with "my" version and wait for feedback about it.

mikeryan’s picture

Status: Active » Postponed (maintainer needs more info)

Can you clarify what part of the code doesn't make sense to you? $timezone going into format_date is a timezone string (e.g, 'America/New_York'), and $to is (if present) a timestamp or datetime string - if not present, it's not used. That all looks as it should be to me.

Thanks.

FrequenceBanane’s picture

Sure, but the current test is if($to), that is to say if $to exists, its value is tested, and we should have a problem for every $to value different from 1 !

mikeryan’s picture

I don't know what you mean by "a problem for every $to value different from 1". If $to exists, it is a Unix timestamp, and we pass it as the first argument to format_date(), which expects a timestamp as its first argument. 1 is a very early Unix timestamp:-), but all the others will work just as well.

FrequenceBanane’s picture

Status: Postponed (maintainer needs more info) » Closed (works as designed)

I'm sorry, I verified how boolans work in PHP and every non-zero value is TRUE, so $to does not have to be 1 to be considered as TRUE in if statement ... :-S

geerlingguy’s picture

Just FYI for anyone else coming from Google... if you have dates like 1900-08-05 (or anything from 1901 to 2038, or thereabouts), you'll get this error, without much in the way of assistance towards debugging. I found that some of the users on my site had birthdates that early, and I had to manually account for those few (really old) users.

From the PHP manual:

The valid range of a timestamp is typically from Fri, 13 Dec 1901 20:45:54 GMT to Tue, 19 Jan 2038 03:14:07 GMT