<?php
$excludedRanges = [
['2017-07-20', '2017-07-21', 'Python', true],
['2017-08-14', '2017-08-15', 'Python', true],
['2017-09-04', '2017-09-08', 'Joris en de Draak', true],
['2017-09-04', '2017-11-28', 'De Tuinman en de Fakir', false],
['2017-09-04', '2017-09-04', 'Spookslot', false],
['2017-09-11', '2017-09-22', 'Fata Morgana', true],
['2017-09-11', '2017-12-01', 'Python', true],
['2017-09-11', '2017-09-15', 'De Oude Tufferbaan', false],
['2017-09-25', '2017-09-29', 'Carnaval Festival', false],
['2017-10-02', '2017-10-06', 'Villa Volta', false],
['2017-10-02', '2017-10-13', 'Gondoletta', false],
['2017-10-07', '2017-10-13', 'Aquanura', false],
];
$startDate = '2017-09-01';
$endDate = '2017-11-30';
$startDay = date('z', strtotime($startDate));
$endDay = date('z', strtotime($endDate));
for($i = $startDay, $j = 0; $i <= $endDay; $i++, $j++) {
$date = date("Y-m-d", strtotime($startDate . " +" . $j . ' days'));
$dayOfWeek = date("w", strtotime($date));
# Only wednesdays and saturdays
if ($dayOfWeek !== 3 || $dayOfWeek !== 5) {
continue;
}
if (($closed = isAnAttractionClosed($i, $excludedRanges)) !== false) {
echo $date . ': ' . $closed[2] . ' gesloten. ' . ($closed[3] ? 'Nee' : 'Liever niet') . PHP_EOL;
continue;
}
echo $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;
}
preferences:
45.55 ms | 402 KiB | 5 Q