sla-timer
sla-timer copied to clipboard
Library doesn't work, false result
Hello,
I'm attempting to utilize the library for calculating durations between two dates. Here's an example:
<?php
require 'vendor/autoload.php';
use Sifex\SlaTimer\SLA;
use Sifex\SlaTimer\SLABreach;
use Sifex\SlaTimer\SLASchedule;
/**
* Create a new SLA between 9am and 5:00pm weekdays
*/
$sla = SLA::fromSchedule(
SLASchedule::create()->from('09:00:00')->to('17:00:00')->onWeekdays()
);
$dateTime_start = DateTime::createFromFormat('H:i:s d-m-Y', '16:58:00 01-12-2023');
$dateTime_start->setTimezone(new DateTimeZone('UTC'));
$utcFormat_start = $dateTime_start->format('H:i:s d-m-Y');
$dateTime_end = DateTime::createFromFormat('H:i:s d-m-Y', '09:01:01 04-12-2023');
$dateTime_end->setTimezone(new DateTimeZone('UTC'));
$utcFormat_end = $dateTime_end->format('H:i:s d-m-Y');
$duration = $sla->duration($utcFormat_start, $utcFormat_end);
var_dump($duration->totalSeconds);
var_dump($duration->forHumans());
Output :
int(120)
string(9) "2 minutes"
The expected result is 3 minutes 1 second. Can you help me understand why it's calculating this way?