Skip to content

Commit 029f3d5

Browse files
committed
Update ValidJalaliDate.php
1 parent f49e23a commit 029f3d5

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

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)