Skip to content

[Validator] Add "format" option to DateTime constraint #14538

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

Closed
wants to merge 1 commit into from
Closed

[Validator] Add "format" option to DateTime constraint #14538

wants to merge 1 commit into from

Conversation

SoboLAN
Copy link

@SoboLAN SoboLAN commented May 4, 2015

Q A
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? yes
Tests pass? yes
Fixed tickets #14521 and partial #14510
License MIT
Doc PR None yet

This PR adds a new format option to the DateTime constraint and deprecates Date and Time constraints.

I will do a PR with necessary changes on SymfonyDocumentation if accepted.

@SoboLAN
Copy link
Author

SoboLAN commented May 4, 2015

Duplicate of #14531 . How do we decide which gets merged ?

…and Time constraints as deprecated

This fixes/closes #14521 and (partially) #14510
@@ -18,6 +18,7 @@
* @Target({"PROPERTY", "METHOD", "ANNOTATION"})
*
* @author Bernhard Schussek <bschussek@gmail.com>
* @author Radu Murzea <radu.murzea@gmail.com>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are not the author

@dosten
Copy link
Contributor

dosten commented May 4, 2015

I think that your method getViolationCode is wrong, after some research in the php source code i find that the errors and warnings in DateTime::getLastErrors() are:

  • Data missing - error
  • Trailing data - error
  • Unexpected character - error
  • Empty string - error
  • The timezone could not be found in the database - error
  • Double time specification - error
  • Double date specification - error
  • Double timezone specification - warning
  • The parsed date was invalid - warning
  • The parsed time was invalid - warning

If the error is "Double timezone specification" your code returns a INVALID_TIME_ERROR which is wrong.
If you are okay with this i propose to close this in favor of #14531 to not duplicate work.

btw, the docs PR is symfony/symfony-docs#5223

{
if (isset($errors[$key]) && count($errors[$key]) > 0) {
$allErrors = array_values($errors[$key]);
$firstError = array_shift($allErrors);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be more than one error

@SoboLAN
Copy link
Author

SoboLAN commented May 4, 2015

@dosten Fine by me. Closed, you won the race anyway :) .

@SoboLAN SoboLAN closed this May 4, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants