diff --git a/server/src/uds/core/util/calendar/__init__.py b/server/src/uds/core/util/calendar/__init__.py index 50ba4044f..df74b431c 100644 --- a/server/src/uds/core/util/calendar/__init__.py +++ b/server/src/uds/core/util/calendar/__init__.py @@ -46,8 +46,7 @@ import six import bitarray import logging -__updated__ = '2017-11-06' - +__updated__ = '2017-12-12' logger = logging.getLogger(__name__) @@ -113,7 +112,6 @@ class CalendarChecker(object): return data - def _updateEvents(self, checkFrom, startEvent=True): next_event = None @@ -162,7 +160,7 @@ class CalendarChecker(object): Returns next event for this interval Returns a list of two elements. First is datetime of event begining, second is timedelta of duration ''' - logger.debug('Obtainint nextEvent') + logger.debug('Obtaining nextEvent') if checkFrom is None: checkFrom = getSqlDatetime() @@ -183,6 +181,5 @@ class CalendarChecker(object): return next_event - def debug(self): return "Calendar checker for {}".format(self.calendar) diff --git a/server/src/uds/models/CalendarRule.py b/server/src/uds/models/CalendarRule.py index 8cbb4fb6c..cb2754f2c 100644 --- a/server/src/uds/models/CalendarRule.py +++ b/server/src/uds/models/CalendarRule.py @@ -33,7 +33,7 @@ from __future__ import unicode_literals -__updated__ = '2017-11-06' +__updated__ = '2017-12-12' from django.db import models from django.utils.encoding import python_2_unicode_compatible @@ -116,6 +116,8 @@ class CalendarRule(UUIDModel): if self.interval == 0: # Fix 0 intervals self.interval = 1 + end = datetime.datetime.combine(self.end if self.end is not None else datetime.datetime.max.date(), datetime.datetime.max.time()); + if self.frequency == WEEKDAYS: dw = [] l = self.interval @@ -123,11 +125,16 @@ class CalendarRule(UUIDModel): if l & 1 == 1: dw.append(weekdays[i]) l >>= 1 - return rules.rrule(rules.DAILY, byweekday=dw, dtstart=self.start) + return rules.rrule(rules.DAILY, byweekday=dw, dtstart=self.start, until=end) else: - return rules.rrule(frq_to_rrl[self.frequency], interval=self.interval, dtstart=self.start) + return rules.rrule(frq_to_rrl[self.frequency], interval=self.interval, dtstart=self.start, until=end) def as_rrule_end(self): + if self.interval == 0: # Fix 0 intervals + self.interval = 1 + + end = datetime.datetime.combine(self.end if self.end is not None else datetime.datetime.max.date(), datetime.datetime.max.time()); + if self.frequency == WEEKDAYS: dw = [] l = self.interval @@ -135,9 +142,9 @@ class CalendarRule(UUIDModel): if l & 1 == 1: dw.append(weekdays[i]) l >>= 1 - return rules.rrule(rules.DAILY, byweekday=dw, dtstart=self.start + datetime.timedelta(minutes=self.duration_as_minutes)) + return rules.rrule(rules.DAILY, byweekday=dw, dtstart=self.start + datetime.timedelta(minutes=self.duration_as_minutes), until=end) else: - return rules.rrule(frq_to_rrl[self.frequency], interval=self.interval, dtstart=self.start + datetime.timedelta(minutes=self.duration_as_minutes)) + return rules.rrule(frq_to_rrl[self.frequency], interval=self.interval, dtstart=self.start + datetime.timedelta(minutes=self.duration_as_minutes), until=end) @property def frequency_as_minutes(self):