generated from spatie/package-skeleton-php
- Sponsor
-
Notifications
You must be signed in to change notification settings - Fork 199
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
move Observed holiday logic to separate trait
1 parent
2f9a616
commit a564053
Showing
6 changed files
with
140 additions
and
131 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
|
||
namespace Spatie\Holidays\Concerns; | ||
|
||
use Carbon\CarbonImmutable; | ||
use Carbon\CarbonInterface; | ||
|
||
trait Observable | ||
{ | ||
protected function observedChristmasDay(int $year): ?CarbonInterface | ||
{ | ||
$christmasDay = (new CarbonImmutable($year.'-12-25'))->startOfDay(); | ||
|
||
return match ($christmasDay->dayName) { | ||
'Saturday' => $christmasDay->next('monday'), | ||
'Sunday' => $christmasDay->next('tuesday'), | ||
default => null, | ||
}; | ||
} | ||
|
||
protected function observedBoxingDay(int $year): ?CarbonInterface | ||
{ | ||
$christmasDay = (new CarbonImmutable($year.'-12-25'))->startOfDay(); | ||
$boxingDay = $christmasDay->addDay(); | ||
|
||
return match ($christmasDay->dayName) { | ||
'Friday' => $boxingDay->next('monday'), | ||
'Saturday' => $boxingDay->next('tuesday'), | ||
default => null, | ||
}; | ||
} | ||
|
||
protected function weekendToNextMonday(string|CarbonInterface $date, int $year): ?CarbonInterface | ||
{ | ||
if (is_string($date)) { | ||
$date = CarbonImmutable::createFromFormat('Y-m-d', "{$year}-{$date}")->startOfDay(); | ||
} | ||
|
||
if ($date->isWeekend()) { | ||
return $date->next('monday'); | ||
} | ||
|
||
return null; | ||
} | ||
|
||
protected function sundayToNextMonday(CarbonInterface $date): ?CarbonInterface | ||
{ | ||
if ($date->isSunday()) { | ||
return $date->next('monday'); | ||
} | ||
|
||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters