8000 [11.x] Fix validator return fails if using different date formats (#5… · laravel/framework@48bdc07 · GitHub
[go: up one dir, main page]

Skip to content

Commit 48bdc07

Browse files
mrvipchiencuong.tt
andauthored
[11.x] Fix validator return fails if using different date formats (#54350)
* fix validator return fails if using different formats * change params name in test --------- Co-authored-by: cuong.tt <cuong.tt@gmail.com>
1 parent 4673387 commit 48bdc07

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

src/Illuminate/Validation/Concerns/ValidatesAttributes.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,8 @@ protected function checkDateTimeOrder($format, $first, $second, $operator)
299299
{
300300
$firstDate = $this->getDateTimeWithOptionalFormat($format, $first);
301301

302+
$format = $this->getDateFormat($second) ?: $format;
303+
302304
if (! $secondDate = $this->getDateTimeWithOptionalFormat($format, $second)) {
303305
if (is_null($second = $this->getValue($second))) {
304306
return true;

tests/Validation/ValidationValidatorTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6316,6 +6316,12 @@ public function testBeforeAndAfterWithFormat()
63166316

63176317
$v = new Validator($trans, ['x' => '1970-01-02', '2018-05-12' => '1970-01-01'], ['x' => 'date_format:Y-m-d|after:2018-05-12']);
63186318
$this->assertTrue($v->fails());
6319+
6320+
$v = new Validator($trans, ['from' => '2020-08-05', 'to' => '2020-06-08'], ['from' => 'date_format:Y-m-d|before:to', 'to' => 'date_format:Y-d-m']);
6321+
$this->assertTrue($v->passes());
6322+
6323+
$v = new Validator($trans, ['from' => '2020-05-08', 'to' => '2020-08-06'], ['from' => 'date_format:Y-m-d', 'to' => 'date_format:Y-d-m|after:from']);
6324+
$this->assertTrue($v->passes());
63196325
}
63206326

63216327
public function testWeakBeforeAndAfter()
@@ -6417,6 +6423,12 @@ public function testWeakBeforeAndAfter()
64176423

64186424
$v = new Validator($trans, ['foo' => '2012-01-15 11:00', 'bar' => null], ['foo' => 'before_or_equal:bar', 'bar' => 'nullable']);
64196425
$this->assertTrue($v->fails());
6426+
6427+
$v = new Validator($trans, ['from' => '2020-08-05', 'to' => '2020-05-08'], ['from' => 'date_format:Y-m-d|before_or_equal:to', 'to' => 'date_format:Y-d-m']);
6428+
$this->assertTrue($v->passes());
6429+
6430+
$v = new Validator($trans, ['from' => '2020-05-08', 'to' => '2020-08-05'], ['from' => 'date_format:Y-m-d', 'to' => 'date_format:Y-d-m|after_or_equal:from']);
6431+
$this->assertTrue($v->passes());
64206432
}
64216433

64226434
public function testSometimesAddingRules()

0 commit comments

Comments
 (0)
0