From 708ecb1aa6c8dedade2bccbc92e42bacfa204e83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Gr=C3=B6ger?= Date: Sun, 1 Mar 2020 21:44:38 +0100 Subject: [PATCH] fixed bug ##206 bug fix that the --- geruecht/controller/userController.py | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/geruecht/controller/userController.py b/geruecht/controller/userController.py index 5d912c4..8578da7 100644 --- a/geruecht/controller/userController.py +++ b/geruecht/controller/userController.py @@ -78,17 +78,25 @@ class UserController(metaclass=Singleton): def getLockedDay(self, date): now = datetime.now() - daysInMonth = calendar.monthrange(date.year, date.month)[1] - startMonth = 1 + oldMonth = False for i in range(1, 8): - if datetime(date.year, date.month, i).weekday() == 2: - startMonth = i + if datetime(now.year, now.month, i).weekday() == 2: + if now.day < i: + oldMonth = True + break + lockedYear = date.year + lockedMonth = date.month if date.month < now.month else now.month - 1 if oldMonth else now.month + daysInMonth = calendar.monthrange(lockedYear, lockedMonth)[1] + startDay = 1 + for i in range(1, 8): + if datetime(lockedYear, lockedMonth, i).weekday() == 2: + startDay = i break - if date.year <= now.year and date.month <= now.month: - for i in range(startMonth, daysInMonth + 1): - self.setLockedDay(datetime(date.year, date.month, i), True) + if lockedYear <= now.year and lockedMonth <= now.month: + for i in range(startDay, daysInMonth + 1): + self.setLockedDay(datetime(lockedYear, lockedMonth, i), True) for i in range(1, 8): - nextMonth = datetime(date.year, date.month + 1, i) + nextMonth = datetime(lockedYear, lockedMonth + 1, i) if nextMonth.weekday() == 2: break self.setLockedDay(nextMonth, True)