Skip to content

Commit 5c35e53

Browse files
authored
Merge pull request #88 from milwad-dev/remove-morilog-jalali
[1.x] Remove `Morilog` dependency
2 parents f49e23a + 7d7b7f7 commit 5c35e53

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

composer.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
"require": {
2828
"php": "^8.0",
2929
"laravel/framework": "9.*|10.*|11.*",
30-
"morilog/jalali": "3.*",
3130
"ext-bcmath": "*",
3231
"ext-ctype": "*"
3332
},

src/Rules/ValidJalaliDate.php

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
namespace Milwad\LaravelValidate\Rules;
44

55
use Illuminate\Contracts\Validation\Rule;
6-
use Morilog\Jalali\CalendarUtils;
76

87
class ValidJalaliDate implements Rule
98
{
@@ -22,7 +21,7 @@ public function passes($attribute, $value)
2221

2322
$date = explode('/', $value); // TODO: Add contruct for jalali date
2423

25-
return CalendarUtils::checkDate(...$date);
24+
return $this->checkValidDate(...$date);
2625
}
2726

2827
/**
@@ -34,4 +33,26 @@ public function message()
3433
{
3534
return __('validate.jalali_date');
3635
}
36+
37+
/**
38+
* Checking whether the date is a Jalali date or not.
39+
*/
40+
protected function checkValidDate(string $year, string $month, string $day): bool
41+
{
42+
return ($year >= -61 && $year <= 3177)
43+
&& ($month >= 1 && $month <= 12)
44+
&& $day >= 1 && $day <= $this->jalaliMonthLength((int) $month);
45+
}
46+
47+
/**
48+
* Getting the number of days through the length of the month.
49+
*/
50+
protected function jalaliMonthLength(int $month): int
51+
{
52+
if ($month <= 6) {
53+
return 31;
54+
}
55+
56+
return 30; // TODO: Add 29 or 30 for some years
57+
}
3758
}

0 commit comments

Comments
 (0)