Repository navigation
Conversation
createFromFormat() silently rolls impossible dates over, so "2023-02-30" for "Y-m-d" was compared as 2023-03-02. The input is now checked with isDateTime() first, matching how Date and the other validators behave.
Cover "2023-02-30" with "Y-m-d" and "c", which must be rejected, plus a leap day and an exceptional format that must still pass.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1884 +/- ##
============================================
- Coverage 97.18% 97.14% -0.04%
- Complexity 1096 1097 +1
============================================
Files 198 198
Lines 2555 2557 +2
============================================
+ Hits 2483 2484 +1
- Misses 72 73 +1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
DateTimeDiffnow rejects impossible dates when a format is given, the same wayDateand the other date validators do.Motivation
When a format is given,
DateTimeDiffpasses the input straight toDateTimeImmutable::createFromFormat().That function silently rolls impossible dates over, therefore
2023-02-30withY-m-dis compared as2023-03-02instead of being rejected.DateTimeDiffalready uses theCanValidateDateTimetrait, but only forgetExceptionalFormats(), that is why it never ran theisDateTime()check that the other validators use.What I have done
In
createDateTimeObject(), the input is now checked withisDateTime()beforecreateFromFormat()is called.Input that fails this check is treated as not a date, so the existing
TEMPLATE_WRONG_FORMATmessage is used.Test Plans
Added the following cases to
DateTimeDiffTest.Y-m-dwith2023-02-30, andcwith2023-02-30T00:00:00+00:00Y-m-dwith the leap day2024-02-29, andcwith2020-01-01T00:00:00+00:00Test Results