Problem/Motivation

When an Optional End Date field is configured to display only the end date and the end date is absent, the module displays the start date instead of leaving the field blank. This issue prevents us from utilizing the module as intended.

Steps to reproduce

1. Add the Optional End Date field to a content type.
2. Configure the field to display only the end date.
3. Create a new node, leaving the end date empty.
4. Observe that when the end date is missing, the start date is displayed. The expected behavior is for the field to remain empty.

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

torfj created an issue. See original summary.

torfj’s picture

Issue summary: View changes
torfj’s picture

Issue summary: View changes

torfj’s picture

Status: Active » Needs review

To resolve this, I added an additional check in the viewElements method to ensure that the start date is not displayed when the end date is absent and the field is configured to display only the end date.
I have created a merge request with the changes. The fix seems to work as expected in my tests now.

Please review the merge request and let me know your thoughts.
Thank you!

torfj’s picture

Updated the code to use the startDateIsDisplayed core function to check if the start date should be displayed.

danyg’s picture

If somebody faces the similar issue but with 8.x-1.4 version, here is the improved patch that resolve this issue.
The current MR's changes don't resolve the issue properly, doesn't take account into the display settings

  • birk committed d07d94e9 on 8.x-1.x
    Issue #3484716 by danyg: End Date Field Displays Start Date When Left...
birk’s picture

Status: Needs review » Fixed

I've committed patch #7 to branch 8, thank you for the work.
Should also fix #3540051: Changing date display does nothing (haven't tested).

Status: Fixed » Closed (fixed)

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

birk’s picture

I'm sorry I haven't moved on this yet.

I was just about to make a new release when I realized this might break optional end date on earlier Drupal versions.

Some of the functions was first added in #2827055: Add option to show only start or end date in the DateTime Range custom formatter, which is Drupal 10.3, so for installations before that it would not work.

When I get some extra time I'll investigate a bit more.
But I think I'll end rolling this back, and then the best thing would be to update to optional end date 2 to get this feature, since it's already ^10.3.