diff --git a/app/Services/WorkingDays/Date/MonToFriWorkingDayDeterminer.php b/app/Services/WorkingDays/Date/MonToFriWorkingDayDeterminer.php new file mode 100644 index 0000000..303be3f --- /dev/null +++ b/app/Services/WorkingDays/Date/MonToFriWorkingDayDeterminer.php @@ -0,0 +1,37 @@ +format('N'); + return $weekday <= 5; // Monday to Friday + } + + public function getWorkingDaysCount(\DateTimeImmutable $startDate, int $workingDays): int + { + $period = new \DatePeriod($startDate, new \DateInterval('P1D'), $startDate->add(new \DateInterval(sprintf('P%dD', $workingDays)))); + $workingDaysCount = 0; + + foreach ($period as $date) { + if ($this->isWorkingDay($date)) { + $workingDaysCount++; + } + } + + return $workingDaysCount; + } +} diff --git a/app/Services/WorkingDays/WorkingDayDeterminerInterface.php b/app/Services/WorkingDays/WorkingDayDeterminerInterface.php new file mode 100644 index 0000000..ca6df45 --- /dev/null +++ b/app/Services/WorkingDays/WorkingDayDeterminerInterface.php @@ -0,0 +1,26 @@ +assertFalse($class->isWorkingDay(new \DateTimeImmutable("2024-01-0" . $day))); + } + + /** + * @return array> + */ + public static function nonWorkingDayProvider(): array + { + return [[6], [7]]; + } + + /** + * @return \Generator> + */ + public static function workingDayProvider(): \Generator + { + for ($isNWD = 0; $isNWD <= 1; $isNWD++) { + for ($x = 1; $x <= 5; $x++) { + yield [$x]; + } + } + } + + #[DataProvider('workingDayProvider')] + public function testIsWorkingDayWillCallIsNWDForWorkingDaysAndReturnValue(int $day): void + { + $class = new MonToFriWorkingDayDeterminer(); + + $this->assertSame(true, $class->isWorkingDay(new \DateTimeImmutable("2024-01-0" . $day))); + } +}