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

[5.3] Revert #16692 and make date_format work with ISO8601 again #16845

Merged
merged 3 commits into from
Dec 17, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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