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

Increase CanValidateDateTimeTest invalid data test coverage #1460

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

agchan12
Copy link

@agchan12 agchan12 commented Jun 3, 2024

What?

  • Update test cases for the data provider used for the invalid date time tests.

Why?

This change is to ensure Respect\Validation is intentional about the DateTime formats.

For context the ISO 8601 standard says that we shouldn't accept -00:00 (or anything similar) offsets.

I noticed that there was an a change in how CanValidateDateTime.php behaved from v2.2 to v2.3.

Prior to v2.3 date time formats of 2018-01-30T19:04:35-00:00 (note the -00:00) would pass validation. After updating to v2.3 the format is not accepted.

This is because the DateTime::createFromFormat accepts the $value of 2018-01-30T19:04:35-00:00 but internally converts the -00:00 to +00:00

            $formattedDate = DateTime::createFromFormat(
                $format,
                $value,
                new DateTimeZone(date_default_timezone_get())
            );

This in turn causes the validation around $value !== $formattedDate->format($format)) to fail

            if ($formattedDate === false || $value !== $formattedDate->format($format)) {
                return false;
            }

Follow up

Since PHP internally converts the -00:00 to a +00:00, will Respect\Validation ever consider accepting a format of -00:00 (and other offshoots of the -0000 time offsets) 😄 ?

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

Successfully merging this pull request may close these issues.

1 participant