You are here

public static function MigrationBase::timestamp in Migrate 6.2

Same name and namespace in other branches
  1. 7.2 includes/base.inc \MigrationBase::timestamp()

Convert an incoming string (which may be a UNIX timestamp, or an arbitrarily-formatted date/time string) to a UNIX timestamp.

Parameters

string $value:

4 calls to MigrationBase::timestamp()
MigrateDestinationComment::import in plugins/destinations/comment.inc
Import a single comment.
MigrateDestinationNode::import in plugins/destinations/node.inc
Import a single node.
MigrateDestinationUser::import in plugins/destinations/user.inc
Import a single user.
MigrateProfileUserHandler::prepare in plugins/destinations/profile.inc

File

includes/base.inc, line 1007
Defines the base class for migration processes.

Class

MigrationBase
The base class for all objects representing distinct steps in a migration process. Most commonly these will be Migration objects which actually import data from a source into a Drupal destination, but by deriving classes directly from MigrationBase…

Code

public static function timestamp($value) {

  // Default empty values to now
  if (empty($value)) {
    return time();
  }

  // Does it look like it's already a timestamp? Just return it
  if (is_numeric($value)) {
    return $value;
  }
  $date = new DateTime($value);
  $time = $date
    ->format('U');
  if ($time == FALSE) {

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