You are here

protected function DateTargetBase::convertToDate in Feeds 8.3

Prepares a date value.

Parameters

string $value: The value to convert to a date.

Return value

\Drupal\Core\Datetime\DrupalDateTime|null A datetime object or null, if there is no value or if the date value has errors.

2 calls to DateTargetBase::convertToDate()
DateTime::prepareDateValue in src/Feeds/Target/DateTime.php
Prepares a date value.
Timestamp::prepareValue in src/Feeds/Target/Timestamp.php
Prepares a single value.

File

src/Feeds/Target/DateTargetBase.php, line 25

Class

DateTargetBase
A base class for date targets.

Namespace

Drupal\feeds\Feeds\Target

Code

protected function convertToDate($value) {
  $value = trim($value);

  // This is a year value.
  if (ctype_digit($value) && strlen($value) === 4) {
    $value = 'January ' . $value;
  }
  if (is_numeric($value)) {
    $date = DrupalDateTime::createFromTimestamp($value, $this
      ->getTimezoneConfiguration());
  }
  elseif (strtotime($value)) {
    $date = new DrupalDateTime($value, $this
      ->getTimezoneConfiguration());
  }
  if (isset($date) && !$date
    ->hasErrors()) {
    return $date;
  }
}