44 lines
1.6 KiB
PHP
44 lines
1.6 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Services\WorkingDays\PublicHolidays;
|
|
|
|
use App\Models\NonWorkingDays;
|
|
use App\Services\WorkingDays\PublicHolidays\Storage\PublicHolidaysStorageInterface;
|
|
use App\Services\WorkingDays\WorkingDayDeterminerInterface;
|
|
|
|
class PublicHolidaysStateDeterminer implements PublicHolidaysStateDeterminerInterface, PublicHolidaysStateStorageInterface, WorkingDayDeterminerInterface
|
|
{
|
|
public function __construct(
|
|
protected readonly PublicHolidaysStorageInterface $publicHolidaysStorage,
|
|
protected readonly string $country
|
|
) {
|
|
}
|
|
|
|
public function isPublicHoliday(\DateTimeImmutable $publicHolidayDate): bool
|
|
{
|
|
return $this->publicHolidaysStorage->isPublicHoliday($this->country, $publicHolidayDate);
|
|
}
|
|
|
|
public function storePublicHoliday(\DateTimeImmutable $publicHolidayDate): ?NonWorkingDays
|
|
{
|
|
return $this->publicHolidaysStorage->storePublicHoliday($this->country, $publicHolidayDate);
|
|
}
|
|
|
|
public function isWorkingDay(\DateTimeImmutable $date): bool
|
|
{
|
|
return !$this->isPublicHoliday($date);
|
|
}
|
|
|
|
public function getPublicHolidaysInInterval(\DateTimeImmutable $startDate, \DateTimeImmutable $endDate): array
|
|
{
|
|
return $this->publicHolidaysStorage->getPublicHolidaysInInterval($this->country, $startDate, $endDate);
|
|
}
|
|
|
|
public function getWorkingDaysCount(\DateTimeImmutable $startDate, int $workingDays): int
|
|
{
|
|
return $workingDays - $this->publicHolidaysStorage->countPublicHolidaysInInterval($this->country, $startDate, $startDate->add(new \DateInterval(sprintf('P%dD', $workingDays))));
|
|
}
|
|
}
|