Exemplo n.º 1
0
 def _addMonth(self, dateTime):
     year, month, day = dateTime.year, dateTime.month, dateTime.day
     details = dateTime.hour, dateTime.minute, dateTime.second, dateTime.microsecond
     if month == 12:  # If December, move to January next year
         year += 1
         month = 1
     else:
         month += 1
     if self.sameWeekday:
         weekday = dateTime.weekday()
         weekNr = min(
             3, (day - 1) / 7
         )  # In what week of the month falls aDate, allowable range 0-3
         day = weekNr * 7 + 1  # The earliest possible day that is on the same weekday as aDate
         result = date.DateTime(year, month, day, *details)
         while result.weekday() != weekday:
             day += 1
             result = date.DateTime(year, month, day, *details)
         return result
     else:
         while True:  # Find a valid date in the next month
             try:
                 return date.DateTime(year, month, day, *details)
             except ValueError:
                 day -= 1
Exemplo n.º 2
0
 def onFirstObserverRegisteredFor(self, event):
     if event.value().startswith('clock.time.'):
         dateTimeString = event.value().split('.')[-1]
         dateTimeTuple = time.strptime(dateTimeString, self.timeFormat)[:6]
         dateTime = dateandtime.DateTime(
             *dateTimeTuple)  # pylint: disable-msg=W0142
         self._scheduledTimer.schedule(dateTime)
Exemplo n.º 3
0
 def _nextDateTime(self, dateTime, amount=0):
     if date.DateTime() == dateTime or not self.unit:
         return dateTime
     amount = amount or self.amount
     if amount > 1:
         dateTime = self._nextDateTime(dateTime, amount - 1)
     if self.unit == 'yearly':
         return self._addYear(dateTime)
     elif self.unit == 'monthly':
         return self._addMonth(dateTime)
     else:
         return self._addDays(dateTime)
Exemplo n.º 4
0
 def __init__(self,
              unit='',
              amount=1,
              sameWeekday=False,
              maximum=0,
              count=0,
              stop_datetime=None,
              recurBasedOnCompletion=False):
     assert unit in self.units
     assert amount >= 1
     self.unit = unit
     self.amount = amount
     self.stop_datetime = stop_datetime or date.DateTime()
     self.sameWeekday = sameWeekday
     # Maximum number of recurrences we give out, 0 == infinite:
     self.max = maximum
     self.count = count  # Actual number of recurrences given out so far
     self.recurBasedOnCompletion = recurBasedOnCompletion