diff --git a/application/controllers/Contestcalendar.php b/application/controllers/Contestcalendar.php index 8b32b44bd..1ca2ade1c 100644 --- a/application/controllers/Contestcalendar.php +++ b/application/controllers/Contestcalendar.php @@ -148,24 +148,30 @@ class Contestcalendar extends CI_Controller { private function contestsNextWeekend($rss) { $contestsNextWeekend = array(); - + $today = date('Y-m-d'); - - $nextFriday = date('Y-m-d', strtotime('next friday', strtotime($today))); - $nextSunday = date('Y-m-d', strtotime('next sunday', strtotime($today))); - + $currentDayOfWeek = date('N', strtotime($today)); + + if ($currentDayOfWeek >= 1 && $currentDayOfWeek <= 4) { + $nextFriday = date('Y-m-d', strtotime('next friday', strtotime($today))); + $nextSunday = date('Y-m-d', strtotime('next sunday', strtotime($today))); + } else { + $nextFriday = date('Y-m-d', strtotime('friday this week', strtotime($today))); + $nextSunday = date('Y-m-d', strtotime('sunday this week', strtotime($today))); + } + foreach ($rss as $contest) { if (!($contest['start'] instanceof DateTime)) { log_message('debug',"Invalid Time format for contest: " . $contest['title']); continue; } $start = date('Y-m-d', strtotime($contest['start']->format('Y-m-d'))); - - if ($start >= $nextFriday && $start <= $nextSunday) { + + if ($start >= $nextFriday && $start <= $nextSunday && $start >= $today) { $contestsNextWeekend[] = $contest; } } - + return $contestsNextWeekend; }