Skip to content

Commit dae3765

Browse files
authored
Remove midnight KO filtering on World Cup matches (#1854)
1 parent c8f61a5 commit dae3765

2 files changed

Lines changed: 40 additions & 9 deletions

File tree

football/src/main/scala/com/gu/mobile/notifications/football/lib/FootballData.scala

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package com.gu.mobile.notifications.football.lib
22

3-
import java.time.{LocalDate, ZonedDateTime}
3+
import java.time.{LocalDate, LocalTime, ZonedDateTime}
44
import com.gu.mobile.notifications.football.{Configuration, Logging}
55
import com.gu.mobile.notifications.football.models.RawMatchData
66
import 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

football/src/test/scala/com/gu/mobile/notifications/football/lib/FootballDataSpec.scala

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,4 +177,24 @@ class FootballDataSpec extends Specification {
177177
footballData.paProvideAlerts(matchWith("303", roundNumber = "Final")) must beTrue
178178
}
179179
}
180+
181+
"isMidnight" should {
182+
183+
val footballData = new FootballData(null, null, null, "test")
184+
185+
"return true for a non-exempt competition kicking off at 00:00" in new FootballDataScope {
186+
val m = matchDayWithCompetition("100").copy(date = ZonedDateTime.parse("2026-05-18T00:00:00Z"))
187+
footballData.isFakeMidnightKO(m) must beTrue
188+
}
189+
190+
"return false for a non-exempt competition kicking off at a non-midnight time" in new FootballDataScope {
191+
val m = matchDayWithCompetition("100").copy(date = ZonedDateTime.parse("2026-05-18T15:00:00Z"))
192+
footballData.isFakeMidnightKO(m) must beFalse
193+
}
194+
195+
"return false for the World Cup (700) kicking off at 00:00" in new FootballDataScope {
196+
val m = matchDayWithCompetition("700").copy(date = ZonedDateTime.parse("2026-05-18T00:00:00Z"))
197+
footballData.isFakeMidnightKO(m) must beFalse
198+
}
199+
}
180200
}

0 commit comments

Comments
 (0)