You are here

public function FacetsDateHandler::gapCompare in Facets 8

Compares two timestamp gaps.

Parameters

int $gap1: An integer containing the gap, see FACETS_DATE_* constants for valid values.

int $gap2: An integer containing the gap, see FACETS_DATE_* constants for valid values.

Return value

int Returns -1 if gap1 is less than gap2, 1 if gap1 is greater than gap2, and 0 if they are equal.

1 call to FacetsDateHandler::gapCompare()
FacetsDateHandler::getTimestampGap in src/Utility/FacetsDateHandler.php
Determines the best search gap to use for an arbitrary date range.

File

src/Utility/FacetsDateHandler.php, line 376

Class

FacetsDateHandler
Dates Handler service.

Namespace

Drupal\facets\Utility

Code

public function gapCompare($gap1, $gap2) {
  $gap_numbers = [
    static::FACETS_DATE_YEAR => 6,
    static::FACETS_DATE_MONTH => 5,
    static::FACETS_DATE_DAY => 4,
    static::FACETS_DATE_HOUR => 3,
    static::FACETS_DATE_MINUTE => 2,
    static::FACETS_DATE_SECOND => 1,
  ];
  $gap1_num = isset($gap_numbers[$gap1]) ? $gap_numbers[$gap1] : 6;
  $gap2_num = isset($gap_numbers[$gap2]) ? $gap_numbers[$gap2] : 6;
  if ($gap1_num == $gap2_num) {
    return 0;
  }
  else {
    return $gap1_num < $gap2_num ? -1 : 1;
  }
}