I'm not sure if this is a bug or a support request, but I would like to be able to have the D7 field formatter show a single date instead of a range , but I can't work out how to do it. The display settings show "Display both From and To dates" in the format settings summary, but editing these settings gives me no option to show a single date.

And yes, I do have 'To Date:' set to 'Never'.

Comments

jrsinclair’s picture

In case anyone is looking for a quick fix for this issue. You can use a theme function in your template.php file to detect dates that start and end on the same day:

function MYTHEMENAME_date_display_range($vars) {
  $date1 = $vars['date1'];
  $date2 = $vars['date2'];
  $timezone = !empty($vars['timezone']) ? $vars['timezone'] : NULL;

  if ( date('Y-m-d', strtotime($date1)) == date('Y-m-d', strtotime($date2)) ) {
    return '<span class="date-display-start">' . $date1 . $timezone . '</span>';
  }
  else {
    return '<span class="date-display-start">' . $date1 . '</span>' .
           '<span class="date-display-separator"> - </span>' .
           '<span class="date-display-end">' . $date2 . $timezone. '</span>';

  }
}

It makes the assumption that you don't care about times, which I don't in this instance.

It would be nice to detect the granularity of the date field and respond accordingly (i.e. if granularity includes times, then show the range, otherwise just show the date). However, since the theme function doesn't have that information, we're stuck with a blanket override.

karens’s picture

Status: Active » Fixed

You will not see any options if you have a to date set to 'never'. In that case you always only see a single date. The only bug here is that the settings summary says you are seeing both from and to dates, when you are only seeing a single date. I just committed a fix for that.

With or without that you are only seeing a single field.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.