1 from Converter import Converter
2 from time import localtime, strftime
3 from Components.Element import cached
5 class ClockToText(Converter, object):
13 # add: date, date as string, weekday, ...
14 # (whatever you need!)
16 def __init__(self, type):
17 Converter.__init__(self, type)
18 if type == "WithSeconds":
19 self.type = self.WITH_SECONDS
20 elif type == "InMinutes":
21 self.type = self.IN_MINUTES
24 elif type == "AsLength":
25 self.type = self.AS_LENGTH
26 elif str(type).find("Format") != -1:
27 self.type = self.FORMAT
28 self.fmt_string = type[7:]
30 self.type = self.DEFAULT
34 time = self.source.time
39 if self.type == self.IN_MINUTES:
40 return "%d min" % (time / 60)
41 elif self.type == self.AS_LENGTH:
42 return "%d:%02d" % (time / 60, time % 60)
46 if self.type == self.WITH_SECONDS:
47 return "%2d:%02d:%02d" % (t.tm_hour, t.tm_min, t.tm_sec)
48 elif self.type == self.DEFAULT:
49 return "%02d:%02d" % (t.tm_hour, t.tm_min)
50 elif self.type == self.DATE:
51 return strftime("%A %B %d, %Y", t)
52 elif self.type == self.FORMAT:
53 spos = self.fmt_string.find('%')
55 s1 = self.fmt_string[:spos]
56 s2 = strftime(self.fmt_string[spos:], t)
59 return strftime(self.fmt_string, t)
63 text = property(getText)