protected static function SearchApiElasticsearchBackend::getDateGap in Elasticsearch Connector 8.5
Same name and namespace in other branches
- 8.7 src/Plugin/search_api/backend/SearchApiElasticsearchBackend.php \Drupal\elasticsearch_connector\Plugin\search_api\backend\SearchApiElasticsearchBackend::getDateGap()
- 8 src/Plugin/search_api/backend/SearchApiElasticsearchBackend.php \Drupal\elasticsearch_connector\Plugin\search_api\backend\SearchApiElasticsearchBackend::getDateGap()
- 8.2 src/Plugin/search_api/backend/SearchApiElasticsearchBackend.php \Drupal\elasticsearch_connector\Plugin\search_api\backend\SearchApiElasticsearchBackend::getDateGap()
- 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
mixed $min: Start date or timestamp.
mixed $max: End date or timestamp.
bool $timestamp: TRUE if the first two params are timestamps, FALSE otherwise. In the case of FALSE, it's assumed the first two arguments are strings and they are converted to timestamps using strtotime().
Return value
string One of 'NONE', 'YEAR', 'MONTH', or 'DAY' depending on the difference
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 801
Class
- SearchApiElasticsearchBackend
- Elasticsearch Search API Backend definition.
Namespace
Drupal\elasticsearch_connector\Plugin\search_api\backendCode
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';
}
}