cmelda / holidays
Holidays and Name's day by country
Fund package maintenance!
Requires
- php: >=8.3
- ext-json: *
Requires (Dev)
- arxeiss/coding-standards: ^0.14
- codeception/codeception: ^5.1
- codeception/module-asserts: ^3
- phpstan/phpstan: ^2.0
- rector/rector: ^2.0
Suggests
- ext-calendar: *
- ext-intl: *
README
Install
composer require cmelda/holidays
List of available countries
Map legend: green = public holidays and name's days, orange = public holidays only.
Map source: Blank map of Europe (without disputed regions).svg, Wikimedia Commons, CC BY-SA 4.0.
Usage
Public Holiday
$holidays = new \Cmelda\Holidays\Holidays('cze');
$date = new DateTimeImmutable();
$day = $holidays->getDay($date);
try {
$publicHolidays = $day->getPublicHolidays();
} catch (\Cmelda\Holidays\Exceptions\NoPublicHolidayException $e) {
// no public holiday
}
Name's day
$holidays = new \Cmelda\Holidays\Holidays('cze');
$date = new DateTimeImmutable();
$day = $holidays->getDay($date);
try {
$names = $day->getNames();
} catch (\Cmelda\Holidays\Exceptions\NotImplementedException $e) {
// name-day calendar is not implemented for this country
} catch (\Cmelda\Holidays\Exceptions\NoNameException $e) {
// no name's day
}
Public holidays and name's days are maintained separately. A country can be supported
for public holidays even when its name's day calendar is not available; in that case
getPublicHolidays() works and getNames() throws NotImplementedException.
NoNameException is used only when a name's day calendar is implemented, but the
selected date has no name's day.
Name's day calendars are available only for countries that have a matching
src/names/{iso}.json data file. The supported countries map uses green for
countries with both public holidays and name's days, and orange for public
holidays only.
Day
$date = new DateTimeImmutable();
$day = new \Cmelda\Holidays\Day($date);
try {
$names = $day->getNames('cze');
} catch (\Cmelda\Holidays\Exceptions\NotImplementedException $e) {
// name-day calendar is not implemented for this country
} catch (\Cmelda\Holidays\Exceptions\NoNameException $e) {
// no name's day
}
try {
$names = $day->getNames('svk');
} catch (\Cmelda\Holidays\Exceptions\NotImplementedException $e) {
// name-day calendar is not implemented for this country
} catch (\Cmelda\Holidays\Exceptions\NoNameException $e) {
// no name's day
}
Business day calculation
use Cmelda\Holidays\BusinessDayCalculator;
$calculator = new BusinessDayCalculator('cze');
$calculator->isWeekend(new DateTimeImmutable('2024-12-21')); // true
$calculator->isHoliday(new DateTimeImmutable('2024-12-24')); // true
$calculator->isWorkingDay(new DateTimeImmutable('2024-12-27')); // true
$nextWorkingDay = $calculator->nextWorkingDay(new DateTimeImmutable('2024-12-24'));
echo $nextWorkingDay->format('Y-m-d'); // 2024-12-27
$afterOneWorkingDay = $calculator->addWorkingDays(
new DateTimeImmutable('2024-03-28'),
1,
);
echo $afterOneWorkingDay->format('Y-m-d'); // 2024-04-02
$includingStartDay = $calculator->addWorkingDays(
new DateTimeImmutable('2024-03-27'),
1,
true,
);
echo $includingStartDay->format('Y-m-d'); // 2024-03-27
If you need all calculations to use a specific timezone, pass it to the constructor:
use Cmelda\Holidays\BusinessDayCalculator;
$calculator = new BusinessDayCalculator(
'cze',
new DateTimeZone('Europe/Prague'),
);
License
Distributed under the MIT License. See LICENSE.txt for more information.

