git.cweiske.de
/
enigma2.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Path and template fixes
[enigma2.git]
/
lib
/
python
/
Components
/
Converter
/
ClockToText.py
diff --git
a/lib/python/Components/Converter/ClockToText.py
b/lib/python/Components/Converter/ClockToText.py
index 5d5df65113b455bb17df46778c3ca2e8844fdc72..109f91259b9db071cf1d0fcf25608d50a851bd29 100644
(file)
--- a/
lib/python/Components/Converter/ClockToText.py
+++ b/
lib/python/Components/Converter/ClockToText.py
@@
-1,11
+1,14
@@
from Converter import Converter
from time import localtime, strftime
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
class ClockToText(Converter, object):
DEFAULT = 0
WITH_SECONDS = 1
IN_MINUTES = 2
DATE = 3
+ FORMAT = 4
+ AS_LENGTH = 5
# add: date, date as string, weekday, ...
# (whatever you need!)
# add: date, date as string, weekday, ...
# (whatever you need!)
@@
-18,9
+21,15
@@
class ClockToText(Converter, object):
self.type = self.IN_MINUTES
elif type == "Date":
self.type = self.DATE
self.type = self.IN_MINUTES
elif type == "Date":
self.type = self.DATE
+ elif type == "AsLength":
+ self.type = self.AS_LENGTH
+ elif str(type).find("Format") != -1:
+ self.type = self.FORMAT
+ self.fmt_string = type[7:]
else:
self.type = self.DEFAULT
else:
self.type = self.DEFAULT
+ @cached
def getText(self):
time = self.source.time
if time is None:
def getText(self):
time = self.source.time
if time is None:
@@
-29,6
+38,8
@@
class ClockToText(Converter, object):
# handle durations
if self.type == self.IN_MINUTES:
return "%d min" % (time / 60)
# handle durations
if self.type == self.IN_MINUTES:
return "%d min" % (time / 60)
+ elif self.type == self.AS_LENGTH:
+ return "%d:%02d" % (time / 60, time % 60)
t = localtime(time)
t = localtime(time)
@@
-38,6
+49,14
@@
class ClockToText(Converter, object):
return "%02d:%02d" % (t.tm_hour, t.tm_min)
elif self.type == self.DATE:
return strftime("%A %B %d, %Y", t)
return "%02d:%02d" % (t.tm_hour, t.tm_min)
elif self.type == self.DATE:
return strftime("%A %B %d, %Y", t)
+ elif self.type == self.FORMAT:
+ spos = self.fmt_string.find('%')
+ if spos > 0:
+ s1 = self.fmt_string[:spos]
+ s2 = strftime(self.fmt_string[spos:], t)
+ return str(s1+s2)
+ else:
+ return strftime(self.fmt_string, t)
else:
return "???"
else:
return "???"