1 from time import localtime
3 class TimerSanityCheck:
4 def __init__(self, timerlist, newtimer):
5 self.timerlist = timerlist
6 self.newtimer = newtimer
10 self.simultimer = [ self.newtimer ]
11 for timer in self.timerlist:
12 if self.isSimultaneous(timer, self.newtimer):
13 self.simultimer.append(timer)
15 if len(self.simultimer) > 1:
16 return self.checkRecordable(self.simultimer)
20 def getSimulTimerList(self):
21 return self.simultimer
23 def isSimultaneous(self, timer1, timer2):
24 # both timers are repeated
25 if (timer1.repeated & timer2.repeated):
26 return self.timeEquals(timer1, timer2)
28 # one timer is repeated
29 if not timer1.repeated:
35 dow2 = (localtime(timer2.begin).tm_wday - 1) % 7
37 if timer1.repeated & (2 ** dow2):
38 return self.timeEquals(timer1, timer2)
40 if (timer1.begin <= timer2.begin < timer1.end) or (timer2.begin <= timer1.begin < timer2.end):
45 def timeEquals(self, timer1, timer2):
46 ltb1 = localtime(timer1.begin)
47 ltb2 = localtime(timer2.begin)
49 begin1 = ltb1.tm_hour * 3600 + ltb1.tm_min * 60 + ltb1.tm_sec
50 begin2 = ltb2.tm_hour * 3600 + ltb2.tm_min * 60 + ltb2.tm_sec
52 end1 = begin1 + timer1.end - timer1.begin
53 end2 = begin2 + timer2.end - timer2.begin
55 return (begin1 <= begin2 < end1) or (begin2 <= begin1 < end2)
57 def checkRecordable(self, timerlist):