-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Validator] DateRange constraint added #7766
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
I would like to add relative formats supported by |
@cursedcoder It's a good idea, i think. |
I think this should be merged into Apart from that, what about timezones? Can you rely on the server's timezone for comparison? What if $birthday contains the date "2012-01-01 GMT-01:00", this would be equivalent to "2012-01-01 01:00 GMT" and consequently fail your constraint because it is greater than "2012-01-01 00:00". Good idea in general, but this needs a lot of thought :) |
<target>This date should be {{ limit }} or earlier.</target> | ||
</trans-unit> | ||
<trans-unit id="66"> | ||
<source>This value should be {{ limit }} or later.</source> |
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.
value -> date
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.
The other way round: date
should be value
above.
I solved this problem by using the comparison constraints: new Assert\Date(),
new Assert\GreaterThanOrEqual(array(
'value' => new \DateTime()
)),
new Assert\LessThanOrEqual(array('value' => new \DateTime(
date('Y-m-d', strtotime("+2 month"))
))), But it has a disadvantage: as @bschussek said above it should be merged into |
@Exelenz Very nice idea - look forward to using this on my current project! |
Related to #7726 and we now have the ExpressionLanguage Component making the original idea allot more powerful |
So what happened in result? There is number of PR for this functionality. Did anyone get merged? |
Replaced by #11673. |
…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
Added DateRange constraint and appropriate translations in russian and english.
Simple example:
Custom format example:
Date format by default is d/m/Y, but easily can be overridden by 'format' property of constraint, f.e.:
This is my first commit to symfony components so feel free to request any additionals - write docs, improve something and so on.