Skip to content

DateTime constraint does not support trailing data #37094

Closed
@stefankleff

Description

@stefankleff

Description
The DateTime constraint can not deal with explicitly ignored trailing data. The validation will fail even though the value matches the specified format.

Example

$validator = Validation::createValidator();
$violations = $validator->validate('2020-01-01 00:00:00', new DateTime('Y-m-d+'));

The code above will create a violation with the message "This value is not a valid datetime."
The "+" in the format allows trailing data (see https://www.php.net/manual/en/datetime.createfromformat.php) BUT DateTime::getLastErrors() will return a warning:

 array:4 [
  "warning_count" => 1
  "warnings" => array:1 [
    10 => "Trailing data"
  ]
  "error_count" => 0
  "errors" => []
]

I suggest that in case the format ends with a "+" the warning should be ignored and don't cause a constraint violation.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions