<?php
$tests = [
[
"inicio" => "07:00:00",
"final" => "09:00:00",
"busca" => "08:00:00",
"saida" => true
],[
"inicio" => "19:00:00",
"final" => "22:00:00",
"busca" => "23:00:00",
"saida" => false
],[
"inicio" => "18:00:00",
"final" => "03:00:00",
"busca" => "01:00:00",
"saida" => true
],
];
foreach($tests as $test)
{
$ininio = new DateTime($test["inicio"]);
$final = new DateTime($test["final"]);
$busca = new DateTime($test["busca"]);
if ($final <= $ininio) {
$final->add(new DateInterval("P1D"));
}
if ($busca <= $ininio) {
$busca->add(new DateInterval("P1D"));
}
if ($busca >= $ininio && $busca <= $final) {
echo "Sim";
} else {
echo "Não";
}
echo ", esperado " . ($test["saida"] ? "sim" : "não") . PHP_EOL;
}
PD9waHAKCiR0ZXN0cyA9IFsKICBbCiAgICAiaW5pY2lvIiA9PiAiMDc6MDA6MDAiLCAKICAgICJmaW5hbCIgID0+ICIwOTowMDowMCIsCiAgICAiYnVzY2EiICA9PiAiMDg6MDA6MDAiLAogICAgInNhaWRhIiAgPT4gdHJ1ZQogIF0sWwogICAgImluaWNpbyIgPT4gIjE5OjAwOjAwIiwgCiAgICAiZmluYWwiICA9PiAiMjI6MDA6MDAiLAogICAgImJ1c2NhIiAgPT4gIjIzOjAwOjAwIiwKICAgICJzYWlkYSIgID0+IGZhbHNlCiAgXSxbCiAgICAiaW5pY2lvIiA9PiAiMTg6MDA6MDAiLCAKICAgICJmaW5hbCIgID0+ICIwMzowMDowMCIsCiAgICAiYnVzY2EiICA9PiAiMDE6MDA6MDAiLAogICAgInNhaWRhIiAgPT4gdHJ1ZQogIF0sCl07Cgpmb3JlYWNoKCR0ZXN0cyBhcyAkdGVzdCkKewogICRpbmluaW8gPSBuZXcgRGF0ZVRpbWUoJHRlc3RbImluaWNpbyJdKTsKICAkZmluYWwgID0gbmV3IERhdGVUaW1lKCR0ZXN0WyJmaW5hbCJdKTsKICAkYnVzY2EgID0gbmV3IERhdGVUaW1lKCR0ZXN0WyJidXNjYSJdKTsKICA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