fork download
  1. <?php
  2.  
  3. $internalEvents = array(
  4. "start" => "03/29/2016 12:00:00",
  5. "end" => "03/29/2016 13:00:00"
  6. ),
  7. "start" => "03/29/2016 12:30:00",
  8. "end" => "03/29/2016 13:30:00"
  9. ),
  10. "start" => "03/29/2016 13:00:00",
  11. "end" => "03/29/2016 14:00:00"
  12. ),
  13. "start" => "03/29/2016 13:30:00",
  14. "end" => "03/29/2016 14:50:00"
  15. ),
  16. "start" => "03/29/2016 14:00:00",
  17. "end" => "03/29/2016 15:00:00"
  18. ),
  19. "start" => "03/29/2016 14:30:00",
  20. "end" => "03/29/2016 15:30:00"
  21. ),
  22. "start" => "03/29/2016 15:00:00",
  23. "end" => "03/29/2016 16:00:00"
  24. ),
  25. "start" => "03/29/2016 15:30:00",
  26. "end" => "03/29/2016 16:30:00"
  27. ),
  28. "start" => "03/29/2016 16:00:00",
  29. "end" => "03/29/2016 17:00:00"
  30. )
  31. );
  32.  
  33. $externalEvents = array(
  34. "start" => "03/29/2016 08:00:00",
  35. "end" => "03/29/2016 12:00:00"
  36. ),
  37. "start" => "03/29/2016 15:30:00",
  38. "end" => "03/29/2016 16:00:00"
  39. ),
  40. "start" => "03/29/2016 13:30:00",
  41. "end" => "03/29/2016 14:15:00"
  42. )
  43. );
  44.  
  45. foreach($internalEvents as $internalEvent) {
  46.  
  47. $internalEventStart = new DateTime($internalEvent['start']);
  48. $internalEventEnd = new DateTime($internalEvent['end']);
  49.  
  50. $result = true;
  51.  
  52. echo "\nverifying " . $internalEventStart->format('Y-m-d H:i') . " - " . $internalEventEnd->format('Y-m-d H:i') . "\n";
  53.  
  54. foreach($externalEvents as $externalEvent) {
  55. $externalEventStart = new DateTime($externalEvent['start']);
  56. $externalEventEnd = new DateTime($externalEvent['end']);
  57.  
  58. // check if there are conflicts between internal and external events
  59. if ($internalEventStart >= $externalEventStart && $internalEventStart <= $externalEventEnd) {
  60. $result = false;
  61. echo " problem 1: event is between busy time: " . "\n";
  62. }
  63.  
  64. if ($internalEventStart >= $externalEventStart && $internalEventStart <= $externalEventEnd && $externalEventEnd <= $internalEventEnd) {
  65. $result = false;
  66. echo " problem 2: event starts during busy time: " . "\n";
  67. }
  68.  
  69. if ($internalEventStart <= $externalEventStart && $externalEventStart <= $internalEventEnd && $internalEventEnd <= $externalEventEnd) {
  70. $result = false;
  71. echo " problem 3: event stops during busy time: " . "\n";
  72. }
  73.  
  74. if (($internalEventStart <= $externalEventStart) && ($externalEventStart <= $externalEventEnd) && ($externalEventEnd <= $internalEventEnd)) {
  75. $result = false;
  76. echo " problem 4: event during busy time: " . "\n";
  77. }
  78.  
  79. if (($internalEventStart <= $internalEventEnd) && ($internalEventEnd <= $externalEventStart) && ($externalEventStart <= $externalEventEnd)) {
  80. $result = false;
  81. echo " problem 5: event during busy time: " . "\n";
  82. }
  83. }
  84.  
  85. if($result) {
  86. echo " result: OK\n";
  87. } else {
  88. echo " result: NOT OK \n";
  89. }
  90. }
Success #stdin #stdout 0.03s 52432KB
stdin
Standard input is empty
stdout
verifying 2016-03-29 12:00 - 2016-03-29 13:00
   problem 1: event is between busy time: 
   problem 2: event starts during busy time: 
   problem 5: event during busy time: 
   problem 5: event during busy time: 
   result: NOT OK 

verifying 2016-03-29 12:30 - 2016-03-29 13:30
   problem 5: event during busy time: 
   problem 3: event stops during busy time: 
   problem 5: event during busy time: 
   result: NOT OK 

verifying 2016-03-29 13:00 - 2016-03-29 14:00
   problem 5: event during busy time: 
   problem 3: event stops during busy time: 
   result: NOT OK 

verifying 2016-03-29 13:30 - 2016-03-29 14:50
   problem 5: event during busy time: 
   problem 1: event is between busy time: 
   problem 2: event starts during busy time: 
   problem 4: event during busy time: 
   result: NOT OK 

verifying 2016-03-29 14:00 - 2016-03-29 15:00
   problem 5: event during busy time: 
   problem 1: event is between busy time: 
   problem 2: event starts during busy time: 
   result: NOT OK 

verifying 2016-03-29 14:30 - 2016-03-29 15:30
   problem 3: event stops during busy time: 
   problem 5: event during busy time: 
   result: NOT OK 

verifying 2016-03-29 15:00 - 2016-03-29 16:00
   problem 3: event stops during busy time: 
   problem 4: event during busy time: 
   result: NOT OK 

verifying 2016-03-29 15:30 - 2016-03-29 16:30
   problem 1: event is between busy time: 
   problem 2: event starts during busy time: 
   problem 4: event during busy time: 
   result: NOT OK 

verifying 2016-03-29 16:00 - 2016-03-29 17:00
   problem 1: event is between busy time: 
   problem 2: event starts during busy time: 
   result: NOT OK