Beispiel #1
0
    def get_next_future_timerange_invalid(self, timestamp):
        """Get next invalid time for timeranges

        :param timestamp: time to check
        :type timestamp: int
        :return: next time when a timerange is not valid
        :rtype: None | int
        TODO: Looks like this function is buggy, start time should not be
        included in returned values
        """
        # print 'Call for get_next_future_timerange_invalid from ', time.asctime(time.localtime(t))
        sec_from_morning = get_sec_from_morning(timestamp)
        # print 'sec from morning', sec_from_morning
        ends = []
        for timerange in self.timeranges:
            tr_start = timerange.hstart * 3600 + timerange.mstart * 60
            if tr_start >= sec_from_morning:
                ends.append(tr_start)
            tr_end = timerange.hend * 3600 + timerange.mend * 60
            if tr_end >= sec_from_morning:
                ends.append(tr_end)
        # print "Ends:", ends
        # Remove the last second of the day for 00->24h"
        if 86400 in ends:
            ends.remove(86400)
        if ends != []:
            return min(ends)
        else:
            return None
Beispiel #2
0
    def get_next_future_timerange_invalid(self, timestamp):
        """Get next invalid time for timeranges

        :param timestamp: time to check
        :type timestamp: int
        :return: next time when a timerange is not valid
        :rtype: None | int
        TODO: Looks like this function is buggy, start time should not be
        included in returned values
        """
        # print 'Call for get_next_future_timerange_invalid from ', time.asctime(time.localtime(t))
        sec_from_morning = get_sec_from_morning(timestamp)
        # print 'sec from morning', sec_from_morning
        ends = []
        for timerange in self.timeranges:
            tr_start = timerange.hstart * 3600 + timerange.mstart * 60
            if tr_start >= sec_from_morning:
                ends.append(tr_start)
            tr_end = timerange.hend * 3600 + timerange.mend * 60
            if tr_end >= sec_from_morning:
                ends.append(tr_end)
        # print "Ends:", ends
        # Remove the last second of the day for 00->24h"
        if 86400 in ends:
            ends.remove(86400)
        if ends != []:
            return min(ends)
        else:
            return None
Beispiel #3
0
    def is_time_valid(self, timestamp):
        """Check if time is valid for this Timerange

        :param timestamp: time to check
        :type timestamp: int
        :return: True if time is valid (in interval), False otherwise
        :rtype: bool
        """
        sec_from_morning = get_sec_from_morning(timestamp)
        return (self.is_valid and self.hstart * 3600 + self.mstart * 60 <=
                sec_from_morning <= self.hend * 3600 + self.mend * 60)
Beispiel #4
0
    def is_time_valid(self, timestamp):
        """Check if time is valid for this Timerange

        :param timestamp: time to check
        :type timestamp: int
        :return: True if time is valid (in interval), False otherwise
        :rtype: bool
        """
        sec_from_morning = get_sec_from_morning(timestamp)
        return (self.is_valid and
                self.hstart * 3600 + self.mstart * 60 <=
                sec_from_morning <=
                self.hend * 3600 + self.mend * 60)
Beispiel #5
0
    def get_next_future_timerange_valid(self, timestamp):
        """Get the next valid timerange (next timerange start in timeranges attribute)

        :param timestamp: base time
        :type timestamp: int
        :return: next time when a timerange is valid
        :rtype: None | int
        """
        sec_from_morning = get_sec_from_morning(timestamp)
        starts = []
        for timerange in self.timeranges:
            tr_start = timerange.hstart * 3600 + timerange.mstart * 60
            if tr_start >= sec_from_morning:
                starts.append(tr_start)
        if starts != []:
            return min(starts)

        return None
Beispiel #6
0
    def get_next_future_timerange_valid(self, timestamp):
        """Get the next valid timerange (next timerange start in timeranges attribute)

        :param timestamp: base time
        :type timestamp: int
        :return: next time when a timerange is valid
        :rtype: None | int
        """
        # print "Look for get_next_future_timerange_valid for t", t, time.asctime(time.localtime(t))
        sec_from_morning = get_sec_from_morning(timestamp)
        starts = []
        for timerange in self.timeranges:
            tr_start = timerange.hstart * 3600 + timerange.mstart * 60
            if tr_start >= sec_from_morning:
                starts.append(tr_start)
        if starts != []:
            return min(starts)
        else:
            return None
Beispiel #7
0
    def get_next_future_timerange_invalid(self, timestamp):
        """Get next invalid time for timeranges

        :param timestamp: time to check
        :type timestamp: int
        :return: next time when a timerange is not valid
        :rtype: None | int
        """
        sec_from_morning = get_sec_from_morning(timestamp)
        ends = []
        for timerange in self.timeranges:
            tr_end = timerange.hend * 3600 + timerange.mend * 60
            if tr_end >= sec_from_morning:
                # Remove the last second of the day for 00->24h"
                if tr_end == 86400:
                    tr_end = 86399
                ends.append(tr_end)
        if ends != []:
            return min(ends)

        return None