Пример #1
0
    def get_next_invalid_day(self, timestamp):
        """Get next day where timerange is not active

        :param timestamp: time we compute from
        :type timestamp: int
        :return: timestamp of the next invalid day (midnight) in LOCAL time.
        :rtype: int | None
        """
        # print "Look in", self.__dict__
        # print 'DR: get_next_invalid_day for', time.asctime(time.localtime(t))
        if self.is_time_day_invalid(timestamp):
            # print "EARLY RETURN"
            return timestamp

        next_future_timerange_invalid = self.get_next_future_timerange_invalid(
            timestamp)
        # print "next_future_timerange_invalid:", next_future_timerange_invalid

        # If today there is no more unavailable timerange, search the next day
        if next_future_timerange_invalid is None:
            # print 'DR: get_next_future_timerange_invalid is None'
            # this day is finish, we check for next period
            (start_time,
             end_time) = self.get_start_and_end_time(get_day(timestamp))
        else:
            # print 'DR: get_next_future_timerange_invalid is',
            # print time.asctime(time.localtime(next_future_timerange_invalid))
            (start_time, end_time) = self.get_start_and_end_time(timestamp)

        # (start_time, end_time) = self.get_start_and_end_time(t)

        # print "START", time.asctime(time.localtime(start_time)),
        # print "END", time.asctime(time.localtime(end_time))
        # The next invalid day can be t day if there a possible
        # invalid time range (timerange is not 00->24
        if next_future_timerange_invalid is not None:
            if start_time <= timestamp <= end_time:
                # print "Early Return next invalid day:", time.asctime(time.localtime(get_day(t)))
                return get_day(timestamp)
            if start_time >= timestamp:
                # print "start_time >= t:", time.asctime(time.localtime(get_day(start_time)))
                return get_day(start_time)
        else:
            # Else, there is no possibility than in our start_time<->end_time we got
            # any invalid time (full period out). So it's end_time+1 sec (tomorrow of end_time)
            return get_day(end_time + 1)

        return None
Пример #2
0
    def get_next_valid_time_from_t(self, timestamp):
        """Get next valid time for time range

        :param timestamp: time we compute from
        :type timestamp: int
        :return: timestamp of the next valid time (LOCAL TIME)
        :rtype: int | None
        """
        if self.is_time_valid(timestamp):
            return timestamp

        # First we search for the day of t
        t_day = self.get_next_valid_day(timestamp)

        # We search for the min of all tr.start > sec_from_morning
        # if it's the next day, use a start of the day search for timerange
        if timestamp < t_day:
            sec_from_morning = self.get_next_future_timerange_valid(t_day)
        else:  # it is in this day, so look from t (can be in the evening or so)
            sec_from_morning = self.get_next_future_timerange_valid(timestamp)

        if sec_from_morning is not None:
            if t_day is not None and sec_from_morning is not None:
                return t_day + sec_from_morning

        # Then we search for the next day of t
        # The sec will be the min of the day
        timestamp = get_day(timestamp) + 86400
        t_day2 = self.get_next_valid_day(timestamp)
        sec_from_morning = self.get_next_future_timerange_valid(t_day2)
        if t_day2 is not None and sec_from_morning is not None:
            return t_day2 + sec_from_morning

        # I did not found any valid time
        return None
Пример #3
0
    def get_next_invalid_day(self, timestamp):
        """Get next day where timerange is not active

        :param timestamp: time we compute from
        :type timestamp: int
        :return: timestamp of the next invalid day (midnight) in LOCAL time.
        :rtype: int | None
        """
        # print "Look in", self.__dict__
        # print 'DR: get_next_invalid_day for', time.asctime(time.localtime(t))
        if self.is_time_day_invalid(timestamp):
            # print "EARLY RETURN"
            return timestamp

        next_future_timerange_invalid = self.get_next_future_timerange_invalid(timestamp)
        # print "next_future_timerange_invalid:", next_future_timerange_invalid

        # If today there is no more unavailable timerange, search the next day
        if next_future_timerange_invalid is None:
            # print 'DR: get_next_future_timerange_invalid is None'
            # this day is finish, we check for next period
            (start_time, end_time) = self.get_start_and_end_time(get_day(timestamp))
        else:
            # print 'DR: get_next_future_timerange_invalid is',
            # print time.asctime(time.localtime(next_future_timerange_invalid))
            (start_time, end_time) = self.get_start_and_end_time(timestamp)

        # (start_time, end_time) = self.get_start_and_end_time(t)

        # print "START", time.asctime(time.localtime(start_time)),
        # print "END", time.asctime(time.localtime(end_time))
        # The next invalid day can be t day if there a possible
        # invalid time range (timerange is not 00->24
        if next_future_timerange_invalid is not None:
            if start_time <= timestamp <= end_time:
                # print "Early Return next invalid day:", time.asctime(time.localtime(get_day(t)))
                return get_day(timestamp)
            if start_time >= timestamp:
                # print "start_time >= t:", time.asctime(time.localtime(get_day(start_time)))
                return get_day(start_time)
        else:
            # Else, there is no possibility than in our start_time<->end_time we got
            # any invalid time (full period out). So it's end_time+1 sec (tomorrow of end_time)
            return get_day(end_time + 1)

        return None
