I have a site where there is only Month/Day/Year being captured in a field and no Time.
The module breaks when the same Month, Day, Year (no time) is used for the start and end date.
I believe this is because the 'single' setting was taken out, but is still being called in DateRangeFormatterRangeFormatter.php on line 80 to set the $single_format variable. This variable which is now empty is passed to the t() in line 81. Results in any page that displays the formatter to break.
It works if you change the getSetting to "one_day"
Old
$single_format = $this->getSetting('single');
$elements[$delta] = ['#markup' => \Drupal::service('date.formatter')->format($start_date, 'custom', t($single_format))];
New
$single_format = $this->getSetting('one_day');
$elements[$delta] = ['#markup' => \Drupal::service('date.formatter')->format($start_date, 'custom', t($single_format))];
I would submit a patch, but for some reason I'm having a hard time publishing it to Drupal.org. Maybe someone wants to test this out and submit a patch?
| Comment | File | Size | Author |
|---|---|---|---|
| #38 | date_range_formatter_daterange_issue.patch | 1.34 KB | rahul_ |
| #35 | 3309324-35.patch | 6.09 KB | norman.lol |
| #32 | date_range_formatter_3309324_#31.patch | 1.63 KB | sea2709 |
| #30 | date_range_formatter_3309324_#30.patch | 850 bytes | bachbach |
| #22 | 8.diff | 981 bytes | nigelcunningham |
Issue fork date_range_formatter-3309324
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
Comment #2
nicholassI am also getting this error after updating the module from
My Error is similar
Comment #3
nicholassComment #4
nicholassSo even after running database updates the error persists, so I will go ahead can create a patch as you suggested. Since changing line 80
$this->getSetting('one_day');seems to work.Comment #6
nicholassChanging this to needs review as it works now on my local and all my views using date ranges appear to be working normally.
Comment #7
nicholassComment #8
davidiio commentedWe ha the same problem described in #2 and we've changed
$single_format = $this->getSetting('single');to
$single_format = $this->getSetting('one_day');And it seems to solve the probleme. Date range is displayed properly without error in dblog.
Thanks :)
Comment #9
nickdickinsonwildeComment #10
vlyalko commentedComment #11
kenrbnsn commentedThis doesn't seem to fix the formatting problem.
I patched v4.0.1 with the patch.
Here is my test record -- see the file "Date and time - no end date.jpg"
Here's how it's displayed -- see the file "Date and time - no end date display.jpg"
Comment #12
bapi_22 commented@here the patch is applying correctly with 4.0.2 version.
Uploading a clean patch
Comment #13
bapi_22 commentedComment #14
tobiasbfyi: The format single, single_all_day was removed via #2947426: Rename "Date range (without time)" formatter, the settings form for single, single_all_day was added again via #3151725: t() calls should be avoided in classes.
Comment #16
taraskorpachI've rebased the commits from the latest release.
The patch from #12 seems good to me; it has been applied, and the issue is resolved. Therefore, I'm marking this as RTBC.
I hope that the fix will be included in the next release, as it is quite critical.
Comment #17
nicholassSo I just removed my patch for https://git.drupalcode.org/project/date_range_formatter/-/merge_requests... and then upgraded drupal/date_range_formatter (dev-9.0.x 8808a9c => dev-9.0.x d1f07a7).
And I am back to seeing a white screen on my site
So is there some kind of missing database update or something? Do I need to change my views? I tried to resave the date fields but that didn't seem to work either.
Comment #18
nicholassHere is an xdebug screenshot if that helps debug, im not sure what needs fixed....
Comment #19
nicholassHere is another screenshot higher up the call stack
Comment #21
nicholassOk so I updated this forks branch with commits from the source, and re-applied the original change. So the new diff is https://git.drupalcode.org/project/date_range_formatter/-/merge_requests... and seems to work for me.
Comment #22
nigelcunningham commentedStatic version of MR for use in composer patching.
Comment #23
lowfidelityPatch from #12 resolves the issue for us on Drupal 10.2.2
Comment #26
teknocat commentedThese patches are not the correct solution to the problem. The issue is that "single" and "single_all_day" options were added to the settings form, but not defined in the schema YML or provided with the default options. They also weren't displayed in the summary.
I'll create another issue fork that makes those corrections.
Comment #28
jeffamI added the
3309324-single-daybranch to create a patch against the dev version of this module.Here's the URL for the patch from the one commit on that branch:
https://git.drupalcode.org/issue/date_range_formatter-3309324/-/commit/4...
This patch only works against the the 9.0.x dev version.
Comment #29
majorrobot commentedCan confirm this is also broken in 4.0.2.
However, the most recent fix (
3309324-single-day) does the trick (at least for the dev version of the module). Would be great to get this merged in and released so we don't have to depend on the dev version!Comment #30
bachbach commentedhere is a patch against 4.0.2
Comment #31
pefferen commentedThe patch in #30 works for us, we use version 4.0.2
It introduced another issue, if the start and end date and time are the same, the date is rendered incorrectly if the
one_daytime format is configured to include the start and end time as well. The module assumes that no end date is needed to render the date if the start and end timestamps are the same.For this I created a new issue #3492241
Comment #32
sea2709 commentedThis patch is an improvement from the patch #30 I see in the formatter configuration, we have 'single' and 'single_all_day' settings but we've never used it. So this patch removes these settings from the settings form.
Comment #33
norman.lol#3309324-30: Passing empty value to t() when same day + time for start and end date is working around the issue so far.
But I'm really confused why we pass a variable to
t()in the first place. You should never uset()to translate variables.Comment #34
norman.lolThis one needs work. We can't simply drop the
singleconfig. Because now dates without an end date will have no way to be configured.Comment #35
norman.lolI think this is how it is supposed to be. Added
singleback and removedt()around variables.Comment #36
pefferen commentedThe patch in comment #35 looks good and works fine in my tests +1 for removing the translation of the variable.
Comment #37
rahul_ commentedWe identified similar issue with the latest code and we fixed using the below Patch
Comment #38
rahul_ commented