Skip to content

Commit

Permalink
[5.3] Revert #16692 and make date_format work with ISO8601 again (#16845
Browse files Browse the repository at this point in the history
)

* Revert "Merge pull request #16692 from rohitsubedi/rohitsubedi-patch-1"

This reverts commit 4c70ab0, reversing
changes made to e91f04b.

* validation: add a few more date_format tests

Showing off how Y-m-d\TH:i:sP matches multple valid ISO 8601 date formats.

* validation: add test showing 00-00-01 passes for Y-m-d

It's unexpected for Y to match two-digit dates
  • Loading branch information
mfn authored and taylorotwell committed Dec 17, 2016
1 parent 08ffe4e commit 359b7c3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Illuminate/Validation/Validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -1841,9 +1841,9 @@ protected function validateDateFormat($attribute, $value, $parameters)
return false;
}

$date = DateTime::createFromFormat($parameters[0], $value);
$parsed = date_parse_from_format($parameters[0], $value);

return $date && $date->format($parameters[0]) === $value;
return $parsed['error_count'] === 0 && $parsed['warning_count'] === 0;
}

/**
Expand Down
15 changes: 15 additions & 0 deletions tests/Validation/ValidationValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2121,8 +2121,23 @@ public function testValidateDateAndFormat()
$v = new Validator($trans, ['x' => '22000-01-01'], ['x' => 'date_format:Y-m-d']);
$this->assertTrue($v->fails());

$v = new Validator($trans, ['x' => '00-01-01'], ['x' => 'date_format:Y-m-d']);
$this->assertTrue($v->passes());

$v = new Validator($trans, ['x' => ['Not', 'a', 'date']], ['x' => 'date_format:Y-m-d']);
$this->assertTrue($v->fails());

$v = new Validator($trans, ['x' => '2000-01-01T00:00:00Z'], ['x' => 'date_format:Y-m-d\TH:i:sP']);
$this->assertTrue($v->passes());

$v = new Validator($trans, ['x' => '2000-01-01T00:00:00Z'], ['x' => 'date_format:Y-m-d\TH:i:sP']);
$this->assertTrue($v->passes());

$v = new Validator($trans, ['x' => '2000-01-01T00:00:00+00'], ['x' => 'date_format:Y-m-d\TH:i:sP']);
$this->assertTrue($v->passes());

$v = new Validator($trans, ['x' => '2000-01-01T00:00:00+00:30'], ['x' => 'date_format:Y-m-d\TH:i:sP']);
$this->assertTrue($v->passes());
}

public function testBeforeAndAfter()
Expand Down

0 comments on commit 359b7c3

Please sign in to comment.