3

[UPDATE: RESOLVED ON MY OWN! YAY!] I've got a date range (start and end date) which I'm using to display a start and end time of an event. However, when the minutes are the same for the start and end time (with differing hours), the first time's minute digits are omitted. See the pic:

Date Range missing minutes

I've looked through the settings and I cannot, for the life of me, figure out how to show minutes when the minutes are the same. When I change it to be different minutes, it looks good:

Date Range with minutes

I'm sure it's some simple setting that I'm just missing, somewhere. But I've searched and googled and can't figure it out. Here's my configuration:

Time Setting

And here is that format:

Date & Time Format

Set to that date type:

Date Type

Seems fine everywhere.

Setting the field.

It's in military time--not sure how to get an AM/PM dropdown. Don't see any options for that, but I haven't really investigated that yet. But that's neither here nor there. I'm hiding the year, month, day in this Add Event form and just using a default value.

The only modules that affect this that I'm using are Date and Date API, as well as Panelizer to display it. I'm using a custom layout with panelizer, but that shouldn't matter.

I actually do have some code in the template.php file that alters a date range, but can't see, as of yet, why that'd be screwing things up:

// template.php    

function times_square_date_display_range($variables) {
  $date1 = $variables['date1'];
  $date2 = $variables['date2'];

  //if the same month, omit first num's month
  if (substr($date1, 2, -1) == substr($date2, 2, -1)) {
    $date1 = substr($date1, 0, 2);
  }
  $timezone = $variables['timezone'];
  $attributes_start = $variables['attributes_start'];
  $attributes_end = $variables['attributes_end'];
  $show_remaining_days = $variables['show_remaining_days'];

  $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.
  $output = '<div class="date-display-range">' . t('!start-date - !end-date', array(
    '!start-date' => $start_date,
    '!end-date' => $end_date,
  )) . '</div>';

  // Add remaining message and return.
  return $output . $show_remaining_days;
}

That's pretty much all the info I have about this.

[UPDATE: It is an error with the if statement at the top of the template.php code. I used this to alter the display of date ranges and had to qualify it more to only affect date ranges, not time ranges. Here's the code for the fix ( skip date outputs with ':' character):

if ( (substr($date1, 2, -1) == substr($date2, 2, -1)) && 
   ( strpos($date1, ':') !== true ) ) { 
  $date1 = substr($date1, 0, 2);
}

Can I give myself the bounty? :) ]

6
  • did you use custom node template file? I mean something like node--news.tpl.php if yes, add template to question.
    – Yuseferi
    Mar 24, 2017 at 22:48
  • I did, and will include that on monday, when i'm back at my work files. Thanks
    – ProGrammar
    Mar 25, 2017 at 21:38
  • 1
    Ok, we'll fix it, have a nice weekend ;)
    – Yuseferi
    Mar 25, 2017 at 21:42
  • Would be good to know what module(s) you are currently using (date? date_range_formatter?) Enjoy the rest of the weekend! Mar 26, 2017 at 10:07
  • 1
    @ProgrammingEqualsSuperpower you can post the answer as an answer (and mark it solved 2 days later). Not sure about the bounty. Mar 29, 2017 at 15:19

2 Answers 2

4
+50

Hope you are using core date module with end date. If you are, here is my field configuration in content type:

date range field configuration with custom format

Once have the field configured with custom date format, the display seems working as expected.

node with date range fields.

Let me know, if I missed configuration details here.

1
  • Even though this isn't the solution to my problem, I'm giving you the bounty because no one answered it and the bounty is just going to disappear.
    – ProGrammar
    Mar 31, 2017 at 21:44
0

It is an error with the if statement at the top of the template.php code. I used this to alter the display of date ranges and had to qualify it more to only affect date ranges, not time ranges. Here's the code for the fix ( skip date outputs with ':' character):

if ( (substr($date1, 2, -1) == substr($date2, 2, -1)) && 
   ( strpos($date1, ':') !== true ) ) { 
  $date1 = substr($date1, 0, 2);
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.