Skip to content

Commit 61a3618

Browse files
committed
Update ValidJalaliDate.php
1 parent d5ba2b9 commit 61a3618

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/Rules/ValidJalaliDate.php

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

55
use Illuminate\Contracts\Validation\Rule;
6+
use Illuminate\Support\Carbon;
67

78
class ValidJalaliDate implements Rule
89
{
@@ -40,22 +41,25 @@ public function message(): string
4041
/**
4142
* Checking whether the date is a Jalali date or not.
4243
*/
43-
protected function checkValidDate(string $year, string $month, string $day): bool
44+
protected function checkValidDate(int $year, int $month, int $day): bool
4445
{
4546
return ($year >= -61 && $year <= 3177)
4647
&& ($month >= 1 && $month <= 12)
47-
&& $day >= 1 && $day <= $this->jalaliMonthLength((int) $month);
48+
&& $day >= 1 && $day <= $this->jalaliMonthLength($year, $month, $year);
4849
}
4950

5051
/**
5152
* Getting the number of days through the length of the month.
5253
*/
53-
protected function jalaliMonthLength(int $month): int
54+
protected function jalaliMonthLength(int $year, int $month, int $day): int
5455
{
56+
if (Carbon::createFromDate($year, $month, $day)->isLeapYear() && $month === 12) {
57+
return 29;
58+
}
5559
if ($month <= 6) {
5660
return 31;
5761
}
5862

59-
return 30; // TODO: Add 29 or 30 for some years
63+
return 30;
6064
}
6165
}

0 commit comments

Comments
 (0)