diff --git a/tailbone/util.py b/tailbone/util.py index 862104e9..61fd37c8 100644 --- a/tailbone/util.py +++ b/tailbone/util.py @@ -80,7 +80,7 @@ def pretty_datetime(config, value): c=humanize.naturaltime(time_ago)) -def raw_datetime(config, value): +def raw_datetime(config, value, verbose=False): """ Formats a datetime as a "raw" human-readable string, with a tooltip showing the more human-friendly "time since" equivalent. @@ -113,9 +113,18 @@ def raw_datetime(config, value): else: kwargs['c'] = six.text_type(value) - # Avoid humanize error when calculating huge time diff. + # avoid humanize error when calculating huge time diff + time_diff = None if abs(time_ago.days) < 100000: - kwargs['title'] = humanize.naturaltime(time_ago) + time_diff = humanize.naturaltime(time_ago) + + # by "verbose" we mean the result text to look like "YYYY-MM-DD (X days ago)" + if verbose: + kwargs['c'] = "{} ({})".format(kwargs['c'], time_diff) + + # vs. if *not* verbose, text is "YYYY-MM-DD" but we add "X days ago" as title + else: + kwargs['title'] = time_diff return HTML.tag('span', **kwargs)