add new skin stuff
[enigma2.git] / lib / python / Components / Converter / ClockToText.py
1 from Components.Converter.Converter import Converter
2 from time import localtime
3
4 class ClockToText(Converter, object):
5         DEFAULT = 0
6         WITH_SECONDS = 1
7         IN_MINUTES = 2
8         
9         # add: date, date as string, weekday, ... 
10         # (whatever you need!)
11         
12         def __init__(self, type, *args, **kwargs):
13                 Converter.__init__(self)
14                 if type == "WithSeconds":
15                         self.type = self.WITH_SECONDS
16                 elif type == "InMinutes":
17                         self.type = self.IN_MINUTES
18                 else:
19                         self.type = self.DEFAULT
20
21         def getText(self):
22                 time = self.source.time
23                 if time is None:
24                         return ""
25
26                 # handle durations
27                 if self.type == self.IN_MINUTES:
28                         return "%d min" % (time / 60)
29                 
30                 t = localtime(time)
31                 
32                 if self.type == self.WITH_SECONDS:
33                         return "%2d:%02d:%02d" % (t.tm_hour, t.tm_min, t.tm_sec)
34                 elif self.type == self.DEFAULT:
35                         return "%02d:%02d" % (t.tm_hour, t.tm_min)
36                 else:
37                         return "???"
38
39         text = property(getText)