From 8df01f7f3f141004a9bf2c48da2ccbe734932e9b Mon Sep 17 00:00:00 2001 From: Chris Hill-Scott Date: Thu, 6 Apr 2017 11:03:05 +0100 Subject: [PATCH] =?UTF-8?q?Fix=20future=20=E2=80=98last=20edited=E2=80=99?= =?UTF-8?q?=20date?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The `format_datetime_relative` filter is only used by the scheduling stuff, which only deals with dates in the future. When used on dates in the past (more than 1 day ago) it gets confused and defaults to ‘tomorrow’. The `format_delta` method does a similar thing, but works for past and future dates. Users can still click through to the next page to see the exact date and time of the edits. --- app/__init__.py | 13 ++++++++----- app/templates/views/templates/template.html | 2 +- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/app/__init__.py b/app/__init__.py index 035bb2a9b..a3e22afbd 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -279,12 +279,15 @@ def format_date_short(date): def format_delta(date): + delta = ( + datetime.now(timezone.utc) + ) - ( + gmt_timezones(date) + ) + if delta < timedelta(seconds=30): + return "just now" return ago.human( - ( - datetime.now(timezone.utc) - ) - ( - dateutil.parser.parse(date) - ), + delta, future_tense='{} from now', # No-one should ever see this past_tense='{} ago', precision=1 diff --git a/app/templates/views/templates/template.html b/app/templates/views/templates/template.html index f18226a98..b1f827535 100644 --- a/app/templates/views/templates/template.html +++ b/app/templates/views/templates/template.html @@ -24,7 +24,7 @@ {% if template._template.updated_at %}
-

Last edited {{ template._template.updated_at|format_datetime_relative }}

+

Last edited {{ template._template.updated_at|format_delta }}

See previous versions