You are here

function feeds_to_unixtime in Feeds 8.2

Same name and namespace in other branches
  1. 7.2 plugins/FeedsParser.inc \feeds_to_unixtime()

Converts to UNIX time.

Parameters

$date: A date that is either a string, a DrupalDateTime or a UNIX timestamp.

$default_value: A default UNIX timestamp to return if $date could not be parsed.

Return value

$date as UNIX time if conversion was successful, $dfeault_value otherwise.

2 calls to feeds_to_unixtime()
FeedsNodeProcessor::setTargetElement in lib/Drupal/feeds/Plugin/feeds/processor/FeedsNodeProcessor.php
Override setTargetElement to operate on a target item that is a node.
FeedsUserProcessor::setTargetElement in lib/Drupal/feeds/Plugin/feeds/processor/FeedsUserProcessor.php
Override setTargetElement to operate on a target item that is a node.

File

./feeds.module, line 1213
Feeds - basic API functions and hook implementations.

Code

function feeds_to_unixtime($date, $default_value) {
  if (is_numeric($date)) {
    return $date;
  }
  elseif (is_string($date) && !empty($date)) {
    $date = new DrupalDateTime($date);
    return $date
      ->format('U');
  }
  elseif ($date instanceof DrupalDateTime) {
    return $date
      ->format('U');
  }
  return $default_value;
}