Oh Dear is the all-in-one monitoring tool for your entire website. We monitor uptime, SSL certificates, broken links, scheduled tasks and more. You'll get a notifications for us when something's wrong. All that paired with a developer friendly API and kick-ass documentation. O, and you'll also be able to create a public status page under a minute. Start monitoring using our free trial now.

A mini package to calculate public holidays in a country

Original – by Freek Van der Herten – 2 minute read

We released a mini package called spatie/holidays that can calculate the public holidays of a country.

ou can get all holidays for a country by using the get method.

use Spatie\Holidays\Holiday;

// returns an array of Belgian holidays
// for the current year
$holidays = Holidays::for('be')->get(); 

Alternatively, you could also pass an instance of Country to the for method.

use Spatie\Holidays\Holiday;
use Spatie\Holidays\Countries\Belgium;

// returns an array of Belgian holidays
// for the current year
$holidays = Holidays::for(Belgium::make())->get(); 

You can also pass a specific year.

use Spatie\Holidays\Holiday;

$holidays = Holidays::for(country: 'be', year: 2024))->get();

If you need to see if a date is a holiday, you can use the isHoliday method.

use Spatie\Holidays\Holiday;

Holidays::for('be')->isHoliday('2024-01-01'); // true

If you need the name of the holiday, you can use the getName method.

use Spatie\Holidays\Holiday;

Holidays::for('be')->getName('2024-01-01'); // Nieuwjaar

In closing

We've made this package for our own needs and packaged it, so you don't have to code it up in your project. You can see a list of all packages we've made previously on our company website.

Share Post LinkedIn

I write about Laravel, PHP, AI and building better software.

Every two weeks, I share practical tips, tutorials, and behind-the-scenes insights from maintaining 300+ open source packages. Join thousands of developers who read along.

No spam. Unsubscribe anytime. You can also follow me on X.

Found something interesting to share?

The community section is a place where developers share links to articles, tutorials and videos. Submit a link and help fellow developers discover great content. As a thank you, you'll receive a coupon for a discount on Spatie products.