1 date.class.inc public BackdropDateTime::validGranularity($granularity = NULL, $flexible = FALSE)

Determines if a a date is valid for a given granularity.

Parameters

array|null $granularity: An array of date parts. Defaults to NULL.

bool $flexible: TRUE if the granularity is flexible, FALSE otherwise. Defaults to FALSE.

Return value

bool: Whether a date is valid for a given granularity.

File

core/includes/date.class.inc, line 329

Class

BackdropDateTime
Extends PHP DateTime class for use with Backdrop.

Code

public function validGranularity($granularity = NULL, $flexible = FALSE) {
  $true = $this->hasGranularity() && (!$granularity || $flexible || $this->hasGranularity($granularity));
  if (!$true && $granularity) {
    foreach ((array) $granularity as $part) {
      if (!$this->hasGranularity($part) && in_array($part, array(
          'second',
          'minute',
          'hour',
          'day',
          'month',
          'year')
        )) {
        switch ($part) {
          case 'second':
            $this->errors[$part] = t('The second is missing.');
            break;

          case 'minute':
            $this->errors[$part] = t('The minute is missing.');
            break;

          case 'hour':
            $this->errors[$part] = t('The hour is missing.');
            break;

          case 'day':
            $this->errors[$part] = t('The day is missing.');
            break;

          case 'month':
            $this->errors[$part] = t('The month is missing.');
            break;

          case 'year':
            $this->errors[$part] = t('The year is missing.');
            break;
        }
      }
    }
  }
  return $true;
}