You are here

protected static function SearchApiElasticsearchBackend::getDateGap in Elasticsearch Connector 8.2

Same name and namespace in other branches
  1. 8.7 src/Plugin/search_api/backend/SearchApiElasticsearchBackend.php \Drupal\elasticsearch_connector\Plugin\search_api\backend\SearchApiElasticsearchBackend::getDateGap()
  2. 8 src/Plugin/search_api/backend/SearchApiElasticsearchBackend.php \Drupal\elasticsearch_connector\Plugin\search_api\backend\SearchApiElasticsearchBackend::getDateGap()
  3. 8.5 src/Plugin/search_api/backend/SearchApiElasticsearchBackend.php \Drupal\elasticsearch_connector\Plugin\search_api\backend\SearchApiElasticsearchBackend::getDateGap()
  4. 8.6 src/Plugin/search_api/backend/SearchApiElasticsearchBackend.php \Drupal\elasticsearch_connector\Plugin\search_api\backend\SearchApiElasticsearchBackend::getDateGap()

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

Parameters

int $min:

int $max:

bool $timestamp:

Return value

string

See also

facetapi_get_timestamp_gap()

1 call to SearchApiElasticsearchBackend::getDateGap()
SearchApiElasticsearchBackend::getDateGranularity in src/Plugin/search_api/backend/SearchApiElasticsearchBackend.php
Helper function to return date gap.

File

src/Plugin/search_api/backend/SearchApiElasticsearchBackend.php, line 488
Contains the SearchApiElasticsearchBackend object.

Class

SearchApiElasticsearchBackend
Plugin annotation @SearchApiBackend( id = "elasticsearch", label = @Translation("Elasticsearch"), description = @Translation("Index items using an Elasticsearch server.") )

Namespace

Drupal\elasticsearch_connector\Plugin\search_api\backend

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';
  }
}