You are here

function facetapi_map_date in Facet API 7.2

Same name and namespace in other branches
  1. 6.3 facetapi.callbacks.inc \facetapi_map_date()
  2. 7 facetapi.callbacks.inc \facetapi_map_date()

Maps date ranges to human readable dates.

Parameters

array $values: An array of indexed values being mapped.

array $options: An associative array of map options containing:

  • format callback: The callback used to format the date, defaults to "facetapi_format_timestamp".

Return value

array An array mapping the indexed values to human readable values.

1 string reference to 'facetapi_map_date'
facetapi_facetapi_facet_info in ./facetapi.facetapi.inc
Implements hook_facetapi_facet_info().

File

./facetapi.callbacks.inc, line 79
Callbacks referenced in hook implementations.

Code

function facetapi_map_date(array $values, array $options) {
  if (empty($options['format callback'])) {
    $options['format callback'] = 'facetapi_format_timestamp';
  }
  $map = array();
  foreach ($values as $value) {
    $range = explode(' TO ', trim($value, '{[]}'));
    if (isset($range[1])) {
      $gap = facetapi_get_date_gap($range[0], $range[1]);
      $map[$value] = facetapi_format_date($range[0], $gap, $options['format callback']);
    }
  }
  return $map;
}