From 37a26c123e1baba5d15ee03b377dc4416f28594e Mon Sep 17 00:00:00 2001 From: Igor Scheller Date: Sat, 21 Jan 2023 01:41:55 +0100 Subject: [PATCH] Validation: Fixed worklog comment: ... --- src/Controllers/Admin/UserWorkLogController.php | 2 +- src/Http/Validation/Rules/StringInputLength.php | 6 +++--- tests/Unit/Http/Validation/Rules/StringInputLengthTest.php | 5 +++++ 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/Controllers/Admin/UserWorkLogController.php b/src/Controllers/Admin/UserWorkLogController.php index 3e62467a..56f6aa6f 100644 --- a/src/Controllers/Admin/UserWorkLogController.php +++ b/src/Controllers/Admin/UserWorkLogController.php @@ -140,7 +140,7 @@ class UserWorkLogController extends BaseController 'work_hours' => $work_hours, 'comment' => $comment, 'is_edit' => $is_edit, - ] + ] + $this->getNotifications() ); } diff --git a/src/Http/Validation/Rules/StringInputLength.php b/src/Http/Validation/Rules/StringInputLength.php index f3726874..3b23fcd6 100644 --- a/src/Http/Validation/Rules/StringInputLength.php +++ b/src/Http/Validation/Rules/StringInputLength.php @@ -2,7 +2,7 @@ namespace Engelsystem\Http\Validation\Rules; -use DateTime; +use Engelsystem\Helpers\Carbon; use Illuminate\Support\Str; use Throwable; @@ -27,11 +27,11 @@ trait StringInputLength protected function isDateTime(mixed $input): bool { try { - new DateTime($input); + $date = Carbon::make($input); } catch (Throwable $e) { return false; } - return true; + return !is_null($date); } } diff --git a/tests/Unit/Http/Validation/Rules/StringInputLengthTest.php b/tests/Unit/Http/Validation/Rules/StringInputLengthTest.php index 26c68079..0a2b2c22 100644 --- a/tests/Unit/Http/Validation/Rules/StringInputLengthTest.php +++ b/tests/Unit/Http/Validation/Rules/StringInputLengthTest.php @@ -29,7 +29,12 @@ class StringInputLengthTest extends TestCase ['TEST', 4], ['?', 1], ['2042-01-01 00:00', '2042-01-01 00:00'], + ['2042-01-01', '2042-01-01'], + ['12:42', '12:42'], ['3', '3'], + ['...', 3], + ['Test Tester', 11], + ['com', 3], ]; } }