Fixed StringInputLength validation
This commit is contained in:
parent
b99e6ed8c1
commit
0188ed5562
|
@ -2,9 +2,9 @@
|
|||
|
||||
namespace Engelsystem\Http\Validation\Rules;
|
||||
|
||||
use Engelsystem\Helpers\Carbon;
|
||||
use DateTime;
|
||||
use Exception;
|
||||
use Illuminate\Support\Str;
|
||||
use Throwable;
|
||||
|
||||
trait StringInputLength
|
||||
{
|
||||
|
@ -27,11 +27,13 @@ trait StringInputLength
|
|||
protected function isDateTime(mixed $input): bool
|
||||
{
|
||||
try {
|
||||
$date = Carbon::make($input);
|
||||
} catch (Throwable $e) {
|
||||
return false;
|
||||
$input = new DateTime($input);
|
||||
// Min 1s diff to exclude any not auto-detected dates / times like ...
|
||||
return abs((new DateTime())->diff($input)->format('%s')) > 1;
|
||||
} catch (Exception $e) {
|
||||
// Ignore it
|
||||
}
|
||||
|
||||
return !is_null($date);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,6 +28,7 @@ class StringInputLengthTest extends TestCase
|
|||
return [
|
||||
['TEST', 4],
|
||||
['?', 1],
|
||||
['', 0],
|
||||
['2042-01-01 00:00', '2042-01-01 00:00'],
|
||||
['2042-01-01', '2042-01-01'],
|
||||
['12:42', '12:42'],
|
||||
|
@ -35,6 +36,11 @@ class StringInputLengthTest extends TestCase
|
|||
['...', 3],
|
||||
['Test Tester', 11],
|
||||
['com', 3],
|
||||
['Test', 4],
|
||||
['H', 1],
|
||||
['3', 3],
|
||||
[42, 42],
|
||||
[99.3, 99.3],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue