Skip to content
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

Error in DateValidator with php format "c" #19754

Open
SOHELAHMED7 opened this issue Feb 4, 2023 · 3 comments
Open

Error in DateValidator with php format "c" #19754

SOHELAHMED7 opened this issue Feb 4, 2023 · 3 comments

Comments

@SOHELAHMED7
Copy link
Contributor

I observed a strange behaviour of \yii\validators\DateValidator.

From PHP docs

c ISO 8601 date 2004-02-12T15:19:21+00:00

What steps will reproduce the problem?

$v = new DateValidator([
            'type' => 'datetime',
            'format' => 'php:c'
        ]);

        Case 1:
        $v->validate('2004-02-12T15:19:21+00:00', $err);  <---- this example is from php.net
        VarDumper::dump($err); <---  'The format of the input value is invalid.'

        Case 2:
        $v->validate('2004-02-12T15:19:21+0000', $err);
        VarDumper::dump($err); <---  'The format of the input value is invalid.'

---

$v2 = new DateValidator([
            'type' => 'datetime',
            'format' => 'php:'.DATE_ATOM
        ]);

        Case 3:
        $v2->validate('2004-02-12T15:19:21+0000', $err);
        VarDumper::dump($err); <--- null

        Case 4:
       $v2->validate('2004-02-12T15:19:21+00:00', $err);
       VarDumper::dump($err); <--- null

What is the expected result?

For case 1 -> Validation should pass

What do you get instead?

For case 1 -> Validation fails

Additional info

Q A
Yii version 2.0.47
PHP version
Operating system
@samdark samdark added this to the 2.0.48 milestone Feb 5, 2023
@samdark samdark added type:bug Bug status:to be verified Needs to be reproduced and validated. labels Feb 5, 2023
@bizley
Copy link
Member

bizley commented Feb 5, 2023

This is a PHP issue, I can see that both c and r are not working. I'm not sure if it should be reported though, PHP says for example that their DateTimeInterface::ISO8601 should not be used since it's not really ISO8601 and to use ISO8601_EXPANDED or ATOM instead. Maybe this is the case as well? c looks like a weird mix between ISO8601 and ISO8601_EXPANDED.

We could throw an InvalidConfigException on init when php:c or php:r is used as a format with the suggestion to use proper formats.

@bizley bizley added status:under discussion and removed status:to be verified Needs to be reproduced and validated. labels Feb 5, 2023
@My6UoT9
Copy link
Contributor

My6UoT9 commented Feb 6, 2023

@SOHELAHMED7
Copy link
Contributor Author

@bizley

Yes that seems to be confusing

We could throw an InvalidConfigException on init when php:c or php:r is used as a format with the suggestion to use proper formats.

I disagree. Throwing error and preventing further execution is not the best option in my humble opinion. I suggest to log a warning/notice with details of the issue and suggesting work-arounds

@samdark samdark removed this from the 2.0.48 milestone May 21, 2023
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