Пример #4
0
    def get_next_valid_day(self, timestamp):
        """Get next valid day for timerange

        :param timestamp: time we compute from
        :type timestamp: int
        :return: timestamp of the next valid day (midnight) in LOCAL time.
        :rtype: int | None
        """
        if self.get_next_future_timerange_valid(timestamp) is None:
            # this day is finish, we check for next period
            (start_time, end_time) = self.get_start_and_end_time(get_day(timestamp) + 86400)
        else:
            (start_time, end_time) = self.get_start_and_end_time(timestamp)

        if timestamp <= start_time:
            return get_day(start_time)

        if self.is_time_day_valid(timestamp):
            return get_day(timestamp)
        return None
Пример #5
0
    def get_next_valid_day(self, timestamp):
        """Get next valid day for timerange

        :param timestamp: time we compute from
        :type timestamp: int
        :return: timestamp of the next valid day (midnight) in LOCAL time.
        :rtype: int | None
        """
        if self.get_next_future_timerange_valid(timestamp) is None:
            # this day is finish, we check for next period
            (start_time,
             _) = self.get_start_and_end_time(get_day(timestamp) + 86400)
        else:
            (start_time, _) = self.get_start_and_end_time(timestamp)

        if timestamp <= start_time:
            return get_day(start_time)

        if self.is_time_day_valid(timestamp):
            return get_day(timestamp)
        return None
Пример #6
0
    def get_min_from_t(self, timestamp):
        """Get next time from t where a timerange is valid (withing range)

        :param timestamp: base time to look for the next one
        :return: time where a timerange is valid
        :rtype: int
        """
        if self.is_time_valid(timestamp):
            return timestamp
        t_day_epoch = get_day(timestamp)
        tr_mins = self.get_min_sec_from_morning()
        return t_day_epoch + tr_mins
Пример #7
0
    def get_min_from_t(self, timestamp):
        """Get next time from t where a timerange is valid (withing range)

        :param timestamp: base time to look for the next one
        :return: time where a timerange is valid
        :rtype: int
        """
        if self.is_time_valid(timestamp):
            return timestamp
        t_day_epoch = get_day(timestamp)
        tr_mins = self.get_min_sec_from_morning()
        return t_day_epoch + tr_mins
Пример #8
0
    def get_next_invalid_time_from_t(self, timestamp):
        """Get next invalid time for time range

        :param timestamp: time we compute from
        :type timestamp: int
        :return: timestamp of the next invalid time (LOCAL TIME)
        :rtype: int
        """
        if not self.is_time_valid(timestamp):
            return timestamp

        # First we search fot the day of t
        t_day = self.get_next_invalid_day(timestamp)
        # print "F**K NEXT DAY", time.asctime(time.localtime(t_day))

        # We search for the min of all tr.start > sec_from_morning
        # if it's the next day, use a start of the day search for timerange
        if timestamp < t_day:
            sec_from_morning = self.get_next_future_timerange_invalid(t_day)
        else:  # t is in this day, so look from t (can be in the evening or so)
            sec_from_morning = self.get_next_future_timerange_invalid(
                timestamp)
        # print "DR: sec from morning", sec_from_morning

        # tr can't be valid, or it will be return at the beginning
        # sec_from_morning = self.get_next_future_timerange_invalid(t)

        # Ok we've got a next invalid day and a invalid possibility in
        # timerange, so the next invalid is this day+sec_from_morning
        # print "T_day", t_day, "Sec from morning", sec_from_morning
        if t_day is not None and sec_from_morning is not None:
            return t_day + sec_from_morning + 1

        # We've got a day but no sec_from_morning: the timerange is full (0->24h)
        # so the next invalid is this day at the day_start
        if t_day is not None and sec_from_morning is None:
            return t_day

        # Then we search for the next day of t
        # The sec will be the min of the day
        timestamp = get_day(timestamp) + 86400
        t_day2 = self.get_next_invalid_day(timestamp)
        sec_from_morning = self.get_next_future_timerange_invalid(t_day2)
        if t_day2 is not None and sec_from_morning is not None:
            return t_day2 + sec_from_morning + 1

        if t_day2 is not None and sec_from_morning is None:
            return t_day2
        else:
            # I'm not find any valid time
            return None
