From a68ffa20c59ffb5c6c38357adee222e2870e3b27 Mon Sep 17 00:00:00 2001 From: Raz Date: Fri, 11 Oct 2024 09:17:18 +0200 Subject: [PATCH] fix scheduler when rotation start date is too early no matter what, so delay the startdate to a new computed startdate --- PadelClub/Data/MatchScheduler.swift | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/PadelClub/Data/MatchScheduler.swift b/PadelClub/Data/MatchScheduler.swift index 2ef29f9..b1518af 100644 --- a/PadelClub/Data/MatchScheduler.swift +++ b/PadelClub/Data/MatchScheduler.swift @@ -493,13 +493,23 @@ final class MatchScheduler : ModelObject, Storable { let timeDifferenceLimitInSeconds = Double(timeDifferenceLimit * 60) var difference = differenceWithBreak - if differenceWithBreak <= 0 { + if differenceWithBreak <= 0, accountUpperBracketBreakTime == false { difference = differenceWithoutBreak } else if differenceWithBreak > timeDifferenceLimitInSeconds && differenceWithoutBreak > timeDifferenceLimitInSeconds { difference = noBreakAlreadyTested ? differenceWithBreak : max(differenceWithBreak, differenceWithoutBreak) } - if difference > timeDifferenceLimitInSeconds && rotationStartDate.addingTimeInterval(-difference) != previousEndDate { + print("Final difference to evaluate: \(difference)") + + if (difference > timeDifferenceLimitInSeconds && rotationStartDate.addingTimeInterval(-difference) != previousEndDate) || difference < 0 { + print(""" + Adjusting rotation start: + - Initial rotationStartDate: \(rotationStartDate) + - Adjusted by difference: \(difference) + - Adjusted rotationStartDate: \(rotationStartDate.addingTimeInterval(-difference)) + - PreviousEndDate: \(previousEndDate) + """) + courts.removeAll(where: { freeCourtPreviousRotation.contains($0) }) freeCourtPerRotation[rotationIndex] = courts courts = freeCourtPreviousRotation