Exposed views date filter with offset not working as expected

Created on 2 July 2018, over 6 years ago
Updated 2 February 2023, about 2 years ago

Problem/Motivation

When using a date/time filed as exposed filter using the "offset from the current time" setting, the filter doesn't display as I expected.

The setting for the filter are:

This leads to the filter being displayed like:

As you can see the dates are output in the filter as the relative text string. This can lead to problems if using a date selector dialog.

Proposed resolution

The output I expected is:

This has the dates computed and entered in the input element.

<!-- h3 id="summary-remaining-tasks">Remaining tasks</h3 --><!--h3 id="summary-ui-changes">User interface changes</h3 --><!-- h3 id="summary-api-changes">API changes</h3 --><!-- h3 id="summary-data-model-changes">Data model changes</h3 -->
🐛 Bug report
Status

Needs work

Version

10.1 ✹

Component
Views  →

Last updated 1 day ago

Created by

🇬🇧United Kingdom John Cook

Live updates comments and jobs are added and updated live.
  • views

    Involves, uses, or integrates with views. In Drupal 8 core, use the “VDC” tag instead.

  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

  • Needs issue summary update

    Issue summaries save everyone time if they are kept up-to-date. See Update issue summary task instructions.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇵🇱Poland Graber

    I finally created this https://www.drupal.org/project/date_filter → to address this issue and many other.
    Looks like issues like this have a very small chance to get enough attention and find their way into core so we have to handle that in contrib :(

  • Status changed to Needs review almost 2 years ago
  • 🇮🇳India junaidpv Kannur, Kerala

    Building on #44. Adding similar improvement as #38 but to the datetime filter in core datetime module.

  • 🇮🇳India junaidpv Kannur, Kerala

    Try fixing CCF.

  • Status changed to Needs work almost 2 years ago
  • 🇺🇞United States smustgrave

    Was previously tagged for tests and issue summary update which still need to happen plese.

    Also please include interdiffs with patches.

  • 🇮🇳India junaidpv Kannur, Kerala

    Exactly same as #47, just re-rolled for 10.1.x

  • 🇫🇷France S3b0uN3t Nantes

    Hello,

    I tried to apply patch on comment #50, but it's thrown an error in datetime module :

    Warning: Undefined array key "type" in Drupal\datetime\Plugin\views\filter\Date->getOffset() (line 180 of core/modules/datetime/src/Plugin/views/filter/Date.php).

    Without this warning, the patch works perfectly on Drupal 10.2.2!

  • 🇫🇷France prudloff Lille

    Starting with #38, the patch always adds +1 day to any max value that does not explicitly contain a time.
    While I understand the reason to do this on date values, I don't think it always makes sense on offset values.
    For example "now" will become "now +1 day" (so tomorrow at the same time). But if I want my view to return results between some date and now, it will be confusing if it starts returning results from tomorrow.

  • 🇮🇳India junaidpv Kannur, Kerala

    Just a re-roll of #50 for 10.3.2

    Hopefully, we need to address #51 and #52.

  • 🇪🇞Spain plopesc Valladolid

    Added new version of the patch against 10.3.2 where it adds support also for missing max value.

  • 🇭🇺Hungary SunnyGambino Buj

    Patch based on 2982968-core-views-improve-date-filter-56.patch.
    Just quick fix to make sure there are no warnings, otherwise AJAX reset button won't work, as it is throwing these annoying warning. :)

  • 🇳🇱Netherlands johnv
  • 🇳🇱Netherlands johnv

    The OP is confusing to me on several accounts
    - the expected outcome is in +/- 3 days, but the actual results are in years
    - the printscreen shows that 'An offset [...]' is selected, instead of 'A date [...]'.

    I my test, when selecting
    - 'An offset [...]', I need to set '-7 days', to '+1 day'
    - 'A date [...]', I need to set '20241231' to '20250303'
    IMO that is OK. I can imagine a view with changes in the last week (using offset).

    Of course the widget is very basic/not acceptable for ordinary users.

    So, this issue still 'Needs issue summary update'

  • 🇮🇳India niranjan_panem Gurugram

    Below is the patch, in drupal 11
    →

Production build 0.71.5 2024