1 date.class.inc | protected BackdropDateTime::setGranularityFromTime($time, $tz) |
Determines the granularity of a date based on the constructor's arguments.
Parameters
string $time: A date string.
bool $tz: TRUE if the date has a timezone, FALSE otherwise.
File
- core/
includes/ date.class.inc, line 408
Class
- BackdropDateTime
- Extends PHP DateTime class for use with Backdrop.
Code
protected function setGranularityFromTime($time, $tz) {
$this->granularity = array();
$temp = date_parse($time);
// Special case for 'now'.
if ($time == 'now') {
$this->granularity = array(
'year',
'month',
'day',
'hour',
'minute',
'second',
);
}
else {
// This PHP date_parse() method currently doesn't have resolution down to
// seconds, so if there is some time, all will be set.
foreach (self::$allgranularity as $g) {
if ((isset($temp[$g]) && is_numeric($temp[$g])) || ($g == 'timezone' && (isset($temp['zone_type']) && $temp['zone_type'] > 0))) {
$this->granularity[] = $g;
}
}
}
if ($tz) {
$this->addGranularity('timezone');
}
}