-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Validator] Added date support to comparison constraints and Range #11673
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
Very nice! Thanks @webmozart |
👍 |
n1 |
👍 |
Don't forget to at least add a docs issue :) - we can just use your examples, they're great! |
@weaverryan I'll be a good boy and open a PR there ;) |
👍 Awesome! Thanks @webmozart |
I added the docs PR now. Ping @symfony/deciders |
Maybe add support for DateTimeInterface |
// This allows to compare with any date/time value supported by | ||
// the DateTime constructor: | ||
// http://php.net/manual/en/datetime.formats.php | ||
if ($value instanceof \DateTime && is_string($comparedValue)) { |
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.
please support both DateTime and DateTimeInterface (for PHP 5.5+ users using the ImmutableDateTime)
Please also add a test validating an ImmutableDateTime rather than a DateTime (running only when the class exists of course) |
👍 |
1 similar comment
👍 |
Thank you @webmozart. |
…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
Wow! Great addition 😉 |
…mparison constraints and Range (webmozart, javiereguiluz) This PR was submitted for the 2.7 branch but it was merged into the 2.6 branch instead (closes #5384). Discussion ---------- Added information about the new date handling in the comparison constraints and Range | Q | A | ------------- | --- | Doc fix? | no | New docs? | yes (symfony/symfony#11673) | Applies to | 2.6+ | Fixed tickets | - This PR finishes #4143 Commits ------- b6c1a93 Added the "payload" option back 7ef2e6a Show annotations first e3efbbf Reordered the code blocks to show Annotations, YAML, XML and PHP 39f46e1 Fixed the issues reported by @xabbuh 7003445 Finished the documentation of the new data comparison validators 1fa69fe Added information about the new date handling in the comparison constraints and Range
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: