Currently the punctuation characters that are stripped out by date_limit_format() are hard-coded. It would be nice if it could be configured somehow, as now people who want to use some exotic punctuation characters (like the bullet point •) experience problems with those characters added at the end of days (because the limited format for timezone still contains some of those bullet points while they were only serving as a separator between day, month and year).

A temporary solution I applied on our project, was to change a small part of the code in date_limit_format so bullet points are considered to be punctuation signs:

// Remove orphaned punctuation at the beginning of the string.
$format = preg_replace('`^([\-/\.,:•\'])`u', '', $format);
// Remove orphaned punctuation at the end of the string.
$format = preg_replace('([\-/\.,:•\']$)u', '', $format);

Note that the unicode modifier is used.

Comments

dg0yt’s picture

I use short dates formatted like "Fr 31.03.". date_limit_format removes the trailing dot (resulting in "Fr 31.03"). but the dot is a neccessary part of this particular date style. Since nothing else is removed from the that particular date format ("D d.m."), punctuation shall not be touched at all IMHO. Configuration would be a workaround.

kla2t’s picture

I team up with dg0yt that the global removal of punctuation at the end of date strings is an unnecessary limitation, and unfortunately it is still there in the latest 7.x version. For example, it is common usage in german to show "from and to" dates falling into the same year as 11.03.-09.04.2011. But since date_limit_format() is neither themeable nor configurable, one cannot deliver this format without patching or hacking date_api.module.

Does the removal of 'orphaned' punctuation do anything but correcting wrong user entries at the date configuration? If not, it would be much better to let users live with their errors than forcing out well-formed date formats!

Anonymous’s picture

subscribe.

Any workaround?

kla2t’s picture

For anyone still interested in this issue, here comes a theme function as a quick solution to the "from - to" problem (removing duplicate years in date ranges without affecting the punctuation):

function MYTHEME_date_display_range($variables) {
  $date1 = $variables['date1'];
  $date2 = $variables['date2'];
  $timezone = $variables['timezone'];
  $start = $variables['attributes_start'];
  $end = $variables['attributes_end'];

  // If start and end year are identical, remove start year
  $date_format = $variables['dates']['format'];
  if (strpos($date_format, 'Y') || strpos($date_format, 'y') || strpos($date_format, 'o')) { // Check if the given date format contains a year variable
    $start_array = explode('-', $start['content']);
    $end_array = explode('-', $end['content']);
    $start_year = $start_array[0];
    $end_year = $end_array[0];
    if ($start_year === $end_year) {
      $date1 = trim(str_replace($start_year, '', $date1));
    }
  }
	
  // Enter your custom date range separator
  $separator = '–';
  
  // Wrap the result with the attributes.
  return t('!start-date!separator!end-date', array(
    '!start-date' => '<span class="date-display-start"' . drupal_attributes($start) . '>' . $date1 . '</span>', 
    '!separator' => '<span class="date-display-separator">' . $separator . '</span>', 
    '!end-date' => '<span class="date-display-end"' . drupal_attributes($end) . '>' . $date2 . $timezone . '</span>',
  ));
}

What it does: First, it checks if the given date format contains a year variable (Y, y or o) at all. Next, it compares the unformatted start and end dates. And then, if start and end year have been proven as identical, it removes the start year simply by replacing it with an empty string.
(Besides, the default separator "to" can be replaced with a custom string.)
Note: For certain date formats, like 2013/03/29, this will cause strange results ('/03/29'), but it's a snap to adapt the function to other date types.

damienmckenna’s picture

Issue summary: View changes
Status: Active » Closed (won't fix)

Unfortunately the Drupal 6 version of the Date module is no longer supported. That said, we appreciate that you took time to work on this issue. Should this request still be relevant for Drupal 7 please feel free to reopen it. Thank you.