Commit d9ba2172 authored by Bram Schoenmakers's avatar Bram Schoenmakers

Second attempt to make humanize_date() more deterministic

This reverts the first attempt (commit
8310b029), because relative dates in terms of
hours were printed.

This attempt passes the now object that we just created to humanize(), so that
will be used as a offset. If we don't supply that object, arrow will create a
different datetime object representing 'now', which might be slightly off
w.r.t. the now object we created.  Therefore the floating point arithmetic done
within the arrow library might not produce the desired results (delta / 86400).

By passing the offset ourselves I was able to produce reliable
results.
parent 8310b029
...@@ -113,5 +113,7 @@ def translate_key_to_config(p_key): ...@@ -113,5 +113,7 @@ def translate_key_to_config(p_key):
def humanize_date(p_datetime): def humanize_date(p_datetime):
""" Returns a relative date string from a datetime object. """ """ Returns a relative date string from a datetime object. """
return arrow.get(p_datetime).humanize().replace('just now', 'today') now = arrow.now()
date = now.replace(day=p_datetime.day, month=p_datetime.month, year=p_datetime.year)
return date.humanize(now).replace('just now', 'today')
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment