1 from Converter import Converter
2 from time import localtime, strftime
3 from Components.Element import cached
5 class ClockToText(Converter, object):
12 # add: date, date as string, weekday, ...
13 # (whatever you need!)
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
23 elif type.find("Format") != -1:
24 self.type = self.FORMAT
25 self.fmt_string = type[7:]
27 self.type = self.DEFAULT
31 time = self.source.time
36 if self.type == self.IN_MINUTES:
37 return "%d min" % (time / 60)
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('%')
50 s1 = self.fmt_string[:spos]
51 s2 = strftime(self.fmt_string[spos:], t)
54 return strftime(self.fmt_string, t)
58 text = property(getText)