-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Validator] Replace Date, DateTime and Time by Timestamp #11925
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
👍 for this. The current string validation is quite useless as it does nto allow changing the format of the string. what would be the behavior if you don't configure a format ? Accepting any format supported by the DateTime constructor, throwing an exception because the format is required, or using a default format ? |
I'd make format required. What do you think? |
yeah, this seems good to me. |
Sounds good to me as well. |
Great solution! 👍 x 1000 for it 😉 |
If this is not be the default behavior, how else would we allow this use-case to be validated then? |
+1 |
actually i run into this problem @webmozart do you have time to implement it? if not i can do this for symfony 3.0. |
I agree with @Tobion, this change will make not possible to accept multiple formats for the same input.. |
As @javiereguiluz said in #21905 (comment), what do you think about reworking DateTimeValidator to include this change and deprecate TimeValidator and DateValidator? |
Closing as this is old, and @Tobion raised a point that is not answered since years. |
…Date|Time|DateTime constraints (ro0NL) This PR was merged into the 4.2-dev branch. Discussion ---------- [Validator] Deprecate validating DateTimeInterface in Date|Time|DateTime constraints | Q | A | ------------- | --- | Branch? | 4.1 | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | yes | Tests pass? | yes | Fixed tickets | #11925 | License | MIT | Doc PR | symfony/symfony-docs#7583 (old PR but not really needed now) Easy version of #21905. I think individual naming has value. Also the goal is to move forward to use `Type` really, not to bother with constraint renames. Commits ------- 5454e6f [Validator] Deprecate validating DateTimeInterface in Date|Time|DateTime constraints
At the moment, we have three constraints for validating date/time values:
Date
accepts\DateTime
instances and 'Y-m-d' stringsDateTime
accepts\DateTime
instances and 'Y-m-d H:i:s' stringsTime
accepts\DateTime
instances and 'H:i:s' stringsI think that's a bit confusing. Usually, a value should not be a
\DateTime
or a string, but either of them; if it is a string, it should usually match a specific pattern.Therefore I propose to deprecate all three constraints. The
\DateTime
case can be solved with theType
constraint already:The second case would be covered by a new
Timestamp
constraint which accepts a format as argument as supported by PHP:This would fix #11919 and replace #11821.
The text was updated successfully, but these errors were encountered: