-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Validator] Added DateTimeRangeValidator #9164
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
This proposal has a few advantages over #7766...
|
CONTRIBUTORS.md is automatically updated 👍 |
@@ -881,3 +881,4 @@ Symfony2 is the result of the work of many people who made the code better | |||
- Erik Saunier (snickers) | |||
- Tony Piper (tonypiper) | |||
- Vladislav Vlastovskiy (vlastv) | |||
- Andrew Moore (FineWolf) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be reverted. It's generated automatically by Fabien from time to time.
throw new InvalidOptionsException(sprintf( | ||
'Option "timezone" must be a valid TimeZone for constraint %s', | ||
__CLASS__ | ||
), array('timezone')); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should link the catched exception as previous exception
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, however this required a change to the signature of InvalidOptionsException
in order to support linked exceptions (the \Exception
class has no setter for this, and it has to be set while constructing the exception).
This change does not break BC.
Then why creating new validators? see #8300, it still misses a few tweaks (timezone + min/max messages) but it's a lighter approach. |
@bamarni : Because of the single responsibility principle.
If you look at the |
Travis failed due to c741c5838d2115d2ac5c50e77c6aef049199c0f3... Test failures are unrelated to this pull request. @fabpot : Can you take a look at your changes? |
@FineWolf : imo your comparison with About single responsibility principle, if those constraints have totally different purposes, why half of your new validator's class is a duplication from date and datetime validators (for datetime object creation)? |
…ts and Range (webmozart) This PR was merged into the 2.6-dev branch. Discussion ---------- [Validator] Added date support to comparison constraints and Range | Q | A | ------------- | --- | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #3640, #7766, #9164, #9390, #8300 | License | MIT | Doc PR | symfony/symfony-docs#4143 This commit adds frequently requested functionality to compare dates. Since the `DateTime` constructor is very flexible, you can do many fancy things now such as: ```php /** * Only accept requests that start in at least an hour. * @Assert\GreaterThanOrEqual("+1 hours") */ private $date; /** * Same as before. * @Assert\Range(min = "+1 hours") */ private $date; /** * Only accept dates in the current year. * @Assert\Range(min = "first day of January", max = "first day of January next year") */ private $date; /** * Timezones are supported. * @Assert\Range(min = "first day of January UTC", max = "first day of January next year UTC") */ private $date; ``` Commits ------- 60a5863 [Validator] Added date support to comparison constraints and Range
This adds a new validator to verify if a
DateTime
is between an optionalmin
ormax
. Essentially, it is theRange
validator forDateTime
.Travis failed due to c741c5838d2115d2ac5c50e77c6aef049199c0f3