File tree Expand file tree Collapse file tree 1 file changed +8
-4
lines changed Expand file tree Collapse file tree 1 file changed +8
-4
lines changed Original file line number Diff line number Diff line change 33namespace Milwad \LaravelValidate \Rules ;
44
55use Illuminate \Contracts \Validation \Rule ;
6+ use Illuminate \Support \Carbon ;
67
78class 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}
You can’t perform that action at this time.
0 commit comments