function facetapi_timestamp_gap_get in Facet API 6
Determines the best search gap to use for an arbitrary date range.
Generally, we use 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_date: A string containing the start date as an ISO date string.
$end_date: A string containing the end date as an ISO date string.
Return value
A string containing the gap, see FACETAPI_DATE_* constants for valid values. Returns FALSE of either of the dates cannot be converted to a timestamp.
3 calls to facetapi_timestamp_gap_get()
- FacetapiLuceneapiAdapter::fetchDate in contrib/
facetapi_luceneapi/ facetapi_luceneapi.adapter.inc - Fetches data from facets that filter results by date ranges.
- facetapi_apachesolr_date_range in contrib/
facetapi_apachesolr/ facetapi_apachesolr.module - Gets the range of dates we are using.
- facetapi_date_gap_get in ./
facetapi.module - Converts ISO date strings to Unix timestamps, passes values to the facetapi_timestamp_gap_get() function to calculate the gap.
File
- ./
facetapi.module, line 1146 - An abstracted facet API that can be used by various search backens.
Code
function facetapi_timestamp_gap_get($start_time, $end_time) {
$time_diff = $end_time - $start_time;
switch (TRUE) {
// NOTE: 86400365 == 60 * 60 * 24 * 365
case $time_diff >= 86400365:
return FACETAPI_DATE_YEAR;
case date('Ym', $start_time) != date('Ym', $end_time):
return FACETAPI_DATE_MONTH;
case $time_diff >= 86400:
return FACETAPI_DATE_DAY;
case $time_diff >= 3600:
return FACETAPI_DATE_HOUR;
case $time_diff >= 60:
return FACETAPI_DATE_MINUTE;
default:
return FACETAPI_DATE_SECOND;
}
}