Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Validator] DateValidator, DateTimeValidator should accept \DateTimeInterface #42705

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
dkarlovi opened this issue Aug 24, 2021 · 4 comments
Closed

Comments

@dkarlovi
Copy link
Contributor

Symfony version(s) affected: 5.3.6

Description
If passing a \DateTimeInterface value to DateValidator and DateTimeValidator, by default it treats it as invalid.

This is ironic since DateTimeValidator actually uses the fact an instance of \DateTime was successfully created as a signal the value is valid.

How to reproduce

Pass a valid instance of \DateTimeInterface to either DateValidator or \DateTimeValidator, they will validate it as invalid.

Possible Solution

Allow \DateTimeInterface values as valid.

Additional context

Using some tools to read Excel files already converts the values in cells to \DateTimeInterface instances (based on Excel cell value format hints). Passing the to the validation process fails it since it's not a string.

@dkarlovi dkarlovi added the Bug label Aug 24, 2021
@dkarlovi dkarlovi changed the title DateValidator, DateTimeValidator should accept \DateTimeInterface [Validator] DateValidator, DateTimeValidator should accept \DateTimeInterface Aug 24, 2021
@derrabus
Copy link
Member

You can use a TypeValidator for that, can't you?

@OskarStark
Copy link
Contributor

I think he can, while I agree that this is a bit ironic πŸ˜„

@dkarlovi
Copy link
Contributor Author

Talked to @stof on Slack. He says the behavior is intentional so I'm closing here.

@derrabus
Copy link
Member

derrabus commented Aug 25, 2021

@OskarStark We've had that behavior and deprecated/removed it, see #25015.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants