ClockToText - optional parameter for adding or remove initial space when is used...
authorims <ims21@users.sourceforge.net>
Fri, 6 Feb 2015 15:19:32 +0000 (16:19 +0100)
committerlittlesat <littlesat99@yahoo.com>
Fri, 6 Feb 2015 17:22:57 +0000 (18:22 +0100)
Signed-off-by: littlesat <littlesat99@yahoo.com>

lib/python/Components/Converter/ClockToText.py

index 9fefe51..1ea6c1a 100644 (file)
@@ -22,6 +22,11 @@ class ClockToText(Converter, object):
 
        def __init__(self, type):
                Converter.__init__(self, type)
+
+               self.fix = ""
+               if ';' in type:
+                       type, self.fix = type.split(';')
+
                if type == "WithSeconds":
                        self.type = self.WITH_SECONDS
                elif type == "InMinutes":
@@ -56,6 +61,14 @@ class ClockToText(Converter, object):
                if time is None:
                        return ""
 
+               # add/remove 1st space
+               def fix_space(string):
+                       if "Proportional" in self.fix and t.tm_hour < 10:
+                               return " " + string
+                       if "NoSpace" in self.fix:
+                               return string.lstrip(' ')
+                       return string
+
                # handle durations
                if self.type == self.IN_MINUTES:
                        return _("%d min") % (time / 60)
@@ -78,12 +91,10 @@ class ClockToText(Converter, object):
 
                if self.type == self.WITH_SECONDS:
                        # TRANSLATORS: full time representation hour:minute:seconds
-                       return _("%2d:%02d:%02d") % (t.tm_hour, t.tm_min, t.tm_sec)
+                       return fix_space(_("%2d:%02d:%02d") % (t.tm_hour, t.tm_min, t.tm_sec))
                elif self.type == self.DEFAULT:
                        # TRANSLATORS: short time representation hour:minute
-                       if t.tm_hour < 10:
-                               return " " + _("%2d:%02d") % (t.tm_hour, t.tm_min)
-                       return _("%2d:%02d") % (t.tm_hour, t.tm_min)
+                       return fix_space(_("%2d:%02d") % (t.tm_hour, t.tm_min))
                elif self.type == self.DATE:
                        # TRANSLATORS: full date representation dayname daynum monthname year in strftime() format! See 'man strftime'
                        d = _("%A %e %B %Y")