You are here

function feeds_to_unixtime in Feeds 7.2

Same name and namespace in other branches
  1. 8.2 feeds.module \feeds_to_unixtime()

Converts to UNIX time.

Parameters

$date: A date that is either a string, a FeedsDateTimeElement 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 plugins/FeedsNodeProcessor.inc
Override setTargetElement to operate on a target item that is a node.
FeedsUserProcessor::setTargetElement in plugins/FeedsUserProcessor.inc
Overrides setTargetElement() to operate on a target item that is an user.

File

plugins/FeedsParser.inc, line 929
Contains FeedsParser and related classes.

Code

function feeds_to_unixtime($date, $default_value) {
  if (is_numeric($date)) {
    return $date;
  }
  if ($date instanceof FeedsDateTimeElement) {
    return $date
      ->getValue();
  }
  if (is_string($date) || is_object($date) && method_exists($date, '__toString')) {
    if ($date_object = date_create(trim($date))) {
      return $date_object
        ->format('U');
    }
  }
  return $default_value;
}