Problem/Motivation

After upgrade to 8.x-1.6 if I don't have the option selected to show the time this error is produced
TypeError: Drupal\date_ap_style\ApStyleDateFormatter::formatRange(): Return value must be of type string, null returned in Drupal\date_ap_style\ApStyleDateFormatter->formatRange() (line 293 of modules/contrib/date_ap_style/src/ApStyleDateFormatter.php).

Steps to reproduce

Have a date/time range field configured fill in data and have the formatter set to only show the date and not the time

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

Comments

emerham created an issue. See original summary.

shelane’s picture

StatusFileSize
new3.05 KB

Thanks for reporting this. I was able to replicate it with another case as all of these methods were given an updated signature with typing. In my case of a date that is not a date range date, this fix worked.

Can you test this patch?

shelane’s picture

Priority: Normal » Critical
emerham’s picture

Still getting the same error in the function formatRange.

I think there's an issue in the formatRange, intellephese is saying that $output on line 293 is "probably undefined". Checking the logic it looks like if I don't have the option of "Show time" checked that $output will never be set and thus is null and being returned as such

if (isset($options['display_time']) && $options['display_time']) {
        $date_output = $start_stamp->format($format_start_date);
        if (!empty($format_end_date)) {
          $date_output .= (isset($options['separator']) && $options['separator'] == 'endash' ? ' – ' : ' to ') . $end_stamp->format($format_end_date);
        }
        $time_output = $this->getTimeOutput($normalized_timestamps, $options, $fieldtype);
        if (!empty($time_output) && isset($options['time_before_date']) && $options['time_before_date']) {
          $output = $time_output . ', ' . $date_output;
        }
        elseif (!empty($time_output)) {
          $output = $date_output . ', ' . $time_output;
        }
        else {
          $output = $date_output;
        }
      }
      return $output;
emerham’s picture

StatusFileSize
new1.35 KB

I moved the if (isset($options['display_time']) && $options['display_time']) down 4 lines and added a new else statement to ensure that $output will have a value.

did some testing both showing and not showing the time date time range that is both same day and different days at different times.

  • shelane committed 92133ec9 on 8.x-1.x authored by emerham
    Issue #3387650 by emerham, shelane: TypeError in formatRange
    
kmonahan’s picture

Was just in the process of making a patch with the same change. :) Can confirm that #5 fixes the issue for me.

shelane’s picture

Status: Active » Fixed

Yep. That's it. Thank you very much!

Status: Fixed » Closed (fixed)

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