diff --git a/app/Services/WorkingDays/PublicHolidays/Generator/PublicHolidaysCzechGenerator.php b/app/Services/WorkingDays/PublicHolidays/Generator/PublicHolidaysCzechGenerator.php new file mode 100644 index 0000000..a65133c --- /dev/null +++ b/app/Services/WorkingDays/PublicHolidays/Generator/PublicHolidaysCzechGenerator.php @@ -0,0 +1,57 @@ +getEasterDateTime($year); + $result[] = $easters->add(new \DateInterval("P1D")); // easter Monday + $result[] = $easters->sub(new \DateInterval("P2D")); // easter Friday + + array_multisort($result, SORT_ASC); + + return $result; + } + + private function getEasterDateTime(int $year): \DateTimeImmutable + { + $base = new \DateTime("$year-03-21"); + $days = \easter_days($year); + + return \DateTimeImmutable::createFromInterface($base->add(new \DateInterval("P{$days}D"))); + } +} diff --git a/app/Services/WorkingDays/PublicHolidays/Generator/PublicHolidaysGenerator.php b/app/Services/WorkingDays/PublicHolidays/Generator/PublicHolidaysGenerator.php new file mode 100644 index 0000000..34e2b01 --- /dev/null +++ b/app/Services/WorkingDays/PublicHolidays/Generator/PublicHolidaysGenerator.php @@ -0,0 +1,18 @@ + new PublicHolidaysCzechGenerator(), + default => throw new \RuntimeException('Unsupported country code'), + }; + } +} diff --git a/tests/Unit/Services/WorkingDays/PublicHolidays/Generator/PublicHolidaysCzechGeneratorTest.php b/tests/Unit/Services/WorkingDays/PublicHolidays/Generator/PublicHolidaysCzechGeneratorTest.php new file mode 100644 index 0000000..d87903d --- /dev/null +++ b/tests/Unit/Services/WorkingDays/PublicHolidays/Generator/PublicHolidaysCzechGeneratorTest.php @@ -0,0 +1,33 @@ +generatePublicHolidaysForYear(2025); + $this->assertEquals([ + new \DateTimeImmutable("2025-01-01"), + new \DateTimeImmutable("2025-04-18"), + new \DateTimeImmutable("2025-04-21"), + new \DateTimeImmutable("2025-05-01"), + new \DateTimeImmutable("2025-05-08"), + new \DateTimeImmutable("2025-07-05"), + new \DateTimeImmutable("2025-07-06"), + new \DateTimeImmutable("2025-09-28"), + new \DateTimeImmutable("2025-10-28"), + new \DateTimeImmutable("2025-11-17"), + new \DateTimeImmutable("2025-12-24"), + new \DateTimeImmutable("2025-12-25"), + new \DateTimeImmutable("2025-12-26"), + ], $czechNWD); + } +} diff --git a/tests/Unit/Services/WorkingDays/PublicHolidaysGeneratorFactoryTest.php b/tests/Unit/Services/WorkingDays/PublicHolidaysGeneratorFactoryTest.php new file mode 100644 index 0000000..0f624d5 --- /dev/null +++ b/tests/Unit/Services/WorkingDays/PublicHolidaysGeneratorFactoryTest.php @@ -0,0 +1,25 @@ +assertInstanceOf(PublicHolidaysCzechGenerator::class, $factory->createPublicHolidaysGeneratorForCountry('CZ')); + } + + public function testRuntimeExceptionGeneratedForUnknownState(): void + { + $factory = new PublicHolidaysGeneratorFactory(); + $this->expectException(\RuntimeException::class); + $factory->createPublicHolidaysGeneratorForCountry('XZ'); + } +}