From f61cf318ae8f992ee10d874d87778d084f411d60 Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Tue, 14 May 2019 15:58:43 -0500 Subject: [PATCH] Add `verbose` flag for `util.raw_datetime()` rendering just seems like could be useful somewhere...though not used yet --- tailbone/util.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) 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)