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)