From 029f3d5917b11a0152550597a67bd1b79f94eb11 Mon Sep 17 00:00:00 2001 From: Milwad Date: Sun, 21 Apr 2024 17:32:44 +0330 Subject: [PATCH 1/3] Update ValidJalaliDate.php --- src/Rules/ValidJalaliDate.php | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/src/Rules/ValidJalaliDate.php b/src/Rules/ValidJalaliDate.php index 6f7d9bf5..0bee345f 100644 --- a/src/Rules/ValidJalaliDate.php +++ b/src/Rules/ValidJalaliDate.php @@ -3,7 +3,6 @@ namespace Milwad\LaravelValidate\Rules; use Illuminate\Contracts\Validation\Rule; -use Morilog\Jalali\CalendarUtils; class ValidJalaliDate implements Rule { @@ -22,7 +21,7 @@ public function passes($attribute, $value) $date = explode('/', $value); // TODO: Add contruct for jalali date - return CalendarUtils::checkDate(...$date); + return $this->checkValidDate(...$date); } /** @@ -34,4 +33,26 @@ public function message() { return __('validate.jalali_date'); } + + /** + * Checking whether the date is a Jalali date or not. + */ + protected function checkValidDate(string $year, string $month, string $day): bool + { + return ($year >= -61 && $year <= 3177) + && ($month >= 1 && $month <= 12) + && $day >= 1 && $day <= $this->jalaliMonthLength((int)$month); + } + + /** + * Getting the number of days through the length of the month. + */ + protected function jalaliMonthLength(int $month): int + { + if ($month <= 6) { + return 31; + } + + return 30; // TODO: Add 29 or 30 for some years + } } From cf6114a17d304cafb77100267057d866c005223b Mon Sep 17 00:00:00 2001 From: Milwad Date: Sun, 21 Apr 2024 17:34:47 +0330 Subject: [PATCH 2/3] remove `morilog/jalali` dependency --- composer.json | 1 - 1 file changed, 1 deletion(-) diff --git a/composer.json b/composer.json index d15ec12c..3540a25c 100644 --- a/composer.json +++ b/composer.json @@ -27,7 +27,6 @@ "require": { "php": "^8.0", "laravel/framework": "9.*|10.*|11.*", - "morilog/jalali": "3.*", "ext-bcmath": "*", "ext-ctype": "*" }, From 7d7b7f78c75cbd270fdd39ba520304656b6c383c Mon Sep 17 00:00:00 2001 From: milwad-dev Date: Sun, 21 Apr 2024 14:05:10 +0000 Subject: [PATCH 3/3] Fix styling --- src/Rules/ValidJalaliDate.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Rules/ValidJalaliDate.php b/src/Rules/ValidJalaliDate.php index 0bee345f..8078a7fc 100644 --- a/src/Rules/ValidJalaliDate.php +++ b/src/Rules/ValidJalaliDate.php @@ -41,7 +41,7 @@ protected function checkValidDate(string $year, string $month, string $day): boo { return ($year >= -61 && $year <= 3177) && ($month >= 1 && $month <= 12) - && $day >= 1 && $day <= $this->jalaliMonthLength((int)$month); + && $day >= 1 && $day <= $this->jalaliMonthLength((int) $month); } /**