You are here

function facetapi_isodate in Facet API 6

Same name and namespace in other branches
  1. 6.3 facetapi.date.inc \facetapi_isodate()
  2. 7.2 facetapi.date.inc \facetapi_isodate()
  3. 7 facetapi.date.inc \facetapi_isodate()

Helper function to convert dates from Unix timestamps into ISO 8601 format.

Parameters

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

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

Return value

A string containing the date in ISO 8601 format.

3 calls to facetapi_isodate()
facetapi_apachesolr_date_range in contrib/facetapi_apachesolr/facetapi_apachesolr.module
Gets the range of dates we are using.
facetapi_luceneapi_timestamp_convert in contrib/facetapi_luceneapi/facetapi_luceneapi.module
Converts all timestamps in an array to dates in ISO 8601 format.
facetapi_next_date_increment_get in ./facetapi.module
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.

File

./facetapi.module, line 1053
An abstracted facet API that can be used by various search backens.

Code

function facetapi_isodate($timestamp, $gap = FACETAPI_DATE_SECOND) {
  switch ($gap) {
    case FACETAPI_DATE_SECOND:
      $format = FACETAPI_DATE_ISO8601;
      break;
    case FACETAPI_DATE_MINUTE:
      $format = 'Y-m-d\\TH:i:00\\Z';
      break;
    case FACETAPI_DATE_HOUR:
      $format = 'Y-m-d\\TH:00:00\\Z';
      break;
    case FACETAPI_DATE_DAY:
      $format = 'Y-m-d\\T00:00:00\\Z';
      break;
    case FACETAPI_DATE_MONTH:
      $format = 'Y-m-01\\T00:00:00\\Z';
      break;
    case FACETAPI_DATE_YEAR:
      $format = 'Y-01-01\\T00:00:00\\Z';
      break;
    default:
      $format = FACETAPI_DATE_ISO8601;
      break;
  }
  return gmdate($format, $timestamp);
}