You are here

function apachesolr_date_format_iso_by_gap in Apache Solr Search 5.2

Same name and namespace in other branches
  1. 6 apachesolr.module \apachesolr_date_format_iso_by_gap()
  2. 6.2 apachesolr.module \apachesolr_date_format_iso_by_gap()

Format an ISO date string based on the gap used to generate it.

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

$gap: A gap.

$iso: An ISO date string.

Return value

A gap-appropriate formatted date.

2 calls to apachesolr_date_format_iso_by_gap()
apachesolr_date_facet_block in ./apachesolr.module
Helper function for displaying a date facet block.
apachesolr_date_format_range in ./apachesolr.module
Format the beginning of a date range query filter that we generated.

File

./apachesolr.module, line 931
Integration with the Apache Solr search application.

Code

function apachesolr_date_format_iso_by_gap($gap, $iso) {

  // TODO: If we assume that multiple search queries are formatted in
  // order, we could store a static list of all gaps we've formatted.
  // Then, if we format an HOUR, MINUTE, or SECOND without previously
  // having formatted a DAY or later, we could include date
  // information.  However, we'd need to do that per-field and I'm not
  // our callers always have field information handy.
  $unix = strtotime($iso);
  if ($unix !== FALSE) {
    switch ($gap) {
      case 'YEAR':
        return format_date($unix, 'custom', 'Y', 0);
      case 'MONTH':
        return format_date($unix, 'custom', 'F Y', 0);
      case 'DAY':
        return format_date($unix, 'custom', 'F j, Y', 0);
      case 'HOUR':
        return format_date($unix, 'custom', 'g A', 0);
      case 'MINUTE':
        return format_date($unix, 'custom', 'g:i A', 0);
      case 'SECOND':
        return format_date($unix, 'custom', 'g:i:s A', 0);
    }
  }
  return $iso;
}