You are here

function _migrate_valid_date in Migrate 6

Check if a date is valid and return the correct timestamp to use. Returns -1 if the date is not considered valid.

3 calls to _migrate_valid_date()
comment_migrate_import_comment in modules/comment.migrate.inc
Implementation of hook_migrate_import_comment().
node_migrate_import_node in modules/node.migrate.inc
Implementation of hook_migrate_import_node().
user_migrate_import_user in modules/user.migrate.inc
Implementation of hook_migrate_import_user().

File

./migrate.module, line 1469
This module provides tools at "administer >> content >> migrate" for analyzing data from various sources and importing them into Drupal tables.

Code

function _migrate_valid_date($date) {
  if (empty($date)) {
    return -1;
  }
  if (is_numeric($date) && $date > -1) {
    return $date;
  }

  // strtotime() doesn't recognize dashes as separators, change to slashes
  $date = str_replace('-', '/', $date);
  $time = strtotime($date);
  if ($time < 0 || !$time) {

    // Handles form YYYY-MM-DD HH:MM:SS.garbage
    if (drupal_strlen($date) > 19) {
      $time = strtotime(drupal_substr($date, 0, 19));
      if ($time < 0 || !$time) {
        return -1;
      }
    }
  }
  return $time;
}