You are here

public function FacetsDateHandler::getNextDateIncrement in Facets 8

Returns the next increment from the given ISO date and gap.

This function is useful for getting the upper limit of a date range from the given start date.

Parameters

string $date: A string containing the date as an ISO date string.

string $gap: A string containing the gap, see FACETS_DATE_* constants for valid values, defaults to YEAR.

Return value

string A string containing the date, FALSE if the passed date could not be parsed.

File

src/Utility/FacetsDateHandler.php, line 323

Class

FacetsDateHandler
Dates Handler service.

Namespace

Drupal\facets\Utility

Code

public function getNextDateIncrement($date, $gap) {
  if (preg_match(static::FACETS_REGEX_DATE, $date, $match)) {

    // Increments the timestamp.
    switch ($gap) {
      case static::FACETS_DATE_MONTH:
        $match[2] += 1;
        break;
      case static::FACETS_DATE_DAY:
        $match[3] += 1;
        break;
      case static::FACETS_DATE_HOUR:
        $match[4] += 1;
        break;
      case static::FACETS_DATE_MINUTE:
        $match[5] += 1;
        break;
      case static::FACETS_DATE_SECOND:
        $match[6] += 1;
        break;
      default:
        $match[1] += 1;
        break;
    }

    // Gets the next increment.
    return $this
      ->isoDate(gmmktime($match[4], $match[5], $match[6], $match[2], $match[3], $match[1]));
  }
  return FALSE;
}