You are here

function apachesolr_date_determine_gap in Apache Solr Search 5.2

Same name and namespace in other branches
  1. 6 apachesolr.module \apachesolr_date_determine_gap()
  2. 6.2 apachesolr.module \apachesolr_date_determine_gap()

Determine the best search gap to use for an arbitrary date range.

Generally, we the maximum gap that fits between the start and end date. If they are more than a year apart, 1 year; if they are more than a month apart, 1 month; etc.

This function uses Unix timestamps for its computation and so is not useful for dates outside that range.

Parameters

$start: Start date as an ISO date string.

$end: End date as an ISO date string.

Return value

YEAR, MONTH, DAY, HOUR, MINUTE, or SECOND depending on how far apart $start and $end are.

1 call to apachesolr_date_determine_gap()
apachesolr_search_date_range in ./apachesolr_search.module

File

./apachesolr.module, line 994
Integration with the Apache Solr search application.

Code

function apachesolr_date_determine_gap($start, $end) {
  $start = strtotime($start);
  $end = strtotime($end);
  if ($end - $start >= 86400 * 365) {
    return 'YEAR';
  }
  if (date('Ym', $start) != date('Ym', $end)) {
    return 'MONTH';
  }
  if ($end - $start > 86400) {
    return 'DAY';
  }

  // For now, HOUR is a reasonable smallest gap.
  return 'HOUR';
}