Skip to content

Commit

Permalink
[#518] Add time_ago_from_datestamp() helper
Browse files Browse the repository at this point in the history
  • Loading branch information
tobes committed Jul 18, 2013
1 parent 194be7c commit 003a211
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions ckan/lib/helpers.py
Expand Up @@ -934,6 +934,21 @@ def time_ago_in_words_from_str(date_str, granularity='month'):
return _('Unknown')


def time_ago_from_timestamp(timestamp):
''' Returns a string like `5 months ago` for a datetime relative to now
:param timestamp: the timestamp or datetime
:type timestamp: string or datetime
:rtype: string
'''
datetime_ = _datestamp_to_datetime(timestamp)
if not datetime_:
return _('Unknown')

# the localised date
return formatters.localised_nice_date(datetime_, show_date=False)


def button_attr(enable, type='primary'):
if enable:
return 'class="btn %s"' % type
Expand Down Expand Up @@ -1696,6 +1711,7 @@ def new_activities():
'localised_filesize',
'list_dict_filter',
'new_activities',
'time_ago_from_timestamp',
# imported into ckan.lib.helpers
'literal',
'link_to',
Expand Down

0 comments on commit 003a211

Please sign in to comment.