Created
October 13, 2022 10:16
-
-
Save heiglandreas/70d42fd251298679b9c13c1484d15fff to your computer and use it in GitHub Desktop.
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
<?php | |
use Org_Heigl\Holidaychecker\Holidaychecker; | |
use Org_Heigl\Holidaychecker\HolidayIteratorFactory; | |
$factory = new HolidayIteratorFactory(); | |
$iterator = $factory->createIteratorFromISO3166('DE'); | |
$checker = new Holidaychecker($iterator); | |
$startDate = new DateTimeImmutable('2022-10-10'); | |
$endDate = new DateTimeImmutable('2022-10-31'); | |
$dateIterator = new DatePeriod( | |
$startDate, | |
new DateInterval('P1D'), | |
$endDate | |
); | |
$numberOfBusinessDays = 0; | |
foreach ($dateIterator as $date) { | |
if ($checker->check($date)->isHoliday()) { | |
continue; | |
} | |
// Your business-Logic here | |
$numberOfBusinessDays++; | |
} | |
echo sprintf( | |
'There are %1$d business-days between %2$s and %3$s', | |
$numberOfBusinessDays, | |
$startDate->format('d.m.Y'), | |
$endDate->format('d.m.Y'), | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment