You are here

protected static function SearchApiElasticsearchConnector::getDateGap in Elasticsearch Connector 7.2

Same name and namespace in other branches
  1. 7.5 modules/elasticsearch_connector_search_api/service.inc \SearchApiElasticsearchConnector::getDateGap()
  2. 7 modules/elasticsearch_connector_search_api/service.inc \SearchApiElasticsearchConnector::getDateGap()

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

See also

facetapi_get_timestamp_gap()

1 call to SearchApiElasticsearchConnector::getDateGap()
SearchApiElasticsearchConnector::getDateGranularity in modules/elasticsearch_connector_search_api/service.inc
Helper function to return date gap.

File

modules/elasticsearch_connector_search_api/service.inc, line 1114
Provides a Elasticsearch-based service class for the Search API using Elasticsearch Connector module.

Class

SearchApiElasticsearchConnector
Search service 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';
  }
}