From 5d033c9aedf474a5d503d6b585a1109ef25c18db Mon Sep 17 00:00:00 2001 From: Rolux Date: Wed, 2 Jul 2008 16:26:20 +0200 Subject: [PATCH 1/2] bugfix --- oxutils/format.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/oxutils/format.py b/oxutils/format.py index 7f878dd..f07c97e 100644 --- a/oxutils/format.py +++ b/oxutils/format.py @@ -177,14 +177,18 @@ def formatDuration(ms, verbosity=0, years=False, hours=False, milliseconds=False duration += ".%03d" % ms else: if verbosity == 1: - durations = ["%sy" % y, "%sd" % d, "%sh" % h, "%sm" % m, "%ss" % s] + durations = ["%sd" % d, "%sh" % h, "%sm" % m, "%ss" % s] + if years: + durations.insert(0, "%sy" % y) if milliseconds: - durations.push("%sms" % ms) + durations.append("%sms" % ms) else: - durations = [plural(y, 'year'), plural(d, 'day'), plural(h,'hour'), + durations = [plural(d, 'day'), plural(h,'hour'), plural(m, 'minute'), plural(s, 'second')] + if years: + durations.insert(0, plural(y, 'year')) if milliseconds: - durations.push(plural(ms, 'millisecond')) + durations.append(plural(ms, 'millisecond')) durations = filter(lambda x: not x.startswith('0'), durations) duration = ' '.join(durations) return duration From eaa1e15d0b34c4c9d2e7ac755b5912868d0b6421 Mon Sep 17 00:00:00 2001 From: Rolux Date: Wed, 2 Jul 2008 16:32:30 +0200 Subject: [PATCH 2/2] better default values for formatDuration() --- oxutils/format.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/oxutils/format.py b/oxutils/format.py index f07c97e..2dcd210 100644 --- a/oxutils/format.py +++ b/oxutils/format.py @@ -139,21 +139,21 @@ def plural(amount, unit, plural='s'): else: unit = plural return "%s %s" % (formatThousands(amount), unit) -def formatDuration(ms, verbosity=0, years=False, hours=False, milliseconds=False): +def formatDuration(ms, verbosity=0, years=True, hours=True, milliseconds=True): ''' verbosity 0: D:HH:MM:SS 1: Dd Hh Mm Ss 2: D days H hours M minutes S seconds years - False: 366 days are 366 days True: 366 days are 1 year 1 day + False: 366 days are 366 days hours - False: 30 seconds are 00:30 True: 30 seconds are 00:00:30 + False: 30 seconds are 00:30 milliseconds - False: never display milliseconds True: always display milliseconds + False: never display milliseconds ''' if years: y = int(ms / 31536000000)