fork download
  1. <?php
  2.  
  3. $tests = [
  4. [
  5. "inicio" => "07:00:00",
  6. "final" => "09:00:00",
  7. "busca" => "08:00:00",
  8. "saida" => true
  9. ],[
  10. "inicio" => "19:00:00",
  11. "final" => "22:00:00",
  12. "busca" => "23:00:00",
  13. "saida" => false
  14. ],[
  15. "inicio" => "18:00:00",
  16. "final" => "03:00:00",
  17. "busca" => "01:00:00",
  18. "saida" => true
  19. ],
  20. ];
  21.  
  22. foreach($tests as $test)
  23. {
  24. $ininio = new DateTime($test["inicio"]);
  25. $final = new DateTime($test["final"]);
  26. $busca = new DateTime($test["busca"]);
  27.  
  28. if ($final <= $ininio) {
  29. $final->add(new DateInterval("P1D"));
  30. }
  31.  
  32. if ($busca <= $ininio) {
  33. $busca->add(new DateInterval("P1D"));
  34. }
  35.  
  36. if ($busca >= $ininio && $busca <= $final) {
  37. echo "Sim";
  38. } else {
  39. echo "Não";
  40. }
  41.  
  42. echo ", esperado " . ($test["saida"] ? "sim" : "não") . PHP_EOL;
  43. }
Success #stdin #stdout 0s 83904KB
stdin
Standard input is empty
stdout
Sim, esperado sim
Não, esperado não
Sim, esperado sim