Problem/Motivation
When using a custom timestamp field to filter a view the filter type used is the numeric filter, rather than the expected date filter, this prevents the view from being filtered by an offset of the timestamp, and also results in an exposed filter on a timestamp field expecting the user to input a valid unix timestamp value, rather than being presented with a date picker element.
note that this only applies to custom fields of the type timestamp, fields such as creayed date and updated date, which are stored in the db as timestamps are handled as expected, using the date filter plugin.
Steps to reproduce
Create a content type with a custom field of type timestamp Add date-time field with timestamp formatter
Or add a custom field of type timestamp to the user object, populate the field with data.
create a view displaying the the content type, or users, and add a filter on the created timestamp field, the filter interface will use the numeric plugin, rather than the date plugin, removing the option to use an offset value in the filter, and displaying the exposed filter as a text input rather than as a date picker.
I've checked this on a simplytest.me instance on drupal 8.9.13 with no additional modules installed to ensure that the issue is present in a base drupal install
Proposed resolution
Ensure that the timestamp field type uses the date filter rather than the numeric filter.
User interface changes
in the views admin the user will be able to select to use an offset, rather than a specific date, where the filter is exposed a date picker will be used rather than an standard text input
Before:

After:

| Comment | File | Size | Author |
|---|---|---|---|
| #13 | core_views-timestamp_date_filter-3204558-13.patch | 504 bytes | phily |
| #25 | Screenshot-before-altering-field.png | 156.03 KB | niranjan_panem |
| #25 | Screenshot-after-altering-field.png | 136.89 KB | niranjan_panem |
| #30 | before.png | 19.43 KB | dcam |
| #30 | after.png | 27.81 KB | dcam |
Issue fork drupal-3204558
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
claudiu.cristeaThis seems a duplicate of #2648950: [PP-2] Use form element of type date instead textfield when selecting a date in an exposed filter. Closing this, but feel free to reopen if you think that this is a different issue,
Comment #3
jkeasley commentedReopening this ticket as it seems to be relating to a different issue to the ticket referred to when marking as duplicate.
The issue referred to seems to relate to the date plugin not providing the expected datepicker elements, while the issue here is that custom timestamp fields use the incorrect plugin 'numeric', rather than the 'date' filter plugin.
note that on testing and reviewing the patches from the referenced issue I noted that the tests for the timestamp filter handling referenced in the patches would not catch this issue, as they test the functionality using filters applied to the created_date field, which is filtered using the expected date filter.
While created_date and updated_date use the expected date filter when adding a view filter to those fields, a custom created timestamp field does not.
Comment #7
tuuuukka commentedIn https://git.drupalcode.org/project/drupal/-/blob/9.5.x/core/modules/view... the filter is set to
date, which is correct. But this is later overridden in https://git.drupalcode.org/project/drupal/-/blob/9.5.x/core/modules/view... ($attributes['type']isint) and the filter is changed tonumeric.As a quick test I did this:
..and it seems to work, so I think that's where it gets twisted.
Comment #9
vivek.kekare commentedThis issue present in Drupal 10.0.x as well. Any update expected for this issue in core itself?
Comment #10
johnpitcairn commentedShould probably move this to 11.x now.
Comment #11
niklp commentedI tried the hack in #7 but it didn't work for me under 10.x
I have had some success in combating the problem by using https://www.drupal.org/project/better_exposed_filters but it's not perfect.
This is a very annoying bug for filtering dates (manifesting as timestamps) by exposed filter... :/
Comment #12
jphelan commented#7 works with me in conjunction with the date_popup module.
Comment #13
phily#7 works for me using Drupal 10.3.6, patch is attached.
It should work with Drupal 11 as the views.views.inc file is the same for these 2 releases.
Comment #14
smustgrave commentedThanks for working on this but issues should be in MRs vs patches and will need test coverage.
Comment #16
jphelan commentedI've opened an MR.
Comment #17
u.kurilla commentedLike #13 the patch does the job for me in Drupal 10.3.6.
Thanks for the MR #16
I was happy when I found this issue and its solution - after a couple of hours! :-)
Comment #19
ironnuts commentedMinor refactor of MR for code readability. Rebased MR. Test coverage still required.
Comment #20
ironnuts commentedAdded a screenshot to the steps to reproduce. It shows the form where the date time field with timestamp formatter is selected. The field is being added to the 'Article' content type.
Comment #21
joshua1234511This MR is no longer necessary as the required changes have already been addressed in the source branch. The fix for the issue can be found in EntityViewsData.php.
https://git.drupalcode.org/project/drupal/-/blob/11.x/core/modules/views...
Comment #22
tuuuukka commented#21 if you're sure it's been fixed, this issue status can be set to fixed or closed..?
Comment #23
gargsuchi commentedCan someone please test issue against 11.x?
Also, do we still need tests for this?
Comment #24
joshua1234511Tested the scenario again 11
- Steps taken
-- Created a content type and added a custom field of type timestamp.
-- Created a view that displays the content type
-- Added a filter for the created timestamp field.
- Test Failed
Even after applying the change from this Drupal core commit, which sets the filter type to date, the mapping still does not work correctly for custom fields.
I am investigating further to resolve this issue.
Related issue: https://www.drupal.org/node/2337515
Comment #25
niranjan_panem commentedWe can alter the numeric date field to actual date time field through drupal's
hook_form_views_exposed_form_alterbelow is the code using the hook
Below are the screen shots of before and after applying the drupal hook
Before
After

