You are here

public function FacetsDateHandler::formatTimestamp in Facets 8

Returns a formatted date based on the passed timestamp and gap.

This function assumes that gaps less than one day will be displayed in a search context in which a larger containing gap including a day is already displayed. So, HOUR, MINUTE, and SECOND gaps only display time information, without date.

Parameters

int $timestamp: An integer containing the Unix timestamp.

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

Return value

string A gap-appropriate display date used in the facet link.

File

src/Utility/FacetsDateHandler.php, line 263

Class

FacetsDateHandler
Dates Handler service.

Namespace

Drupal\facets\Utility

Code

public function formatTimestamp($timestamp, $gap = self::FACETS_DATE_YEAR) {
  switch ($gap) {
    case static::FACETS_DATE_MONTH:
      return $this->dateFormatter
        ->format($timestamp, 'custom', 'F Y', 'UTC');
    case static::FACETS_DATE_DAY:
      return $this->dateFormatter
        ->format($timestamp, 'custom', 'F j, Y', 'UTC');
    case static::FACETS_DATE_HOUR:
      return $this->dateFormatter
        ->format($timestamp, 'custom', 'g A', 'UTC');
    case static::FACETS_DATE_MINUTE:
      return $this->dateFormatter
        ->format($timestamp, 'custom', 'g:i A', 'UTC');
    case static::FACETS_DATE_SECOND:
      return $this->dateFormatter
        ->format($timestamp, 'custom', 'g:i:s A', 'UTC');
    default:
      return $this->dateFormatter
        ->format($timestamp, 'custom', 'Y', 'UTC');
  }
}