How to find freetime slots during working hours of 8 to 17hrs given an array of busytime slots in a day using php

43 Views Asked by At

am trying to write a function to find freetime slots during working hours 8 - 17hrs

can anyone help with an algorithm please

Can anyone read this array using its index

      {
        "starttime": "07:30",
        "endtime": "08:30"
      },
      {
        "starttime": "11:00",
        "endtime": "11:30"
      },
      {
        "starttime": "14:00",
        "endtime": "15:00"
      }
    ]

forexample

for ($i = 0; $i < count($value); $i++) {
            $free = array();
            
            if ($value[$i]["starttime"] > $start_time) {
                $free['starttime'] = $start_time;
                $free['endtime'] = $value[$i]["starttime"];
            } else {
                if ($value[$i]["endtime"] > $start_time) {
                    $free['starttime'] = $value[$i]["endtime"];
                    $free['endtime'] = $value[$i + 1]["starttime"];
                } else {
                    $free['starttime'] = $start_time;
                    $free['endtime'] = $value[$i + 1]["starttime"];
                }
            }
            array_push($freetimes["free"], $freetimes);
        }

this way is not possible its not returning any result

0

There are 0 best solutions below