check in gacks handle code
[sfa.git] / gacks / gackscalendar.py
1 class GacksCalendar:
2     def __init__(self):
3         pass
4
5     def query(self, id, unitStart, unitStop, timeStart, timeStop):
6         pass
7
8     def insert_record(self, item):
9         pass
10
11 class GacksListCalendar(GacksCalendar):
12     def __init__(self):
13         self.items = []
14
15     def test_id(x, y):
16         if not x:
17             return True
18         else:
19             return (x == y)
20
21     def test_lesser(x, y):
22         if not x:
23             return True
24         else if y==INFINITY:
25             return True
26         else:
27             return (x<y)
28
29     def test_greater_equal(x, y):
30         if not x:
31             return True
32         else if x==INFINITY:
33             return True
34         else if y==INFINITY:
35             return False
36         else:
37             return (x>=y)
38
39     def query(self, id, unitStart=0, unitStop=INFINITY, timeStart=0, timeStop=INFINITY):
40         list = []
41         for item in self.items:
42             if test_id(id, item.id) and
43                test_lesser(unitStart, item.unitStop) and
44                test_greater_equal(unitStop, item.unitStart) and
45                test_lesser(timeStart, item.timeStop) and
46                test_greater_equal(timeStop, item.timeStart):
47                  list = list + item
48         return list
49
50     def insert_record(self, item):
51         conflicts = self.query(item.id, item.unitStart, item.unitStop, item.timeStart, item.timeStop)
52         for conflict in conflicts:
53             self.items.remove(conflict)
54
55         self.items.append(item)
56