Skip to content
Hi, I'm Alex & I'm currently looking for a Laravel job. Please reach out to me via twitter, or click this link.

Working with Holidays

The best way to work with Holidays is to use the Yasumi Holiday PHP Library (https://yasumi.dev).

Simply require the library using composer:

$ composer require azuyalabs/yasumi

Then iterate over each holiday and add it to the SLA's holiday periods.

require 'vendor/autoload.php';

use Yasumi\Yasumi;
use Sifex\SlaTimer\SLA;
use Sifex\SlaTimer\SLABreach;
use Sifex\SlaTimer\SLASchedule;

/**
 * Create a new SLA between 9am and 5:30pm weekdays
 */
$sla = SLA::fromSchedule(
    SLASchedule::create()->from('09:00:00')->to('17:30:00')
        ->onWeekdays()
);

$holidays = Yasumi::create('Australia', 2022);

// Add each holiday in 2022 to the SLA's list of Holidays
$sla->addHolidays($holidays->getHolidayDates());

Released under the MIT License.