Problem/Motivation
The datetime module has recently been made views compatible (nice) but you can only use it to match exact dates.
There are currently 3 different date arguments ("Date in the form of YYYY.", "Date in the form of MM.", "Date in the form of DD."). They seem to be following the conventions that were set forth in the created date arguments.
Proposed resolution
Add an argument that allows filtering using operators like in the datetime filter.
Remaining tasks
Discuss best approach, write tests+code, evaaluate code.
User interface changes
Adds a datetime contextual filter that allows operator selection.
API changes
Possible deprecating current views arguments if a solution seems to make them redundant.
Data model changes
None.
Comments
Comment #1
Jaesin commentedThis is my first approach but I think it would be better to be able to handle YYYY, MM and DD in a new argument named datetime so we can deprecate the other 3 arguments.
Comment #2
mpdonadioThanks for the initial patch. Changing this to a feature request, as it wasn't present in Drupal 7 / Views 3. I am really surprised I have never run into this situation before, but I see how this can be useful.
I don't think we would be able to deprecate the other arguments, as I suspect that would be an upgrade and migrate path nightmare and we don't want any API changes at this point. Also, in theory, we should be able to add validators to those to range check the existing ones. Instead, I would remove the fixed date option, and just have this handle computed dates (what you called offset dates).
#2489476: [PP-1] Base fields miss out on Views data from hook_field_views_data() may (or may not) complicate this issue, or change its approach.
Computed dates in the URL also require adding a cache context (probably to make it non-cachable). Not sure how to handle that with an argument plugin.
Added a few tags. We will eventually need a Beta Eval, but not until we iron this out a bit more.
Do we use the term "calculated" or "computed" more in core? I think "computed" may be more appropriate in this case.
Even though this is just an alias, I think this is too disruptive. I would rename your new class "ComputedDate" to match the argument key. This makes even more sense if you just have it handle computed dates.
Bad docblock format. Does it really need to be public or should you have a getter instead? I also think the general convention in Drupal is not set the initial value here, but in the constructor.
Needs docblock and access declaration. This happens several times in the patch.
Bad indent. Needs docblock.
Needs @param in the docblock.
Comment #3
Jaesin commented@mpdonadio Thanks for reviewing.
Some outstanding questions.
I changed NumericDate to FormulaicDate because Drupal\views\Plugin\views\argument\Date extends Formula. This first patch is just meant to be a proof of concept. I want to get conversation started about this.
I would argue that the YYYY, MM and DD arguments should be able to use operators as well. If all date arguments are computable, with = being the default operator, all we need to add is a full date version.
I find the way these dates were implemented to be really weird. Does anyone know the theory behind having individual segments for date arguments but not having a complete date as a single argument? Does anyone know why operators weren't already introduced for date arguments?
Comment #4
mpdonadioAs for how useful, I use the YYYY and MM arguments all the time when building things like blogs, and need yearly and/or monthly archives. I've used DD once or twice.
I'm sure you can come up for a use case for using operators for computed date arguments, but in all of the cases I could think of, an exposed filter fit the bill better on sites I have done. I'm gong to let others chime in, though. I'm mostly neutral on this as is. The VDC people should see this, too.
If we do want this feature, I think adding operators to the existing arguments and adding a full date argument w/ operators may be best. Adding operators would require an upgrade path + tests, as it would be a schema change.
Allowing operators on date arguments from the URL has caching complications, and D7 and earlier made this tougher to handle in a sane manner. With exposed filters, the operator becomes part of the URL, so you don't have the problem.
As for why things were implemented the way they were, I don't think we will ever know other than to say that both Views and DateTime were non-core modules before Drupal 8, and a lot of features were straight ports and relatively unchanged from Drupal 5.
Comment #5
amateescu commentedDiscussed this with @dawehner and it's very unlikely to happen for core 8.0.0, so we should probably move it to the Date contrib module and try to bring it into core in 8.1.
Comment #6
mpdonadioStill not 100% convinced this is needed, especially with the caching complications, but yeah, let's postpone for now.
Comment #7
luksakI just came across this because I need a year based exposed filter. Should filters be covered in a different issue? In my opinion Views integration is incomplete if this is missing.
Comment #8
Jaesin commentedHello @Lukas, I agree with you and think there is no reason postpone development on this issue if anyone has time to work on it.
From my perspective, it makes sense to add operators to the base class so you can choose the operator (defaulting to "=") for all date arguments.
Comment #10
caspervoogt commentedJust chiming in to say that filtering on year, month, and day separately would be great. In D7 this was possible by setting the granularity in the filter's settings. I am really missing that feature. Perhaps the Date module will finally handle this and get rolled into core.
Comment #11
sukanya.ramakrishnan commented+1 for caspervoogt's comment!!! Really missing the granularity feature!! Hope it gets added to core soon!
Comment #12
mpdonadioThere is not reason to postpone this as far as I can tell. However, we are realling trying to move away from the do-it-all plugins in 8.x, and breaking things down into more manageable plugins. TBH, I need to review the IS and the plugins to assess where we stand with this.
Comment #14
jhedstromI've never been quite clear on what this issue was about. From the IS:
This isn't accurate. The views integration went in with the same granularity that numeric dates receive from the Views module itself. Specifically, it provides individual date components (year, month, day), and some commonly used combinations (year & month for instance).
Here's the list of available arguments for a single field:

Marking as needing an IS update to clarify what would need to be done.
Comment #16
benoitf commentedMaths comparison and date offset would be much more pertinent than string tools (begin with, string length).
Could date fields be managed as the publication date?
Filtering on publication date is ok.
Comment #19
jibranIs it still required after #2786577: The Views integration Datetime Range fields should extend the views integration for regular Datetime fields?
Comment #31
smustgrave commentedThank you for sharing your idea for improving Drupal.
We are working to decide if this proposal meets the Criteria for evaluating proposed changes. There hasn't been any discussion here for over 8 years which suggests that this has either been implemented or there is no community support. Your thoughts on this will allow a decision to be made.
Since we need more information to move forward with this issue, the status is now Postponed (maintainer needs more info). If we don't receive additional information to help with the issue, it may be closed after three months.
Thanks!
Comment #32
benoitf commentedI've just checked, and date comparison is now possible in Views. I've managed to filter a view with dates (either a publication date or a content date), with operators (>, <, etc.) on date offset (eg "-1 month") or YYYY-MM-DD.
I don't how long this is possible, but I can now replace my workarounds! ;-)
So, I think this issue can be closed.