'Compute the instant when this job should run next.'

def _schedule_next_run(self):

    assert (self.unit in ('seconds', 'minutes', 'hours', 'days', 'weeks'))
    self.period = datetime.timedelta(**{self.unit: self.interval})
    self.next_run = (datetime.datetime.now() + self.period)
    if (self.start_day is not None):
        assert (self.unit == 'weeks')
        weekdays = ('monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sunday')
        assert (self.start_day in weekdays)
        weekday = weekdays.index(self.start_day)
        days_ahead = (weekday - self.next_run.weekday())
        if (days_ahead <= 0):
            days_ahead += 7
        self.next_run += (datetime.timedelta(days_ahead) - self.period)
    if (self.at_time is not None):
        assert ((self.unit in ('days', 'hours')) or (self.start_day is not None))
        kwargs = {'minute': self.at_time.minute, 'second': self.at_time.second, 'microsecond': 0}
        if ((self.unit == 'days') or (self.start_day is not None)):
            kwargs['hour'] = self.at_time.hour
        self.next_run = self.next_run.replace(**kwargs)
        if (not self.last_run):
            now = datetime.datetime.now()
            if ((self.unit == 'days') and (self.at_time > now.time()) and (self.interval == 1)):
                self.next_run = (self.next_run - datetime.timedelta(days=1))
            elif ((self.unit == 'hours') and (self.at_time.minute > now.minute)):
                self.next_run = (self.next_run - datetime.timedelta(hours=1))
    if ((self.start_day is not None) and (self.at_time is not None)):
        if ((self.next_run - datetime.datetime.now()).days >= 7):
            self.next_run -= self.period
