public function DateGranularity::validGranularity in Date 8
Determines if 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 granuliarty is flexible, FALSE otherwise. Defaults to FALSE.
Return value
bool Whether a date is valid for a given granularity.
File
- date_api/
lib/ Drupal/ date_api/ DateGranularity.php, line 144 - Definition of DateGranularity.
Class
- DateGranularity
- This class manages granularity. It can set granularity, get it from an array, get it from a format string, see if the array has any time or date elements, set and unset various granularity parts, create a nongranularity array of the granularity parts…
Namespace
Drupal\date_apiCode
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)) {
$this->errors[$part] = t("The @part is missing.", array(
'@part' => $part,
));
}
}
}
return $true;
}