Skip to content

Library doesn't work, false result #6

@vipera7

Description

@vipera7

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions