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.

Updating Schedules

Because sometimes we might need to update our SLA Schedules over time – without invalidating existing SLA calculations, sla-timer allows us to update the SLA with a new SLASchedule that will commence after the effectiveFrom date provided.









 
 
 


// Create our initial schedule
$sla = SLA::fromSchedule(
    SLASchedule::create()->from('09:00:00')->to('09:01:00')
        ->everyDay()
);

// Add our new superseded schedule, only starting after 27 July 2022
$sla->addSchedule(
    SLASchedule::create()->effectiveFrom('27-07-2022')
        ->from('09:00:00')->to('09:00:30')->onWeekdays()->and()
        ->from('09:00:00')->to('09:00:10')->onWeekends()
);

Then if we run our duration method across both our old schedule and our new schedule.

// Given the time now is 14:00:00 31-07-2022
$sla->duration('08:35:40 25-07-2022')->totalSeconds; // 230
TablesOld ScheduleNew Schedule
25th July60s30s
26th July60s30s
27th July60s30s
28th July60s30s
29th July60s30s
30th July60s10s
31st July60s10s
Total120s110s
230s

Released under the MIT License.