Repository navigation
[5.6] Testable date validation rules when comparison has relative time - #23211
Merged
taylorotwell merged 1 commit intoFeb 20, 2018
Merged
Conversation
derekmd
force-pushed
the
testable-validation-relative-time-params
branch
4 times, most recently
from
February 19, 2018 08:12
b7c4220 to
d91a0ca
Compare
derekmd
force-pushed
the
testable-validation-relative-time-params
branch
2 times, most recently
from
February 19, 2018 09:11
a5ae20b to
4ade081
Compare
Member
|
I updated Carbon dependency on laravel/framework. |
derekmd
force-pushed
the
testable-validation-relative-time-params
branch
from
February 19, 2018 16:35
4ade081 to
eab65c5
Compare
Contributor
Author
|
Even better! The commit has been updated for just Carbon >= 1.22. |
Member
|
Your method |
derekmd
force-pushed
the
testable-validation-relative-time-params
branch
2 times, most recently
from
February 20, 2018 16:45
51f7094 to
a4416eb
Compare
Date validation rule parameters containing relative time like 'today' or 'next monday' do not respective Carbon::setTestNow(). To get a date-adjusted value when these keywords are present in a date parameter, instantiate Carbon over DateTime or strtotime().
derekmd
force-pushed
the
testable-validation-relative-time-params
branch
from
February 20, 2018 16:48
a4416eb to
7bcfa90
Compare
Contributor
Author
|
I sat for an unreasonable amount of time trying to think of a good name and |
Member
|
I think that makes sense. |
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.
Change requested by: #19520
I noticed this issue recently in a feature test hitting an API endpoint and doing a HTTP request assertion equivalent to:
Only
starts_onvalues after 2018-02-19 would pass validation.Date validation rule parameters containing relative time like 'today' or 'next monday' don't respect
Carbon::setTestNow(). To get a date-adjusted value when these keywords are present in a date parameter, instantiateCarboninstead ofDateTimeorstrtotime().The previous date parameter behaviour is left as-is. Only when
Carbon::hasTestNow()andCarbon::hasRelativeKeywords($value)aretruewill an attempt be made to parse the string for an adjusted date.Workaround forCarbon1.20 & 1.21Given
carbon\carbondependency of~1.20, this code:wasn't supported until 1.22 (pull request: briannesbitt/Carbon#634) released Jan 15, 2017. So a few
Carbonconstructor lines were needed inValidatesAttributesto supporttodayas a validated relative time keyword.