You are here

public function FacetsDateHandler::isoDate in Facets 8

Converts dates from Unix timestamps into ISO 8601 format.

Parameters

int $timestamp: An integer containing the Unix timestamp being converted.

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

Return value

string A string containing the date in ISO 8601 format.

1 call to FacetsDateHandler::isoDate()
FacetsDateHandler::getNextDateIncrement in src/Utility/FacetsDateHandler.php
Returns the next increment from the given ISO date and gap.

File

src/Utility/FacetsDateHandler.php, line 91

Class

FacetsDateHandler
Dates Handler service.

Namespace

Drupal\facets\Utility

Code

public function isoDate($timestamp, $gap = 'SECOND') {
  switch ($gap) {
    case static::FACETS_DATE_SECOND:
      $format = static::FACETS_DATE_ISO8601;
      break;
    case static::FACETS_DATE_MINUTE:
      $format = 'Y-m-d\\TH:i:00\\Z';
      break;
    case static::FACETS_DATE_HOUR:
      $format = 'Y-m-d\\TH:00:00\\Z';
      break;
    case static::FACETS_DATE_DAY:
      $format = 'Y-m-d\\T00:00:00\\Z';
      break;
    case static::FACETS_DATE_MONTH:
      $format = 'Y-m-01\\T00:00:00\\Z';
      break;
    case static::FACETS_DATE_YEAR:
      $format = 'Y-01-01\\T00:00:00\\Z';
      break;
    default:
      $format = static::FACETS_DATE_ISO8601;
      break;
  }
  return gmdate($format, $timestamp);
}