public static function DateGranularity::arrayFromPrecision in Date 8
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').
2 calls to DateGranularity::arrayFromPrecision()
- DateTimezoneTest::testTimezone in lib/
Drupal/ date/ Tests/ DateTimezoneTest.php - @todo.
- DateTimezoneTest::testTimezone in date_field/
lib/ Drupal/ date_field/ Tests/ DateTimezoneTest.php - @todo.
File
- date_api/
lib/ Drupal/ date_api/ DateGranularity.php, line 214 - 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 static function arrayFromPrecision($precision) {
$granularity_array = self::$granularity_parts;
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;
}
}