コード例 #1
0
def process_time_range(value):
    """
    Return a tuple with (from, to) time in minutes from midnight.
    """
    from_time, to_time = value.split('-')
    from_t = get_minutes_from_midnight(from_time)
    to_t = get_minutes_from_midnight(to_time)
    return (from_t, to_t)
コード例 #2
0
def process_time_range(value):
    """
    Return a tuple with (from, to) time in minutes from midnight.
    """
    from_time, to_time = value.split('-')
    from_t = get_minutes_from_midnight(from_time)
    to_t = get_minutes_from_midnight(to_time)
    return (from_t, to_t)
コード例 #3
0
    def minutes_to_closing(self, day, time):
        """
        Return 0 if closed for given day and time, else number of minutes to closing
        """
        if self.is_always_open: return -1  # TODO value for "not closing"?
        day = day.lower()

        if not day in self.opening_hours: return 0

        for op_hours in self.opening_hours[day]:
            if op_hours[0] < get_minutes_from_midnight(time) < op_hours[1]:
                return op_hours[1] - get_minutes_from_midnight(time)
        return 0
コード例 #4
0
    def minutes_to_closing(self, day, time):
        """
        Return 0 if closed for given day and time, else number of minutes to closing
        """
        if self.is_always_open: return -1   # TODO value for "not closing"?
        day = day.lower()

        if not day in self.opening_hours: return 0

        for op_hours in self.opening_hours[day]:
            if op_hours[0] < get_minutes_from_midnight(time) < op_hours[1]:
                return op_hours[1] - get_minutes_from_midnight(time)
        return 0
コード例 #5
0
    def is_open(self, day, time):
        """
        Return True if open for given day and time, else False
        """
        if self.is_always_open: return True
        day = day.lower()

        if not day in self.opening_hours: return False

        for op_hours in self.opening_hours[day]:
            if op_hours[0] < get_minutes_from_midnight(time) < op_hours[1]:
                return True
        return False
コード例 #6
0
    def is_open(self, day, time):
        """
        Return True if open for given day and time, else False
        """
        if self.is_always_open: return True
        day = day.lower()

        if not day in self.opening_hours: return False

        for op_hours in self.opening_hours[day]:
            if op_hours[0] < get_minutes_from_midnight(time) < op_hours[1]:
                return True
        return False
コード例 #7
0
 def test_get_minutes_from_midnight(self):
     self.assertEqual(get_minutes_from_midnight("0:00"), 0)
     self.assertEqual(get_minutes_from_midnight("02:00"), 120)
     self.assertEqual(get_minutes_from_midnight("18:42"), 1122)
コード例 #8
0
 def test_get_minutes_from_midnight(self):
     self.assertEqual(get_minutes_from_midnight("0:00"), 0)
     self.assertEqual(get_minutes_from_midnight("02:00"), 120)
     self.assertEqual(get_minutes_from_midnight("18:42"), 1122)