1 from Converter import Converter
2 from time import localtime, strftime
3 from Components.Element import cached
5 class ClockToText(Converter, object):
14 # add: date, date as string, weekday, ...
15 # (whatever you need!)
17 def __init__(self, type):
18 Converter.__init__(self, type)
19 if type == "WithSeconds":
20 self.type = self.WITH_SECONDS
21 elif type == "InMinutes":
22 self.type = self.IN_MINUTES
25 elif type == "AsLength":
26 self.type = self.AS_LENGTH
27 elif type == "Timestamp":
28 self.type = self.TIMESTAMP
29 elif str(type).find("Format") != -1:
30 self.type = self.FORMAT
31 self.fmt_string = type[7:]
33 self.type = self.DEFAULT
37 time = self.source.time
42 if self.type == self.IN_MINUTES:
43 return "%d min" % (time / 60)
44 elif self.type == self.AS_LENGTH:
45 return "%d:%02d" % (time / 60, time % 60)
46 elif self.type == self.TIMESTAMP:
51 if self.type == self.WITH_SECONDS:
52 return "%2d:%02d:%02d" % (t.tm_hour, t.tm_min, t.tm_sec)
53 elif self.type == self.DEFAULT:
54 return "%02d:%02d" % (t.tm_hour, t.tm_min)
55 elif self.type == self.DATE:
56 return strftime("%A %B %d, %Y", t)
57 elif self.type == self.FORMAT:
58 spos = self.fmt_string.find('%')
60 s1 = self.fmt_string[:spos]
61 s2 = strftime(self.fmt_string[spos:], t)
64 return strftime(self.fmt_string, t)
69 text = property(getText)