Exemplo n.º 1
0
 def __sub__(self, other):
     ''' Make sure substraction returns instances of the right classes. '''
     if self == DateTime() and isinstance(other, datetime.datetime):
         max = timedelta.TimeDelta.max
         return timedelta.TimeDelta(max.days, max.seconds, max.microseconds)
     result = super(DateTime, self).__sub__(other)
     if isinstance(result, datetime.timedelta):
         result = timedelta.TimeDelta(result.days, result.seconds,
                                      result.microseconds)
     elif isinstance(result, datetime.datetime):
         result = self.__class__(result.year, result.month, result.day,
                                 result.hour, result.minute, result.second,
                                 result.microsecond)
     return result
Exemplo n.º 2
0
 def __sub__(self, other):
     newdate = super(RealDate, self).__sub__(other)
     if isinstance(newdate, datetime.timedelta):
         return timedelta.TimeDelta(newdate.days, newdate.seconds,
                                    newdate.microseconds)
     else:
         return RealDate(newdate.year, newdate.month, newdate.day)
Exemplo n.º 3
0
 def __init__(self, callback, period):
     assert period in self.periodsAllowed
     self._period = timedelta.TimeDelta(**{period + 's':
                                           1})  # pylint: disable-msg=W0142
     self._resetToStartOfPeriodArguments = self._startOfPeriodArguments(
         period)
     self._onceTimer = OnceTimer(self._startFiringEveryPeriod)
     super(PeriodicTimer, self).__init__(callback)
Exemplo n.º 4
0
 def _addYear(self, dateTime):
     if (calendar.isleap(dateTime.year) and dateTime.month <= 2 and dateTime.day <=28) or \
        (calendar.isleap(dateTime.year + 1) and dateTime.month >=3):
         days = 366
     else:
         days = 365
     newDateTime = dateTime + timedelta.TimeDelta(days=days)
     if self.sameWeekday:
         # Find the nearest date in newDate's year that is on the right
         # weekday:
         weekday, year = dateTime.weekday(), newDateTime.year
         oneDay = timedelta.TimeDelta(days=1)
         newEarlierDateTime = newLaterDateTime = newDateTime
         while newEarlierDateTime.weekday() != weekday:
             newEarlierDateTime = newEarlierDateTime - oneDay
         while newLaterDateTime.weekday() != weekday:
             newLaterDateTime = newLaterDateTime + oneDay
         if newEarlierDateTime.year != year:
             newDateTime = newLaterDateTime
         else:
             newDateTime = newEarlierDateTime
     return newDateTime
Exemplo n.º 5
0
    def schedule(self, function, dateTime):
        proxy = ScheduledMethod(function)

        def callback():
            if proxy in self.__jobs:
                del self.__jobs[proxy]
            wx.CallAfter(proxy)

        if dateTime <= dateandtime.Now() + timedelta.TimeDelta(
                milliseconds=500):
            callback()
        else:
            self.__jobs[proxy] = job = self.add_date_job(callback,
                                                         dateTime,
                                                         misfire_grace_time=0)
            return job
Exemplo n.º 6
0
 def _addDays(self, dateTime):
     nrOfDays = dict(daily=1, weekly=7)[self.unit]
     return dateTime + timedelta.TimeDelta(days=nrOfDays)
Exemplo n.º 7
0
 def endOfWorkWeek(self):
     days = 5 - self.weekday()
     if days < 0:
         days += 7
     friday = self + timedelta.TimeDelta(days=days)
     return DateTime(friday.year, friday.month, friday.day).endOfDay()
Exemplo n.º 8
0
 def endOfWeek(self):
     days = self.weekday()
     sunday = self + timedelta.TimeDelta(days=7 - days)
     return DateTime(sunday.year, sunday.month, sunday.day).endOfDay()
Exemplo n.º 9
0
 def startOfWeek(self):
     days = self.weekday()
     monday = self - timedelta.TimeDelta(days=days - 1)
     return DateTime(monday.year, monday.month, monday.day)
Exemplo n.º 10
0
 def endOfYesterday(self):
     return self.endOfDay() - timedelta.TimeDelta(days=1)
Exemplo n.º 11
0
 def endOfTomorrow(self):
     return self.endOfDay() + timedelta.TimeDelta(days=1)
Exemplo n.º 12
0
 def __sub__(self, other):
     if isinstance(other, InfiniteDate):
         return timedelta.TimeDelta()
     else:
         return timedelta.TimeDelta.max
Exemplo n.º 13
0
 def schedule_interval(self, function, days=0, minutes=0, seconds=0):
     job = ScheduledMethod(function)
     if not self.__scheduler.isScheduled(job):
         startDate = dateandtime.Now().endOfDay() if days > 0 else None
         self.__scheduler.scheduleInterval(job, timedelta.TimeDelta(days=days, minutes=minutes, seconds=seconds), startDateTime=startDate)
         return job