You are here

function date_granularity_array_from_precision in Date 7.2

Same name and namespace in other branches
  1. 6.2 date_api.module \date_granularity_array_from_precision()
  2. 7.3 date_api/date_api.module \date_granularity_array_from_precision()
  3. 7 date_api/date_api.module \date_granularity_array_from_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').

1 call to date_granularity_array_from_precision()
DateTimezoneTestCase::testTimezone in tests/DateTimezoneTestCase.test
Create a date fields, combining various timezones and granularity.

File

date_api/date_api.module, line 1627
This module will make the date API available to other modules.

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;
  }
}