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.
php
// 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.
php
// Given the time now is 14:00:00 31-07-2022
$sla->duration('08:35:40 25-07-2022')->totalSeconds; // 230| Tables | Old Schedule | New Schedule |
|---|---|---|
| 25th July | 60s | 30s |
| 26th July | 60s | 30s |
| 27th July | 60s | 30s |
| 28th July | 60s | 30s |
| 29th July | 60s | 30s |
| 30th July | 60s | 10s |
| 31st July | 60s | 10s |
| Total | 120s | 110s |
| 230s | ||