You are here

private static function TimestampUtils::stringToTimestampAdvConfig in Node expire 7.2

Converts string to timestamp with interval option checking.

File

src/Module/Utils/TimestampUtils.php, line 192
TimestampUtils class.

Class

TimestampUtils
TimestampUtils class.

Namespace

Drupal\node_expire\Module\Utils

Code

private static function stringToTimestampAdvConfig($format, $str) {
  $dt = \DateTime::createFromFormat('!' . $format, $str);
  if (!$dt) {

    // Try if string is an interval.
    $dt = new \DateTime();
    $dt
      ->modify($str);
    if (!$dt) {
      throw new ExpireException(t('Wrong datetime/interval string.'));
    }
    else {
      return $str;
    }
  }
  $timestamp = $dt
    ->getTimestamp();
  return $timestamp;
}