[5.5] Fixed date comparison validators failing when a format is specified #20940
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.
[ This is a follow-up to the closed PRs #20789 and #20868. ]
Fixed Validator failing on 'before_or_equal:today' when the input is today's date and a format is specified
The issue was that the time part was bleeding through from the current timestamp in
DateTime::createFromFormat
.Test case:
Some further information I found (thanks to @arjasco 's comment on the previous PR):
!
prepended.@taylorotwell "Isn't this going to break applications? What if people want the time part?"
If you have time fields in the date format, the validation will still use them.
http://php.net/manual/en/datetime.createfromformat.php
I have also added a number of date validation tests in a second commit. These tests deal with the time parts, and show that the fix I made is not breaking anything.
If you still think this change might cause issues, please provide a test case that this PR causes to fail, so that I have a chance of fixing the problem.
[ When porting my fix to branch
5.5
, I added extra test cases for the newdate_equals
validator to have that covered too. This exercise led me to a bug in its implementation, which I also fixed. ]Fixed Validator failing on 'date_equals' when a format is specified
Also added a number of test cases.
The issue was that
===
always returns false for the two separate DateTime instances returned bygetDateTimeWithOptionalFormat
.The fix can easily be applied to branch
5.4
too, so that users of the previous version get the benefits too. It doesn't have to be backported, as I originally wrote the fix for that branch. Here is the PR, it just needs to be merged. (It contains the first 2 commits of this PR.)