From 406fc1960601cd2ba280a0e81aa0a34cebca4ccf Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Thu, 19 Jun 2008 16:41:53 +0200 Subject: [PATCH] optionaly display short runtime, add languages2Letter --- oxutils/format.py | 9 ++++++--- oxutils/lang.py | 7 +++++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/oxutils/format.py b/oxutils/format.py index bfb2ca7..11b1ec9 100644 --- a/oxutils/format.py +++ b/oxutils/format.py @@ -139,7 +139,7 @@ def plural(amount, unit, plural='s'): else: unit = plural return "%s %s" % (formatThousands(amount), unit) -def ms2runtime(ms): +def ms2runtime(ms, shortenLong=False): ''' >>> ms2runtime(5000) '5 seconds' @@ -167,8 +167,11 @@ def ms2runtime(ms): if days >= 365: years = int(days / 365) days = days % 365 - runtimeString = (plural(years, 'year'), plural(days, 'day'), - plural(hours,'hour'), plural(minutes, 'minute'), plural(seconds, 'second')) + if shortenLong and years > 0 or days > 99: + runtimeString = ("%sy" % years, "%sd" % days, "%sh" % hours, "%sm" % minutes, "%ss" % seconds) + else: + runtimeString = (plural(years, 'year'), plural(days, 'day'), + plural(hours,'hour'), plural(minutes, 'minute'), plural(seconds, 'second')) runtimeString = filter(lambda x: not x.startswith('0'), runtimeString) return " ".join(runtimeString).strip() diff --git a/oxutils/lang.py b/oxutils/lang.py index 964ac9f..789cab3 100644 --- a/oxutils/lang.py +++ b/oxutils/lang.py @@ -234,3 +234,10 @@ def englishName(lang): return l[0] return None +def languages2Letter(): + languages = [] + for l in _iso639_languages: + if l[2]: + languages.append(l[2]) + return languages +