improve published Date output

This commit is contained in:
Thomas Pointhuber 2014-03-15 19:13:57 +01:00
parent 7a922b2ab8
commit 794165d19c
1 changed files with 17 additions and 3 deletions

View File

@ -161,10 +161,24 @@ def index():
if 'publishedDate' in result: if 'publishedDate' in result:
if result['publishedDate'].date() == datetime.now().date(): if result['publishedDate'].date() == datetime.now().date():
timedifference = datetime.now()-result['publishedDate'] timedifference = datetime.now()-result['publishedDate']
if timedifference.seconds < 60*60: minutes = int((timedifference.seconds/60)%60)
result['publishedDate'] = gettext(u'{0:d} minutes ago').format(timedifference.seconds/60) hours = int(timedifference.seconds/60/60)
if hours == 0:
if minutes == 1:
result['publishedDate'] = gettext(u'1 minute ago')
else:
result['publishedDate'] = gettext(u'{minutes} minutes ago').format(minutes=minutes)
else: else:
result['publishedDate'] = gettext(u'{0:d} hours ago').format(timedifference.seconds/60/60) if hours == 1:
if minutes == 1:
result['publishedDate'] = gettext(u'1 hour, 1 minute ago')
else:
result['publishedDate'] = gettext(u'1 hour, {minutes} minutes ago').format(minutes=minutes)
else:
if minutes == 1:
result['publishedDate'] = gettext(u'{hours} hours, 1 minutes ago').format(hours=hours)
else:
result['publishedDate'] = gettext(u'{hours} hours, {minutes} minutes ago').format(hours=hours, minutes=minutes)
else: else:
result['publishedDate'] = format_date(result['publishedDate']) result['publishedDate'] = format_date(result['publishedDate'])