small cleanup
[enigma2.git] / lib / python / Components / Converter / ClockToText.py
index 085ebc1a3a8dc9db95fa0c2063ad150281813838..5cc709f223a041db5c02839fe2c5c4253dd2eeb6 100644 (file)
@@ -1,23 +1,28 @@
-from Components.Converter.Converter import Converter
-from time import localtime
+from Converter import Converter
+from time import localtime, strftime
+from Components.Element import cached
 
 class ClockToText(Converter, object):
        DEFAULT = 0
        WITH_SECONDS = 1
        IN_MINUTES = 2
+       DATE = 3
        
        # add: date, date as string, weekday, ... 
        # (whatever you need!)
        
-       def __init__(self, type, *args, **kwargs):
-               Converter.__init__(self)
+       def __init__(self, type):
+               Converter.__init__(self, type)
                if type == "WithSeconds":
                        self.type = self.WITH_SECONDS
                elif type == "InMinutes":
                        self.type = self.IN_MINUTES
+               elif type == "Date":
+                       self.type = self.DATE
                else:
                        self.type = self.DEFAULT
 
+       @cached
        def getText(self):
                time = self.source.time
                if time is None:
@@ -33,6 +38,8 @@ class ClockToText(Converter, object):
                        return "%2d:%02d:%02d" % (t.tm_hour, t.tm_min, t.tm_sec)
                elif self.type == self.DEFAULT:
                        return "%02d:%02d" % (t.tm_hour, t.tm_min)
+               elif self.type == self.DATE:
+                       return strftime("%A %B %d, %Y", t)
                else:
                        return "???"