Skip to content

Commit

Permalink
allow to include saturday as workday
Browse files Browse the repository at this point in the history
  • Loading branch information
fabio-ivona committed Jan 15, 2024
1 parent 0b3987f commit bce4fca
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/composer.lock
18 changes: 11 additions & 7 deletions src/SuperchargedCarbonServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
}

Expand All @@ -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--;
}
}
Expand Down

0 comments on commit bce4fca

Please sign in to comment.