Needs work
Project:
Drupal core
Version:
main
Component:
datetime.module
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
16 Nov 2017 at 14:53 UTC
Updated:
6 Nov 2025 at 20:19 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
geertvd commentedFor #2699477: Steps towards handling end dates in Calendar 8 we'd need some specific date range arguments.
At the moment we just add arguments filtering on a date range's start date, this gives problems for events overlapping multiple months.
For our use case I think there's 2 options:
Once #2786577: The Views integration Datetime Range fields should extend the views integration for regular Datetime fields is in we could create an arguments for both the start date en end date and set the operator to ">=" and "<="
Comment #3
geertvd commentedTo be clear, I don't think we need the "Calculated Date" argument as proposed in #2544832: Views argument for the datetime module should use maths., I'm just talking about the configurable operators which is talked about in that issue.
Comment #4
geertvd commentedI needed something like to be able to create a calendar view with date ranges. For now I opted for my first suggestion.
This patch if far from complete but I might unblock some people in #2699477: Steps towards handling end dates in Calendar 8.
Keeping to postponed until #2786577: The Views integration Datetime Range fields should extend the views integration for regular Datetime fields is in.
Comment #5
jhedstromComment #7
jibran#2786577: The Views integration Datetime Range fields should extend the views integration for regular Datetime fields is in.
Comment #8
dwwThere's no reason this is postponed anymore, right? Needs work given patch #4, "needs tests", etc, but someone could start moving this forward at this point, no?
Thanks,
-Derek
Comment #9
mpdonadioYeah, the blocking issues are in 8.6.x, so this can start up again.
Comment #10
plachThe attached patch builds on #4 and implements approach 2: i.e. it provides an operator to filter on date range. In fact solution 1 requires two arguments in a Calendar view, which was breaking pagers in my installation.
To achieve this cleanly the patch adds a
DateRangeargument extending the existingDateone. It also provides a subclass for each supported granularity, to be consistent withDatetime, however I'm not sure why we need this and we don't just provide a granularity selector on the parent class.Tests still missing as this will likely need at very least some refinement.
Comment #11
anybodyComment #14
catchRe-rolled.
Comment #15
anybodyGreat, thank you! I'll review this further, but so far RTBC +1
Comment #16
codeclarified commentedRe-rolled 2924061-10.patch for 8.6.16Actually, ignore me, 10 should still apply cleanly to 8.6.16, composer decided to mess with me by bumping my core version to 8.7 which is where the patch failed to apply
Comment #17
anybody#14 is working for me with 8.7.1 while #16 failed to apply.
Comment #18
anybodyComment #19
yogeshmpawar#14 working for me as well & #16 failed to apply on 8.8.x branch, also no interdiff added for #16 so removing this patch from the issue for now. @codeclarified - if you want you can add your patch again with an interdiff so that It will be really helpful for reviewers to review (See here details about how to create an interdiff).
Comment #20
slefevre@ccad.edu commentedBoth #14 and #16 fail to apply for me on 8.7.3Scratch that, I wasn't applying them correctly.
Comment #21
imclean commentedThis sounds very useful but I can't quite follow what this patch is supposed to do beyond "specific filters that take into account both start and end date". Would it be possible for someone to please update the IS with a full explanation of the goals here? For example, what filters, arguments and sort options it will offer.
Comment #22
imclean commentedOr will specific filters etc. be possible via plugins with this patch?
Comment #24
finex commentedHi, the patch works if I create a field using the Drupal UI. It doesn't if the field has been created programmatically. Do I need to implement something extra on my code?
The following is the field definition on my Entity:
I've also reported the problem on the following issue: https://www.drupal.org/project/drupal/issues/2786577?page=1#comment-1337...
Comment #25
ckaotikSo far, the patch in #14 adds
datetime_rangevariants of the argument handlers. It can filter on both start and end value at once (via the "Range intersects" operator in the newdatetime_range*argument handlers), and allows configuring an operator for datetime field arguments in the first place.However, the new
datetime_rangeargument handler does so far only seem to support theintersect_rangeoperator, and only adds an empty condition for all other operators? Potentially useful filtering might include queries such as (START and END being the argument/filter inputs):What I'm missing so far is
datetime.views.schema.yml)Comment #26
imclean commentedI've added some filters in Views Daterange Filters. It would be good to add the equivalent ones here as a minimum.
Comment #27
holist commentedI'm having the expected results by applying patch from #14 and adding two contextual filters in my view. Both filters refer to the same date field (date range starting date to be exact). The first one contains formula "greater than or equal" and the second one has formula "less than or equal". Now I add URL parameters to my view like
2020-01-01/2020-02-01and I get rows with date from Jan 1st to Feb 1st.Maybe this explanation could help someone write the issue summary in a meaningful way.
Comment #29
brulain commentedEverybody uses dates, but date management in D8 is very very much worse than date management in D7: How is it possible ? Is it a (stupid) choice ? A mistake ? An oversight ?
I dont understand, because many unnecessary gadgets have been added into D8.
Comment #30
colan#29: Drupal 8 core was almost a complete re-architecture. As such, modules generally had to be rewritten. So in order to make D8 shippable within a reasonable time frame, minimal requirements were set for planned features, which includes date functionality. Enhanced features were left for later.
Rather than complaining about it, you can help move things along by either directly helping with these issues yourself (by uploading patches, etc.), or paying someone else to do it. That's how open-source software development works.
Comment #31
brulain commentedOK, and for what ? A modern gaz factory (french expression) ?
How many years or major versions will we have to wait for a decent date module ? D10, D11, ... ?
Well done man, the argument that kills. Rather, I suggest you do it right, starting with the basics: managing dates is part of the basics.
Comment #32
mrpauldriver commentedI understand your frustration @brulain but I think you should stand down; this isn't how we cooperate and get stuff done around around here. Maybe Drupal isn't for you?
I agree that development of the date ecosystem has been hit and miss with Drupal 8. Hopefully this will improve as we move forward.
And yes, I agree that dates should be part of the basics; but the trouble is dates are not basic, they are very complicated. Time zones, different faith calendars, not to mention different ways of storing such information in a database.
Picking fights doesn't help. Please stop.
Comment #33
brulain commentedThanks for your answer @MrPaulDriver.
This is more than frustration: it hasn't changed for 4 years.
So Drupal (8) isn't for me because the date module is still pathetic.
I do hope it will improve and not regress: but when ?...
I know that. But Drupal 8 implements many other more complex features (maybe more attractive): it is a matter of choice and prioritization.
Yes, sometimes it does.
I stop here, all is said. I have to be patient and have faith.
Comment #34
dipakmdhrm commentedHere's a try for the filter plugin for date range field:
I tried this with the most common application that I believe a date range filter could have: event search.
I may have over-engineered this in an effort to cover all possibilities.
Here's a list of the possibilities based on the following diagram:
What this patch does:
- Adds a new all-in-one filter for date range field (in addition to existing ones for end and start date components of the field) to cover all above possibilities.
- Uses HTML5 date field for exposed form for the field with date only storage.
- Uses combination of HTML5 date & time field for exposed form for the field with date & time storage.
Things still to do:
- Add argument (from #10) & sort plugins.
- Add tests
- Update hook to add schema for sites where this module is already installed
Gotchas:
- Filter for a field with both date & time storage doesn't work properly because states don't work for datetime field. See: https://www.drupal.org/project/drupal/issues/2419131
Comment #35
dipakmdhrm commentedAdded a couple of comments and removed a debug statement.
Comment #36
dipakmdhrm commentedArrggghhh... I created the patch for 8.8.x.
Will upload a new patch for 9.x version as well.
Comment #37
dwwThanks for your work on this!
However, I think this is turning into big scope creep. For example, we should fix #2648950: [PP-2] Use form element of type date instead textfield when selecting a date in an exposed filter generally, not have daterange-only filters do it differently/better than date filters.
This looks unused (which is good, since I don't think we should care at the Field API level about anything in here).
s/Date/DateRange/
I think this wants {@inheritdoc}, instead.
Maybe move this to an inline comment at the start of the body?
"the" would fit on previous line.
"$rc" is a bit terse as a variable name. Can we be more verbose / self-documenting?
"on/at" seems weird.
A) Missing @param docs for $which.
B) Missing docs for @return
C) s/Provide/Provides/
@todo ;)
Slick, but basically out of scope. Or at least we should postpone this on solving it for 'date' filters, first. See #2648950.
A) s/comparision/comparison/
B) Would fit on previous line (and maybe "in", too).
C) s/sql/SQL/
Nice, but I don't think this will fly. ;)
A) You want @see if you're linking to a URL.
B) I doubt core committers will go for this as a substitute for actual inline docs that explain WTF is going on. ;)
This sure seems like a lot of code and complication. Maybe this is the only way. Haven't had my face deep in the views date* handling recently, so I don't know off the top of my head if this is all necessary, if it already basically exists elsewhere, etc, but raising flag of "wow, do we really need all this?"
Lots of missing PHPDocs here. Not flagging them all. Probably not worth documenting until we decide if we actually need all this.
Thanks again for your effort on this! I think maybe 'postponed' is best, and we make sure existing date* filters use a date form element first. Then we can circle back and do all this. But I won't unilaterally make that decision.
Cheers,
-Derek
Comment #38
dwwp.s. The bot flagged 20 code style errors at https://www.drupal.org/pift-ci-job/1721356 -- those will eventually need to be addressed, too (might be some overlap with what I already pointed out above).
Comment #39
dwwYeah, let's postpone this and get all hands on deck at #2648950: [PP-2] Use form element of type date instead textfield when selecting a date in an exposed filter (and its blockers 🤦♂️).
Thanks,
-Derek
Comment #40
dwwAlso, since #2786577: The Views integration Datetime Range fields should extend the views integration for regular Datetime fields is already in (and there are a bunch of views handlers of various types for datetime_range) the scope of this is only the dedicated datetime_range filter plugin, right?
Comment #41
dipakmdhrm commentedCouple of thoughts on this (I might be wrong and missing something here):
Yep, I do believe I over-engineered it. But I do believe we should work on it so that we provide at least the following major filtering functionalities for something like events search:
Lastly, Thank you for your review of the patch. I'll definitely be more careful in future to avoid all the mistakes I did in this patch.
Comment #42
dww#37:
#39 (45 minutes later) - I do what I just said I wouldn't do. 🤦♂️
#41: You're totally right, these can definitely happen in parallel. 👍Thanks for (rightfully) pushing back.
Thanks for the patch, and you're welcome for the review. 😉 No worries about mistakes in the patch. That's why we have such a thorough review process / culture. It's how we learn. ;) Vastly better to contribute something (with "mistakes") and have to improve it, than to not contribute at all (a far greater "mistake").
Thanks/sorry,
-Derek
Comment #43
dipakmdhrm commentedNo worries at all!! Happens to the best of us.
Amen!
Comment #45
it-cruAdded to Bug Smash Initiative because I think a lot of people (also me) thinking it is already integrated/possible to filter for a core provided date_range field based on start and end date with views.
Example: Display all events x days before they start and until they end.
Haven't figured out how to configure this with a date_range field and views yet. Please correct me if I'm wrong (currently really late in germany now...)
Comment #46
vakulrai commented@dipakmdhrm , @dww , I have made changes to the patch based on the inputs by #37.
Also I found some problem while saving the view with some default values to the filter config form, it was mainly happening because the the filter schema expects value as "String", but the Datetime was storing drupalDateTime() object to it.
I have added a solution to it , and also added test scenarios to test the new plugin.
Please review !.
Thanks
Comment #47
vakulrai commentedFixing some Cspell issues and coding standards.
Comment #49
jeroentComment #50
karishmaamin commentedWorking on re-roll
Comment #51
karishmaamin commentedTried to fix some of custom command failure errors
Comment #52
vsujeetkumar commentedNeeds to add "Doc comment" for some methods in file "DateRange.php" to fix the "custom command failed" Issues.
Comment #53
suresh prabhu parkala commentedUpdate the patch as per #52. Please have a look.
Comment #57
graber commentedComment #58
graber commentedTurned out problems on our project originated elsewhere and patch from #14 still works fine. Added the current work to a fork, maybe it'll be easier to review.
Comment #62
jaime@gingerrobot.com commentedComment #63
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It either no longer applies to Drupal core, or fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".
Apart from a re-roll or rebase, this issue may need more work to address feedback in the issue or MR comments. To progress an issue, incorporate this feedback as part of the process of updating the issue. This helps other contributors to know what is outstanding.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #65
mikell commentedUpdated patch from #53 so it applies on D11.2.
Comment #66
kevin.dutra commentedTweak for the D11.2 reroll for PHP8.4 compatibility
Comment #67
oily commentedHave updated the IS, applied the IS template, updated the Remaining Tasks and the Proposed resolution.