1 date.class.inc | public BackdropDateTime::hasGranularity($g = NULL) |
Checks granularity array for a given entry.
@returns bool TRUE if the date part is present in the date's granularity.
Parameters
array|null $g: An array of date parts. Defaults to NULL.
File
- core/
includes/ date.class.inc, line 291
Class
- BackdropDateTime
- Extends PHP DateTime class for use with Backdrop.
Code
public function hasGranularity($g = NULL) {
if ($g === NULL) {
// Just want to know if it has something valid means no lower
// granularities without higher ones.
$last = TRUE;
foreach (self::$allgranularity as $arg) {
if ($arg == 'timezone') {
continue;
}
if (in_array($arg, $this->granularity) && !$last) {
return FALSE;
}
$last = in_array($arg, $this->granularity);
}
return in_array('year', $this->granularity);
}
if (is_array($g)) {
foreach ($g as $gran) {
if (!in_array($gran, $this->granularity)) {
return FALSE;
}
}
return TRUE;
}
return in_array($g, $this->granularity);
}