I purpose we need to make the date range separator (currently 'to') more dynamic. I had to go into date.theme and change this to a dash. I will have to redo this every time the module updates now.

Here is what I purpose. A new field found at '/admin/config/regional/date-time/formats/[format_id]/edit' that allows user input. That way each format that is applied can have a unique separator? If I get some free time this week I can look into building this but I want to make sure this commit could work its way into the Date module or if I should create an additional module to tie into Date for this functionality. Seems pretty universal to me.

Comments

HeathN’s picture

pacome’s picture

Hello,

a simple solution is to copy the date_display_range function from date.theme to your theme template.php,
then rename with your theme name, and change the separator as you like :

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

  $start_date = '<span class="date-display-start"' . drupal_attributes($attributes_start) . '>' . $date1 . '</span>';
  $end_date = '<span class="date-display-end"' . drupal_attributes($attributes_end) . '>' . $date2 . $timezone . '</span>';

  // If microdata attributes for the start date property have been passed in,
  // add the microdata in meta tags.
  if (!empty($variables['add_microdata'])) {
    $start_date .= '<meta' . drupal_attributes($variables['microdata']['value']['#attributes']) . '/>';
    $end_date .= '<meta' . drupal_attributes($variables['microdata']['value2']['#attributes']) . '/>';
  }

  // Wrap the result with the attributes.
  return t('!start-date PUT YOUR OWN SPERATOR HERE !end-date', array(
    '!start-date' => $start_date,
    '!end-date' => $end_date,
  ));
}

(do not forget to flush all your cache ;)

This way you are not going to have any trouble while updating modules and so..

regards
P-

miromarchi’s picture

Thanks, copying date_display_range function in my theme template.php worked perfectly! Now I can update date module without loosing my start - end date separator customization.
Thanks

maxplus’s picture

Thanks,
#2 helped me out, I also added a div around my separator this way, handy for styling!

Taliesin84’s picture

Hi there, and I hope someone sees this.

I tested pacome's solution and it works great, but I need to apply it to a specific content type I created.
I have no idea where to start, and I want to learn how to do this.

Can I get a few pointers?

Thanks a bunch