_social_event_format_date in social event has a conditional that will never run, meaning that events on the same date will never show an end time

Created on 8 February 2024, 5 months ago

Problem/Motivation

There is a section at the end of _social_event_format_date that checks whether the dates are the same to determine how to format the date. There is a logic error in the code that causes the end time of events to never be shown if the dates are the same.

Here is the bare conditional structure with the conditionals themselves stripped out, and the comments included to show the logic error

    // Date are the same or there are no end date.
    if () {
      
    }
    // The date is the same, the time is different.
    elseif () {
      
    }
    // They are not the same day (or empty?).
    else {
      
    }

If you check that the dates are the same, and then elseif against the dates being the same, but times being different, you'll never reach that block of code in the elseif

I recommend refactoring that block from

    // Date are the same or there are no end date.
    if ($end_datetime === NULL || $start_datetime == $end_datetime || $start_date == $end_date) {
      $event_date = empty($start_time) ? $start_date : "$start_date $start_time";
    }
    // The date is the same, the time is different.
    elseif (date(DateTimeItemInterface::DATE_STORAGE_FORMAT, $start_datetime) == date(DateTimeItemInterface::DATE_STORAGE_FORMAT, $end_datetime)) {
      $event_date = "$start_date $start_time - $end_time";
    }
    // They are not the same day (or empty?).
    else {
      $event_date = "$start_date $start_time - $end_date $end_time";
    }

to

    // Date are the same or there are no end date.
    if ($end_datetime === NULL || $start_datetime == $end_datetime || $start_date == $end_date) {
      if (date(DateTimeItemInterface::DATE_STORAGE_FORMAT, $start_datetime) == date(DateTimeItemInterface::DATE_STORAGE_FORMAT, $end_datetime)) {
        // The date is the same, the time is different.
        $event_date = "$start_date $start_time - $end_time";
      } else {
        // No End date, or the date and time are the same.
        $event_date = empty($start_time) ? $start_date : "$start_date $start_time";
      }
    }
    // They are not the same day (or empty?).
    else {
      $event_date = "$start_date $start_time - $end_date $end_time";
    }
πŸ› Bug report
Status

Active

Version

12.1

Component

Code (back-end)

Created by

πŸ‡―πŸ‡΅Japan ultrabob Japan

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.69.0 2024