1 date.inc | date_granularity_array_from_precision($precision) |
Constructs an array of granularity based on a given precision.
Parameters
string $precision: A granularity item.
Return value
array: A granularity array containing the given precision and all those above it. For example, passing in 'month' will return array('year', 'month').
File
- core/
includes/ date.inc, line 500 - Date API functions.
Code
function date_granularity_array_from_precision($precision) {
$granularity_array = array('year', 'month', 'day', 'hour', 'minute', 'second');
switch ($precision) {
case 'year':
return array_slice($granularity_array, -6, 1);
case 'month':
return array_slice($granularity_array, -6, 2);
case 'day':
return array_slice($granularity_array, -6, 3);
case 'hour':
return array_slice($granularity_array, -6, 4);
case 'minute':
return array_slice($granularity_array, -6, 5);
default:
return $granularity_array;
}
}