add possibility to use ValueRange as ValueEqual Converter
[enigma2.git] / lib / python / Components / Converter / ServiceTime.py
1 from Converter import Converter
2 from Components.Element import cached
3 from enigma import iServiceInformation
4
5 class ServiceTime(Converter, object):
6         STARTTIME = 0
7         ENDTIME = 1
8         DURATION = 2
9
10         def __init__(self, type):
11                 Converter.__init__(self, type)
12                 if type == "EndTime":
13                         self.type = self.ENDTIME
14                 elif type == "StartTime":
15                         self.type = self.STARTTIME
16                 elif type == "Duration":
17                         self.type = self.DURATION
18                 else:
19                         raise str("'%s' is not <StartTime|EndTime|Duration> for eEventTime converter" % type)
20
21         @cached
22         def getTime(self):
23                 service = self.source.service
24                 info = self.source.info
25                 
26                 if not info or not service:
27                         return None
28
29                 if self.type == self.STARTTIME:
30                         return info.getInfo(service, iServiceInformation.sTimeCreate)
31                 elif self.type == self.ENDTIME:
32                         begin = info.getInfo(service, iServiceInformation.sTimeCreate)
33                         len = info.getLength(service)
34                         return begin + len
35                 elif self.type == self.DURATION:
36                         return info.getLength(service)
37
38         time = property(getTime)