Skip to content

Instantly share code, notes, and snippets.

@heiglandreas
Created October 13, 2022 10:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save heiglandreas/70d42fd251298679b9c13c1484d15fff to your computer and use it in GitHub Desktop.
Save heiglandreas/70d42fd251298679b9c13c1484d15fff to your computer and use it in GitHub Desktop.
<?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