File tree Expand file tree Collapse file tree 2 files changed +23
-3
lines changed Expand file tree Collapse file tree 2 files changed +23
-3
lines changed Original file line number Diff line number Diff line change 2727 "require" : {
2828 "php" : " ^8.0" ,
2929 "laravel/framework" : " 9.*|10.*|11.*" ,
30- "morilog/jalali" : " 3.*" ,
3130 "ext-bcmath" : " *" ,
3231 "ext-ctype" : " *"
3332 },
Original file line number Diff line number Diff line change 33namespace Milwad \LaravelValidate \Rules ;
44
55use Illuminate \Contracts \Validation \Rule ;
6- use Morilog \Jalali \CalendarUtils ;
76
87class 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}
You can’t perform that action at this time.
0 commit comments