-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Annotation] GreaterThan & DateTime #9390
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
Comments
There was already a discussion about this. |
@sstok I don't understand why the referenced PR is related to this ticket. According to the discussion, it allows to define an other field in the object graph as reference in a constraint but in this ticket, he doesn't want to compare his field with an other one. |
actually, it should have been linked to #7766 closing as duplicate |
@stof Thanks, anyway, I still don't understand why the referenced PR is related to this ticket. With this addition, if it is merged into the Range constraint, I can't see how I will check if my date is greater than now (with annotation) as I can't provide the min value with |
@egeloen The PR I linked would support passing |
@stof Okay thx for the clarification |
Ah because of the |
Nop, I was talking about an object. |
…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
Hi there,
At work we wanted to check if a date (in a form) was greater than "now". The problem was that we were using annotations in our entity for the validation and (apparently) there is no "simple" way to do so.
The solutions which came to my mind were:
$builder->add('foo', 'bar', array('constraints' => new \DateTime())
)@Assert\True
on my date field and implement anisDateValid
method@DateTime
annotation which would extends from\DateTime
and could be used everywhere (in my case :@Assert\GreaterThan(value = @DateTime)
)I've chosen to implement the latest of my proposal (
@DateTime
), it works well (IMO it is flexible, clean and reusable) and I think it could be a very good idea to implement it in symfony.What do you think about it?
If you feel like it, I can share my work.
The text was updated successfully, but these errors were encountered: