Skip to content

Commit

Permalink
Fix date validation (#40088)
Browse files Browse the repository at this point in the history
  • Loading branch information
driesvints authored Dec 17, 2021
1 parent 00eeab6 commit d88228e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/Illuminate/Validation/Concerns/ValidatesAttributes.php
Original file line number Diff line number Diff line change
Expand Up @@ -265,9 +265,11 @@ protected function checkDateTimeOrder($format, $first, $second, $operator)
$firstDate = $this->getDateTimeWithOptionalFormat($format, $first);

if (! $secondDate = $this->getDateTimeWithOptionalFormat($format, $second)) {
$second = $this->getValue($second);
if (is_null($second = $this->getValue($second))) {
return true;
}

$secondDate = is_null($second) ? null : $this->getDateTimeWithOptionalFormat($format, $second);
$secondDate = $this->getDateTimeWithOptionalFormat($format, $second);
}

return ($firstDate && $secondDate) && ($this->compare($firstDate, $secondDate, $operator));
Expand Down
3 changes: 3 additions & 0 deletions tests/Validation/ValidationValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4173,6 +4173,9 @@ public function testBeforeAndAfterWithFormat()
$v = new Validator($trans, ['start' => '31/12/2012', 'ends' => null], ['start' => 'date_format:d/m/Y|before:ends', 'ends' => 'date_format:d/m/Y|after:start']);
$this->assertTrue($v->fails());

$v = new Validator($trans, ['start' => '31/12/2012', 'ends' => null], ['start' => 'date_format:d/m/Y|before:ends', 'ends' => 'nullable|date_format:d/m/Y|after:start']);
$this->assertTrue($v->passes());

$v = new Validator($trans, ['x' => date('d/m/Y')], ['x' => 'date_format:d/m/Y|after:yesterday|before:tomorrow']);
$this->assertTrue($v->passes());

Expand Down

0 comments on commit d88228e

Please sign in to comment.