By my eye, it appears that all dates are first converted to Unix timestamps:

      // Work from a timestamp
      $from = MigrationBase::timestamp($from);
      if ($to) {
        $to = MigrationBase::timestamp($to);
      }

Timestamps will not work for dates prior to the Unix epoch. We should be using DateTime, and use Date module's helper functions for converting between the different formats. It'd probably be helpful to get Karen Stevenson's thoughts around this, too.

Comments

q0rban’s picture

Hmm, maybe I'm wrong about this. I guess strtotime returns negative numbers for times prior to the epoch? Still, Karen always advises me not to use timestamps, and when Karen says something about dates, I listen. ;)

mikeryan’s picture

Project: Migrate Extras » Date
Component: Date » Miscellaneous

@q0rban: Date migration support is in the Date module itself now.

KarenS’s picture

Title: All dates are converted to a Unix timestamp » Rework Date Migrate to not use timestamps
Category: bug » task

I'm going to switch this to a task. Timestamps are more limited but will work fine so long as you are not trying to migrate historical dates, so it is probably not critical to fix immediately.

hamish_s’s picture

So, as I read through as many of the issue reports (on dates before 1901) as I possibly can, may I now conclude that dates before 1901 cannot be imported? That is, as KarenS suggests, that for those who need to import historical dates (as I do), we are a small group of users, and therefore, given the resource requirements, it is unlikely to get fixed in any reasonable time??

I need my dates to be in ISO format for use by another module, and so, am I SOL? We will have to load manually?

Thanks,

H

sharonknieper’s picture

hamish_s I'm working on a work around for my historical dates by writing a callback in the field mapping. If the value looks like a timestamp already MigrationBase::timestamp passes it along without processing with strtotime, so if you get the correct timestamp first I think it should be okay. This is what I did:

$this->addFieldMapping('field_death', 'Year')
 ->callbacks(array($this, 'preEpochDateProcessing'));

and

    protected function preEpochDateProcessing($date){
      $newdate = new DateTime($date);
      $date = $newdate->getTimestamp();
      return $date;
  }

I've only started testing so I'm not sure how well this will work, but I thought I'd share the idea of a callback.

sharonknieper’s picture

hamish_s realized you mentioned pre 1901 dates. In my testing it looks like the following adjustment to the above code would work:

replace

$date = $newdate->getTimestamp();

with

$date = $newdate->format("U");