Skip to content

Commit

Permalink
Merge pull request #88 from milwad-dev/remove-morilog-jalali
Browse files Browse the repository at this point in the history
[1.x] Remove `Morilog` dependency
  • Loading branch information
milwad-dev authored Apr 21, 2024
2 parents f49e23a + 7d7b7f7 commit 5c35e53
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
1 change: 0 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
"require": {
"php": "^8.0",
"laravel/framework": "9.*|10.*|11.*",
"morilog/jalali": "3.*",
"ext-bcmath": "*",
"ext-ctype": "*"
},
Expand Down
25 changes: 23 additions & 2 deletions src/Rules/ValidJalaliDate.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace Milwad\LaravelValidate\Rules;

use Illuminate\Contracts\Validation\Rule;
use Morilog\Jalali\CalendarUtils;

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

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

return CalendarUtils::checkDate(...$date);
return $this->checkValidDate(...$date);
}

/**
Expand All @@ -34,4 +33,26 @@ public function message()
{
return __('validate.jalali_date');
}

/**
* Checking whether the date is a Jalali date or not.
*/
protected function checkValidDate(string $year, string $month, string $day): bool
{
return ($year >= -61 && $year <= 3177)
&& ($month >= 1 && $month <= 12)
&& $day >= 1 && $day <= $this->jalaliMonthLength((int) $month);
}

/**
* Getting the number of days through the length of the month.
*/
protected function jalaliMonthLength(int $month): int
{
if ($month <= 6) {
return 31;
}

return 30; // TODO: Add 29 or 30 for some years
}
}

0 comments on commit 5c35e53

Please sign in to comment.