Skip to content

Commit 5cd3e76

Browse files
authored
Merge pull request #44 from ingenerator/fix-date-validation-from-null
Allow date validation to accept null
2 parents 96ad7a5 + 993e7d7 commit 5cd3e76

File tree

3 files changed

+12
-23
lines changed

3 files changed

+12
-23
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
### Unreleased
22

3+
### v1.17.1 (2022-10-28)
4+
5+
* Fix deprecation warning when passing NULL to date validator by casting
6+
to empty string to maintain current behaviour.
7+
38
### v1.17.0 (2022-10-14)
49

510
* Support PHP 8.2

src/Validation/StrictDate.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ public static function iso_date($value)
131131

132132
protected static function is_datetime_format($format, $value)
133133
{
134-
$dt = \DateTimeImmutable::createFromFormat($format, $value);
134+
$dt = \DateTimeImmutable::createFromFormat($format, (string) $value);
135135

136136
return ($dt AND ($dt->format($format) === $value));
137137
}

test/unit/Validation/StrictDateTest.php

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ class StrictDateTest extends TestCase
1616

1717
/**
1818
* @testWith ["", false]
19+
* [null, false]
1920
* ["junk", false]
2021
* ["01/10/01", false]
2122
* ["2016-01-01", false]
@@ -32,6 +33,7 @@ public function test_it_validates_iso_datetime($value, $expect)
3233

3334
/**
3435
* @testWith ["", false]
36+
* [null, false]
3537
* ["junk", false]
3638
* ["01/10/01", false]
3739
* ["2016-01-45", false]
@@ -107,28 +109,10 @@ public function test_date_compare_funcs_validate_invalid_input($data, $from_fiel
107109
);
108110
}
109111

110-
public function provider_date_after_date()
111-
{
112-
return [
113-
// Invalid inputs all true as they should be caught by other rules
114-
// Simple > the first one
115-
[
116-
['a' => new \DateTimeImmutable, 'b' => new \DateTimeImmutable('-5 mins')],
117-
'a',
118-
'b',
119-
FALSE
120-
],
121-
[
122-
['a' => new \DateTimeImmutable('-5 mins'), 'b' => new \DateTimeImmutable],
123-
'a',
124-
'b',
125-
TRUE
126-
],
127-
];
128-
}
129-
130112
/**
131113
* @testWith ["", "-5 mins", false]
114+
* [null, "", true]
115+
* ["", null, true]
132116
* ["-5 mins", "", true]
133117
*/
134118
public function test_it_validates_date_after_date($from, $to, $expect)
@@ -138,8 +122,8 @@ public function test_it_validates_date_after_date($from, $to, $expect)
138122
StrictDate::date_after(
139123
new \ArrayObject(
140124
[
141-
'from' => new \DateTimeImmutable($from),
142-
'to' => new \DateTimeImmutable($to)
125+
'from' => new \DateTimeImmutable((string) $from),
126+
'to' => new \DateTimeImmutable((string) $to)
143127
]
144128
),
145129
'from',

0 commit comments

Comments
 (0)