remove unneeded
[enigma2.git] / lib / python / Components / Converter / ClockToText.py
1 from Converter import Converter
2 from time import localtime, strftime
3 from Components.Element import cached
4
5 class ClockToText(Converter, object):
6         DEFAULT = 0
7         WITH_SECONDS = 1
8         IN_MINUTES = 2
9         DATE = 3
10         FORMAT = 4
11         
12         # add: date, date as string, weekday, ... 
13         # (whatever you need!)
14         
15         def __init__(self, type):
16                 Converter.__init__(self, type)
17                 if type == "WithSeconds":
18                         self.type = self.WITH_SECONDS
19                 elif type == "InMinutes":
20                         self.type = self.IN_MINUTES
21                 elif type == "Date":
22                         self.type = self.DATE
23                 elif type.find("Format") != -1:
24                         self.type = self.FORMAT
25                         self.fmt_string = type[7:]
26                 else:
27                         self.type = self.DEFAULT
28
29         @cached
30         def getText(self):
31                 time = self.source.time
32                 if time is None:
33                         return ""
34
35                 # handle durations
36                 if self.type == self.IN_MINUTES:
37                         return "%d min" % (time / 60)
38                 
39                 t = localtime(time)
40                 
41                 if self.type == self.WITH_SECONDS:
42                         return "%2d:%02d:%02d" % (t.tm_hour, t.tm_min, t.tm_sec)
43                 elif self.type == self.DEFAULT:
44                         return "%02d:%02d" % (t.tm_hour, t.tm_min)
45                 elif self.type == self.DATE:
46                         return strftime("%A %B %d, %Y", t)
47                 elif self.type == self.FORMAT:
48                         spos = self.fmt_string.find('%')
49                         if spos > 0:
50                                 s1 = self.fmt_string[:spos]
51                                 s2 = strftime(self.fmt_string[spos:], t)
52                                 return str(s1+s2)
53                         else:
54                                 return strftime(self.fmt_string, t)
55                 else:
56                         return "???"
57
58         text = property(getText)