From fbeff056311418e4d38debd72a47c3554910fda3 Mon Sep 17 00:00:00 2001 From: Ralph Bean Date: Mon, 22 Jul 2013 00:47:52 -0400 Subject: [PATCH] Gotta make time denominations singular when there is only "1" --- tahrir/utils.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/tahrir/utils.py b/tahrir/utils.py index 173dab1a..694d13d2 100644 --- a/tahrir/utils.py +++ b/tahrir/utils.py @@ -126,6 +126,13 @@ def avatar_method(self, size): return avatar_method +def singularize(term, value): + """ Strip the 's' off of plural words to dumbly singularize them. """ + if value == 1: + return term[:-1] + else: + return term + def make_relative_time_property(attr): SHORT_DENOMINATIONS = { @@ -135,7 +142,6 @@ def make_relative_time_property(attr): 'hours': 'hrs', 'minutes': 'mins', 'seconds': 'secs', - 'microseconds': 'ms', } @property @@ -153,12 +159,15 @@ def relative_time_method(self): rd = dateutil.relativedelta.relativedelta(seconds=math.fabs(delta)) denominations = [ 'years', 'months', 'days', 'hours', - 'minutes', 'seconds', 'microseconds'] + 'minutes', 'seconds'] for denomination in denominations: value = getattr(rd, denomination, 0) if value: - return "%d %s %s" % (value, - SHORT_DENOMINATIONS[denomination], suffix) + return "%d %s %s" % ( + value, + singularize(SHORT_DENOMINATIONS[denomination], value), + suffix + ) return "just now"