function apachesolr_date_determine_gap in Apache Solr Search 6
Same name and namespace in other branches
- 5.2 apachesolr.module \apachesolr_date_determine_gap()
- 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()
File
- ./apachesolr.module, line 1116 
- 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';
  }
  return 'HOUR';
}