<?php
define("NEE", 99);
define("KAN", 1);
define("LIEVER_NIET", 2);
define("JA", 0);
$excludedRanges = [
['2017-07-20', '2017-07-21', 'Python', NEE],
['2017-08-14', '2017-08-15', 'Python', NEE],
['2017-09-04', '2017-09-08', 'Joris en de Draak', NEE],
['2017-09-04', '2017-11-28', 'De Tuinman en de Fakir', KAN],
['2017-09-04', '2017-09-04', 'Spookslot', JA],
['2017-09-11', '2017-09-22', 'Fata Morgana', LIEVER_NIET],
['2017-09-11', '2017-12-01', 'Python', KAN],
['2017-09-11', '2017-09-15', 'De Oude Tufferbaan', JA],
['2017-09-25', '2017-09-29', 'Carnaval Festival', KAN],
['2017-10-02', '2017-10-06', 'Villa Volta', JA],
['2017-10-02', '2017-10-13', 'Gondoletta', JA],
['2017-10-07', '2017-10-13', 'Aquanura', KAN],
];
$startDate = '2017-09-01';
$endDate = '2017-12-31';
$startDay = date('z', strtotime($startDate));
$endDay = date('z', strtotime($endDate));
# Only wednesdays and fridays
$acceptedDays = [3, 5];
for($i = $startDay, $j = 0; $i <= $endDay; $i++, $j++) {
$date = date("Y-m-d", strtotime($startDate . " +" . $j . ' days'));
$dayOfWeek = date("w", strtotime($date));
if (!in_array($dayOfWeek, $acceptedDays)) {
continue;
}
if (($closed = isAnAttractionClosed($i, $excludedRanges)) !== false) {
$highest = getHighestAnswer($i, $excludedRanges);
echo date("d-m-Y", strtotime($date)) . ': ' . getClosedAttractions($i, $excludedRanges) . ' gesloten. ';
switch ($highest) {
case NEE:
echo 'Nee.';
break;
case KAN:
echo 'Kan.';
break;
case LIEVER_NIET:
echo 'Liever niet.';
break;
default:
echo 'Ja.';
break;
}
echo PHP_EOL;
continue;
}
echo date("d-m-Y", strtotime($date)) . ': Ja' . PHP_EOL;
}
/**
* @param int $dayOfTheYear
* @param array $closedAttractions
* @return bool
*/
function isAnAttractionClosed($dayOfTheYear, $closedAttractions) {
foreach ($closedAttractions as $closed) {
$start = date('z', strtotime($closed[0]));
$end = date('z', strtotime($closed[1]));
if ($dayOfTheYear >= $start && $dayOfTheYear <= $end) {
return $closed;
}
}
return false;
}
function getHighestAnswer($dayOfTheYear, $closedAttractions) {
$highest = JA;
foreach ($closedAttractions as $closed) {
$start = date('z', strtotime($closed[0]));
$end = date('z', strtotime($closed[1]));
if ($dayOfTheYear >= $start && $dayOfTheYear <= $end) {
if ($closed[3] > $highest) {
$highest = $closed[3];
}
}
}
return $highest;
}
function getClosedAttractions($dayOfTheYear, $closedAttractions) {
$attractions = '';
foreach ($closedAttractions as $closed) {
$start = date('z', strtotime($closed[0]));
$end = date('z', strtotime($closed[1]));
if ($dayOfTheYear >= $start && $dayOfTheYear <= $end) {
$attractions .= $closed[2] . ', ';
}
}
return rtrim($attractions, ', ');
}
preferences:
50.63 ms | 402 KiB | 5 Q