From e2ec2ce2a710d21455b8bfd0b9b26953b394cba9 Mon Sep 17 00:00:00 2001 From: FoxxMD Date: Fri, 25 Sep 2026 10:10:11 -0400 Subject: [PATCH] fix: date fallback when repo play has no playdate on comparison --- .../drizzle/repositories/PlayRepository.ts | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/backend/common/database/drizzle/repositories/PlayRepository.ts b/src/backend/common/database/drizzle/repositories/PlayRepository.ts index c7ab5c42..4e49f789 100644 --- a/src/backend/common/database/drizzle/repositories/PlayRepository.ts +++ b/src/backend/common/database/drizzle/repositories/PlayRepository.ts @@ -959,17 +959,19 @@ export const getTemporallyCloseDateCompareOp = (play: PlayObject, opts: {bufferT // make sure we use the const [sotPlayDate, SOT] = getScrobbleTsSOCDateWithContext(play); + const {playDate} = play.data; - if(useDuration && play.data.duration !== undefined) { + // if play has no playDate fallback to using SOT date (which defaults to now) + if(useDuration && play.data.duration !== undefined && playDate !== undefined) { if(SOT === SCROBBLE_TS_SOC_END) { - endRange = play.data.playDate!.add(bufferTime, 's'); - startRange = play.data.playDate!.subtract(play.data.duration + bufferTime,'s') + endRange = playDate.add(bufferTime, 's'); + startRange = playDate.subtract(play.data.duration + bufferTime,'s') } else { - endRange = play.data.playDate!.add(play.data.duration + bufferTime, 's'); - startRange = play.data.playDate!.subtract(bufferTime,'s') + endRange = playDate.add(play.data.duration + bufferTime, 's'); + startRange = playDate.subtract(bufferTime,'s') } - } else if(play.data.playDateCompleted !== undefined && useCompleted) { - startRange = play.data.playDate!.subtract(bufferTime, 's'); + } else if(play.data.playDateCompleted !== undefined && useCompleted && playDate !== undefined) { + startRange = playDate.subtract(bufferTime, 's'); // this will be present if source reports it // or we tracked it live with MemorySource endRange = play.data.playDateCompleted.add(bufferTime, 's'); -- 2.51.2