You are here

public static function TimestampHelper::isInterval in Node expire 7.2

Check is the string an interval.

2 calls to TimestampHelper::isInterval()
TimestampUtils::dateStrFromCfgDefault in src/Module/Utils/TimestampUtils.php
Makes date string from default config value for node type.
TimestampUtils::dateStrToCfgDefault in src/Module/Utils/TimestampUtils.php
Converts date string to timestamp int.

File

src/Module/CommonExpire/Conversion/TimestampHelper.php, line 65
TimestampHelper class.

Class

TimestampHelper
TimestampHelper class.

Namespace

Drupal\node_expire\Module\CommonExpire\Conversion

Code

public static function isInterval($str) {
  $str1 = trim($str);
  if (empty($str1)) {
    return FALSE;
  }
  $str2 = substr($str1, 0, 1);
  if ($str2 == '+' || $str2 == '-') {

    // Continue.
  }
  else {
    return FALSE;
  }

  // Try if string is an interval.
  $dt = new \DateTime();
  $dt
    ->modify($str1);
  if (!$dt) {
    return FALSE;
  }
  else {
    return TRUE;
  }
}