Development

Working with bank holidays with a Carbon wrapper

Working with dates in php is easy but working with bank holidays is a little more involved thankfully there is an awesome Carbon class that makes it super easy!

Getting setup requires composer:

composer require citco/carbon

Then to use it import it:

use Citco\Carbon;

Then you can initialise it and use it like this:

// Creates a new instance of the class
$c = new Carbon(); // Today's date

Get an array of bank holidays:

// Returns array of holidays for the given year
$c->getBankHolidays(2017);

To check if a date falls on a bank holiday it’s as simple as:

$boolean = $c->isBankHoliday('2017-03-28');

Returns the event when it’s a bank holiday and null for any other day.

Get the library from https://github.com/citco/carbon

 

David Carr

David Carr

For the past 12 years, I’ve been developing applications for the web using mostly PHP. I do this for a living and love what I do as every day there is something new and exciting to learn.

In my spare time, the web development community is a big part of my life. Whether managing online programming groups and blogs or attending a conference, I find keeping involved helps me stay up to date. This is also my chance to give back to the community that helped me get started, a place I am proud to be apart of.

Besides programming I love spending time with friends and family and can often be found together going out catching the latest movie, staying in playing games on the sofa or planning a trip to someplace I’ve never been before.