Skip to content

Commit

Permalink
Gotta make time denominations singular when there is only "1"
Browse files Browse the repository at this point in the history
  • Loading branch information
ralphbean committed Jul 22, 2013
1 parent 9d9f0a3 commit fbeff05
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions tahrir/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -135,7 +142,6 @@ def make_relative_time_property(attr):
'hours': 'hrs',
'minutes': 'mins',
'seconds': 'secs',
'microseconds': 'ms',
}

@property
Expand All @@ -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"

Expand Down

0 comments on commit fbeff05

Please sign in to comment.