spatie/holidays
Calculate public holidays for supported countries using ISO codes or country classes. Get an array of Holiday objects with name, CarbonImmutable date, and type (e.g., national). PHP 8.4+ package by Spatie, with extensible country definitions.
JsonSerializable), enabling easy API responses or CLI tooling.DE-BW for Baden-Württemberg) may require explicit handling. Validate coverage for target markets upfront.CarbonImmutable usage).Spatie\Holidays\Holidays to an interface).Holiday::for('us')->get()).config() bindings)./api/holidays?country=de&year=2025).composer require spatie/holidays "^2.3"
// config/app.php
'providers' => [
// ... other providers
Spatie\Holidays\HolidaysServiceProvider::class,
];
Or manually bind:
$this->app->singleton(Holidays::class, fn() => new Holidays());
config/holidays.php (if extending the package).carbon/carbon v2.60+ (included with Laravel 10+). For older Laravel, ensure Carbon is updated.Holidays::for(country: 'us', year: 2024)), which may require PHP 8.4+.Holidays::for('us')->get()).JsonSerializable output for API use.Holidays::for('us', region: 'CA')).[] or log).src/Countries/ and CountryRegistry.php.Holidays::has('zz') to pre-check).(country, year, region, locale) to avoid recomputation.$key = "holidays:{$country}:{$year}:{$region}:{$locale}";
return Cache::remember($key, now()->addYear(), fn() => Holidays::for($country, $year, $region, $locale)->get());
| Failure Scenario | Impact | Mitigation |
|---|---|---|
| Unsupported country | Exception or empty data | Pre-check with Holidays::has() |
| PHP 8.4+ requirement | Integration fails on older PHP | Upgrade PHP or fork the package |
| Holiday data inaccuracies | Business logic errors (e.g., payroll) | Validate against official sources |
| Regional holiday misconfig | Wrong holidays for a region | Test all target regions explicitly |
| Cache stampede | High CPU/memory during cache misses | Use probabilistic early expiration |
Holidays::for('us')->get() works.getInRange(), isHoliday()).Usage.md to the project for internal conventions (e.g., caching strategies).How can I help you explore Laravel packages today?