Пример #9
0
    def get_next_invalid_time_from_t(self, timestamp):
        """Get next invalid time for time range

        :param timestamp: time we compute from
        :type timestamp: int
        :return: timestamp of the next invalid time (LOCAL TIME)
        :rtype: int
        """
        if not self.is_time_valid(timestamp):
            return timestamp

        # First we search fot the day of t
        t_day = self.get_next_invalid_day(timestamp)
        # print "F**K NEXT DAY", time.asctime(time.localtime(t_day))

        # We search for the min of all tr.start > sec_from_morning
        # if it's the next day, use a start of the day search for timerange
        if timestamp < t_day:
            sec_from_morning = self.get_next_future_timerange_invalid(t_day)
        else:  # t is in this day, so look from t (can be in the evening or so)
            sec_from_morning = self.get_next_future_timerange_invalid(timestamp)
        # print "DR: sec from morning", sec_from_morning

        # tr can't be valid, or it will be return at the beginning
        # sec_from_morning = self.get_next_future_timerange_invalid(t)

        # Ok we've got a next invalid day and a invalid possibility in
        # timerange, so the next invalid is this day+sec_from_morning
        # print "T_day", t_day, "Sec from morning", sec_from_morning
        if t_day is not None and sec_from_morning is not None:
            return t_day + sec_from_morning + 1

        # We've got a day but no sec_from_morning: the timerange is full (0->24h)
        # so the next invalid is this day at the day_start
        if t_day is not None and sec_from_morning is None:
            return t_day

        # Then we search for the next day of t
        # The sec will be the min of the day
        timestamp = get_day(timestamp) + 86400
        t_day2 = self.get_next_invalid_day(timestamp)
        sec_from_morning = self.get_next_future_timerange_invalid(t_day2)
        if t_day2 is not None and sec_from_morning is not None:
            return t_day2 + sec_from_morning + 1

        if t_day2 is not None and sec_from_morning is None:
            return t_day2
        else:
            # I'm not find any valid time
            return None
Пример #10
0
    def get_next_invalid_day(self, timestamp):
        # pylint: disable=no-else-return
        """Get next day where timerange is not active

        :param timestamp: time we compute from
        :type timestamp: int
        :return: timestamp of the next invalid day (midnight) in LOCAL time.
        :rtype: int | None
        """
        if self.is_time_day_invalid(timestamp):
            return timestamp

        next_future_timerange_invalid = self.get_next_future_timerange_invalid(
            timestamp)

        # If today there is no more unavailable timerange, search the next day
        if next_future_timerange_invalid is None:
            # this day is finish, we check for next period
            (start_time,
             end_time) = self.get_start_and_end_time(get_day(timestamp))
        else:
            (start_time, end_time) = self.get_start_and_end_time(timestamp)

        # (start_time, end_time) = self.get_start_and_end_time(t)

        # The next invalid day can be t day if there a possible
        # invalid time range (timerange is not 00->24
        if next_future_timerange_invalid is not None:
            if start_time <= timestamp <= end_time:
                return get_day(timestamp)
            if start_time >= timestamp:
                return get_day(start_time)
        else:
            # Else, there is no possibility than in our start_time<->end_time we got
            # any invalid time (full period out). So it's end_time+1 sec (tomorrow of end_time)
            return get_day(end_time + 1)
        return None
Пример #11
0
    def get_next_valid_time_from_t(self, timestamp):
        """Get next valid time for time range

        :param timestamp: time we compute from
        :type timestamp: int
        :return: timestamp of the next valid time (LOCAL TIME)
        :rtype: int | None
        """
        # print "\tDR Get next valid from:", time.asctime(time.localtime(t))
        # print "DR Get next valid from:", t
        if self.is_time_valid(timestamp):
            return timestamp

        # print "DR Get next valid from:", time.asctime(time.localtime(t))
        # First we search fot the day of t
        t_day = self.get_next_valid_day(timestamp)

        # print "DR: T next valid day", time.asctime(time.localtime(t_day))

        # We search for the min of all tr.start > sec_from_morning
        # if it's the next day, use a start of the day search for timerange
        if timestamp < t_day:
            sec_from_morning = self.get_next_future_timerange_valid(t_day)
        else:  # t is in this day, so look from t (can be in the evening or so)
            sec_from_morning = self.get_next_future_timerange_valid(timestamp)
        # print "DR: sec from morning", sec_from_morning

        if sec_from_morning is not None:
            if t_day is not None and sec_from_morning is not None:
                return t_day + sec_from_morning

        # Then we search for the next day of t
        # The sec will be the min of the day
        timestamp = get_day(timestamp) + 86400
        t_day2 = self.get_next_valid_day(timestamp)
        sec_from_morning = self.get_next_future_timerange_valid(t_day2)
        if t_day2 is not None and sec_from_morning is not None:
            return t_day2 + sec_from_morning
        else:
            # I'm not find any valid time
            return None