From bce4fca72005cf6134e31f4e3a858a40ee64f7f9 Mon Sep 17 00:00:00 2001 From: Fabio Ivona Date: Mon, 15 Jan 2024 11:00:40 +0100 Subject: [PATCH] allow to include saturday as workday --- .gitignore | 1 + src/SuperchargedCarbonServiceProvider.php | 18 +++++++++++------- 2 files changed, 12 insertions(+), 7 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..17fb143 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/composer.lock diff --git a/src/SuperchargedCarbonServiceProvider.php b/src/SuperchargedCarbonServiceProvider.php index 1a0e929..72532e9 100644 --- a/src/SuperchargedCarbonServiceProvider.php +++ b/src/SuperchargedCarbonServiceProvider.php @@ -11,8 +11,8 @@ namespace Defstudio\SuperchargedCarbon; -use Carbon\Carbon\CarbonInterface; use Carbon\CarbonImmutable; +use Carbon\CarbonInterface; use Illuminate\Support\Carbon; use Illuminate\Support\ServiceProvider; @@ -129,8 +129,12 @@ public function register() } - $holiday_closure = function () use ($holidays) { - if (!$this->isWeekday()) { + $holiday_closure = function (bool $saturdayIsWorkday = false) use ($holidays) { + if($this->isSaturday()){ + if(!$saturdayIsWorkday){ + return true; + } + }elseif ($this->isSunday()) { return true; } @@ -143,14 +147,14 @@ public function register() return false; }; - $workday_closure = function () { - return !$this->isHoliday(); + $workday_closure = function (bool $saturdayIsWorkday = false) { + return !$this->isHoliday($saturdayIsWorkday); }; - $add_workdays_closure = function ($days_to_add = 1) { + $add_workdays_closure = function (int $days_to_add = 1, bool $saturdayIsWorkday = false) { while ($days_to_add > 0) { $this->addDay(); - if ($this->isWorkday()) { + if ($this->isWorkday($saturdayIsWorkday)) { $days_to_add--; } }