Comment #28
dcam commentedI closed the old MR because the .inc file it was modifying has been changed into a service class. There's no point in rebasing that.
I started to write a test and then decided "There is no way I'm writing a Unit test that covers an entire, complicated, nearly 500 line function." So I split the offending code out into its own function in the same class. I tried to leave it as unmolested as possible - no arbitrary code formatting changes. That way it should be easier to verify that not much changed.
Comment #29
smustgrave commentedWith UI changes need before/after screenshots added to the summary, depending how big the change may need UX sign off or a CR
Comment #30
dcam commentedScreenshots added.
Comment #31
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".
This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #32
dcam commentedRebased
Comment #33
dcam commentedSorry, this was in NR status.
Comment #34
smustgrave commentedLeft a comment on the MR
Comment #35
smustgrave commentedLeft comments on the MR.
Comment #36
dcam commentedFeedback was addressed.
Comment #37
smustgrave commentedFeedback appears to be have been addressed thanks @dcam!
Comment #38
xjmPosted some small stuff on the MR.
Meanwhile, is the IS up to date here? I didn't see anything in the patch that would result in the indicated UI. If it does, that's some serious magic. (I mean, it is Views, so maybe.)
Does this issue apply only to Views?
Finally, I think it would need a CR. Even if it's a bugfix, it may result in a behavior change in some circumstances.
Comment #39
xjmShould we have a followup to do the rest?
Comment #40
dcam commentedYes. The addition of the condition...
...enables the date filter for timestamps. I understand if that's hard to see because I moved all that code.
I'm not sure what other part of Core this problem might apply to. If there is one, then I think that should be handled in a separate issue.
I added a CR at https://www.drupal.org/node/3538264.
Comment #41
drummWe ran into this when we used a timestamp field and had a surprising deficit of functionality.
Comment #42
lostcarpark commentedI think it's confusing that relative dates work on Datetime fields, but not on Timestamps, so it would be great to get this over the line.
Comment #43
smustgrave commentedCan the follow up mentioned be created
Comment #44
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".
This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #45
dcam commentedThe follow-up has been added at #3568536: Break up FieldViewsDataProvider::defaultFieldImplementation().
Comment #47
dcam commentedI should have moved this back to RTBC when I created the follow-up issue.
Comment #48
dwwAdding a monster related issue, and also a minor concern on the MR.
Comment #49
dcam commentedI don't have an answer for the question of whether we should change it for the argument as well. It's understandable why this issue has only been about the filter plugin. This is more of a user-facing issue. For the record, I couldn't find an existing issue about the argument plugin.
Considering that changing the argument plugin would increase the potential for disruption to existing views I'm not willing to make that call unilaterally. Tagging for subsystem maintainer review due to the question on the MR.
Comment #50
dww#2544832: Views argument for the datetime module should use maths. is the closest I know of about the date argument question. Maybe we should indeed resurrect that from PMNMI and handle my concern over there.
Meanwhile, there have been a series of these "use a more useful filter plugin" issues. E.g. the linked one about dates, or #3347343: Add Views EntityReference filter to support better UX for exposed filters. There were all sorts of hassles with potential disruptions, what to do about existing views, etc, etc. I'm not clear why this issue can so easily change this, without similar concerns. 😅
Comment #51
dwwOh right, see #3517303: [PP-1] Use the new 'entity_reference' Views filter in EntityViewsData::processViewsDataForEntityReference() more directly about disruption and what to do about it. That proposes focusing on #3458099: Views handler loading should respect configuration as the way to truly avoid potential disruption.
Comment #52
graber commentedA few nits plus I agree with @dww that we should also fix the argument plugin here as it's a tiny change and that also touches the UI. Unfortunately at the moment the date filter argument doesn't support any additional input options (offset) as the filter does so no UI changes there really but maybe eventually as it should really for consistency so better to cover it early.
Removing the "Needs subsystem maintainer review" tag, I can review again if needed, hopefully VBO D8+ and date_filter modules creator will be enough ;)