Last active
July 7, 2016 13:59
-
-
Save lfbittencourt/b40e1499bbc550a3066c0ca1fe80d8c8 to your computer and use it in GitHub Desktop.
Time range clashing scenarios
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Assumes that the lower and upper bounds are exclusive | |
$scenarios = [ | |
// [AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA] | |
// [BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB] | |
['14:00', '15:00', '14:00', '15:00', true], | |
// [AAAAAAAAAAAAAAAAAAAAA] | |
// [BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB] | |
['14:20', '14:40', '14:00', '15:00', true], | |
// [AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA] | |
// [BBBBBBBBBBBBBBBBBBBBB] | |
['14:00', '15:00', '14:20', '14:40', true], | |
// [AAAAAAAAAAA] | |
// [BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB] | |
['14:00', '14:20', '14:00', '15:00', true], | |
// [AAAAAAAAAAAAAAAAAAA] | |
// [BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB] | |
['14:40', '15:00', '14:00', '15:00', true], | |
// [AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA] | |
// [BBBBBBBBBBBBBBBBBBBBB] | |
['14:00', '15:00', '14:00', '14:20', true], | |
// [AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA] | |
// [BBBBBBBBBBBBBBBBBBBBB] | |
['14:00', '15:00', '14:40', '15:00', true], | |
// [AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA] | |
// [BBBBBBBBBBBBBBBBBBBBBBBBBBBBBB] | |
['14:20', '15:20', '14:00', '15:00', true], | |
// [AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA] | |
// [BBBBBBBBBBBBBBBBBBBBBBBBBBBBBB] | |
['14:00', '15:00', '14:20', '15:20', true], | |
// [AAAAAAAAAAAAAAAAAA] | |
// [BBBBBBBBBBBBBBBBBB] | |
['13:00', '14:00', '14:00', '15:00', false], | |
// [AAAAAAAAAAAAAAAAAA] | |
// [BBBBBBBBBBBBBBBBBB] | |
['15:00', '16:00', '14:00', '15:00', false], | |
// [AAAAAAAAAAAAAAA] | |
// [BBBBBBBBBBBBBBB] | |
['13:00', '14:00', '15:00', '16:00', false], | |
// [AAAAAAAAAAAAAAA] | |
// [BBBBBBBBBBBBBBB] | |
['15:00', '16:00', '13:00', '14:00', false], | |
]; | |
foreach ($scenarios as $scenario) { | |
list($a1, $a2, $b1, $b2, $expectedResult) = $scenario; | |
$result = $a1 < $b2 && $a2 > $b1; | |
echo "$a1 < $b2 && $a2 > $b1 === ", | |
$result ? 'true' : 'false', | |
" (expected result was ", | |
$expectedResult ? 'true' : 'false', | |
")", | |
PHP_EOL; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
PS: assumes that lower and upper bounds are exclusive. If you wish to include that, change the
<
and>
operators to<=
and=>
. Refer to http://stackoverflow.com/a/325964/1102265.