1 date.module date_granularity($field)

Retrieves the granularity for a field.

$field['settings']['granularity'] will contain an array like ('hour' => 'hour', 'month' => 0) where the values turned on return their own names and the values turned off return a zero need to reconfigure this into simple array of the turned on values


array $field: The field array.


core/modules/date/date.module, line 428
Defines date/time field types.


function date_granularity($field) {
  if (!is_array($field) || !is_array($field['settings']['granularity'])) {
    $granularity = backdrop_map_assoc(array('year', 'month', 'day'));
    $field['settings']['granularity'] = $granularity;
  return array_values(array_filter($field['settings']['granularity']));