You are here

function facetapi_get_next_date_gap in Facet API 7.2

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

Return a date gap one increment smaller than the one passed.

Parameters

$gap: A string containing the gap, see FACETAPI_DATE_* constants for valid values.

$min_gap: A string containing the the minimum gap that can be returned, defaults to FACETAPI_DATE_SECOND. This is useful for defining the smallest increment that can be used in a date drilldown.

Return value

A string containing the smaller date gap, NULL if there is no smaller gap. See FACETAPI_DATE_* constants for valid values.

File

./facetapi.date.inc, line 68
Date handling functions.

Code

function facetapi_get_next_date_gap($gap, $min_gap = FACETAPI_DATE_SECOND) {

  // Array of numbers used to determine whether the next gap is smaller than
  // the minimum gap allowed in the drilldown.
  $gap_numbers = array(
    FACETAPI_DATE_YEAR => 6,
    FACETAPI_DATE_MONTH => 5,
    FACETAPI_DATE_DAY => 4,
    FACETAPI_DATE_HOUR => 3,
    FACETAPI_DATE_MINUTE => 2,
    FACETAPI_DATE_SECOND => 1,
  );

  // Gets gap numbers for both the gap and minimum gap, checks if the next gap
  // is within the limit set by the $min_gap parameter.
  $gap_num = isset($gap_numbers[$gap]) ? $gap_numbers[$gap] : 6;
  $min_num = isset($gap_numbers[$min_gap]) ? $gap_numbers[$min_gap] : 1;
  return $gap_num > $min_num ? array_search($gap_num - 1, $gap_numbers) : $min_gap;
}