11package com .gu .mobile .notifications .football .lib
22
3- import java .time .{LocalDate , ZonedDateTime }
3+ import java .time .{LocalDate , LocalTime , ZonedDateTime }
44import com .gu .mobile .notifications .football .{Configuration , Logging }
55import com .gu .mobile .notifications .football .models .RawMatchData
66import org .joda .time .DateTime
@@ -124,17 +124,28 @@ class FootballData(
124124 .getOrElse(false ) // Shouldn't ever happen
125125 }
126126
127+
128+ /**
129+ * PA give 00:00 as the start time when they don't actually know the kickoff time yet,
130+ * so those matches are unusable and should be filtered out. Competitions in
131+ * `competitionsAllowingMidnightKO` are excluded from this check because a 00:00 kickoff can be
132+ * genuine for them (e.g. the World Cup, whose schedule spans multiple time zones and is
133+ * published months in advance).
134+ */
135+ private val competitionsAllowingMidnightKO = Set (
136+ " 700" , // FIFA World Cup
137+ " 701" , // FIFA World Cup qualifying
138+ " 714" , // Copa America
139+ )
140+ private [lib] def isFakeMidnightKO (matchDay : MatchDay ): Boolean = {
141+ val isAllowlisted = matchDay.competition.exists(c => competitionsAllowingMidnightKO.contains(c.id))
142+ ! isAllowlisted && matchDay.date.toLocalTime == LocalTime .MIDNIGHT
143+ }
144+
127145 def matchIdsInProgress (dateTime : ZonedDateTime ): Future [List [MatchDay ]] = {
128146 def inProgress (m : MatchDay ): Boolean =
129147 m.date.minusHours(2 ).isBefore(dateTime) && m.date.plusHours(4 ).isAfter(dateTime)
130148
131- // unfortunately PA provide 00:00 as start date when they don't have the start date
132- // so we can't do anything with these matches
133- def isMidnight (matchDay : MatchDay ): Boolean = {
134- val localDate = matchDay.date.toLocalTime
135- localDate.getHour() == 0 && localDate.getMinute() == 0
136- }
137-
138149 logger.info(s " Retrieving matches on or around $dateTime from PA " )
139150 for {
140151 matches <- paClient.aroundToday(dateTime)
@@ -154,7 +165,7 @@ class FootballData(
154165 matchesInSupportedCompetitions
155166 .filter(inProgress)
156167 .filter(paProvideAlerts)
157- .filterNot(isMidnight )
168+ .filterNot(isFakeMidnightKO )
158169 }
159170 }
160171
0 commit comments