You are here

protected static function SearchApiElasticsearchAbstractService::getDateGap in Search API Elasticsearch 7

Helper function. Return date gap from two dates or timestamps.

See also

facetapi_get_timestamp_gap()

1 call to SearchApiElasticsearchAbstractService::getDateGap()
SearchApiElasticsearchAbstractService::getDateGranularity in includes/SearchApiElasticsearchAbstractService.inc
Helper function to return date gap.

File

includes/SearchApiElasticsearchAbstractService.inc, line 506
Provides a Elasticsearch-based service class for the Search API.

Class

SearchApiElasticsearchAbstractService
Elasticsearch service abstract class.

Code

protected static function getDateGap($min, $max, $timestamp = TRUE) {
  if ($timestamp !== TRUE) {
    $min = strtotime($min);
    $max = strtotime($max);
  }
  if (empty($min) || empty($max)) {
    return 'DAY';
  }
  $diff = $max - $min;
  switch (TRUE) {
    case $diff > 86400 * 365:
      return 'NONE';
    case $diff > 86400 * gmdate('t', $min):
      return 'YEAR';
    case $diff > 86400:
      return 'MONTH';
    default:
      return 'DAY';
  }
}