Handle all from and to relative dates in API4 #24663
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Overview
API4 does not work correctly with relative dates that are open ended (e.g. From start of current calendar year). The open ended date is set to NULL here and then that is somewhere converted to a 0 timestamp, so one side of the comparison is Jan 1, 1970. That works half the time and doesn't work the other half of the time (when the To date is 1970).
Before
The unspecified date was set to 0.
After
Open ended relative date API calls with =, !=, <>, LIKE or NOT LIKE are converted to >= or <= as appropriate.
Nothing is changed for BETWEEN or NOT BETWEEN calls.
Technical Details
It is possible (for example in Search Kit) to specify a BETWEEN with relative date ranges as the From and To dates. That works fine in general, but won't work with half of the open ended relative dates. Such a query is pretty nonsensical and I don't think we need to worry about what it returns.
It would have been nice if BETWEEN date and NULL was equivalent to >= date in SQL, but it isn't.