You are here

public static function TimestampUtils::dateStrFromCfgDefault in Node expire 7.2

Makes date string from default config value for node type.

If used for Node Type, interval string is accepted as output and $return_intervals = TRUE.

If used for Node, interval string is converted to real DateTime string and $return_intervals = FALSE.

NODE_EXPIRE_NO_EXPIRE and '' are used as special values. Intervals are accepted as well.

3 calls to TimestampUtils::dateStrFromCfgDefault()
FormHookHandler::hookFormNodeTypeFormAlter in src/Module/Hook/FormHookHandler.php
Implements hook_form_node_type_form_alter().
NodeHookHandler::doNodePrepare in src/Module/Hook/NodeHookHandler.php
Implements hook_node_prepare().
TimestampUtils::dateDbToStr in src/Module/Utils/TimestampUtils.php
Convert timestamp int to date string.

File

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

Class

TimestampUtils
TimestampUtils class.

Namespace

Drupal\node_expire\Module\Utils

Code

public static function dateStrFromCfgDefault($default, $return_intervals = TRUE) {
  if (!isset($default)) {
    $date_out = '';
    return $date_out;
  }
  $default1 = trim($default);
  if (empty($default1)) {
    $date_out = '';
  }
  elseif (TimestampHelper::isInterval($default)) {
    if ($return_intervals) {

      // Return as interval string - for Node Type.
      $date_out = $default;
    }
    else {

      // Convert to DateTime string - for Node.
      $timestamp = TimestampHelper::stringIntervalToTimestamp($default);
      $date_out = self::timestampToStr($timestamp);
    }
  }
  elseif (is_int($default)) {

    // It is timestamp, handle it.
    $date_out = self::timestampToStr($default);
  }
  else {

    // Maybe legacy string from old version.
    try {
      $format = 'Y-m-d';
      $timestamp = TimestampHelper::stringToTimestamp($format, $default);
      $date_out = self::timestampToStr($timestamp);
    } catch (\Exception $e) {
      $date_out = '';
    }
  }
  return $date_out;
}