From 50e8637b715a55aba3ac87bbd96958041f4b7d98 Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Mon, 20 Jul 2015 09:52:24 -0500 Subject: [PATCH] Fix timezone issues with `util.pretty_datetime()` function. Seems we should just calculate the "time ago" value instead of just providing a "then" timestamp and expecting the humanize library to understand exactly what we meant. --- tailbone/util.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/tailbone/util.py b/tailbone/util.py index 2dfa399b..ba938edd 100644 --- a/tailbone/util.py +++ b/tailbone/util.py @@ -26,12 +26,14 @@ Utilities from __future__ import unicode_literals +import datetime + import pytz import humanize from webhelpers.html import HTML -from rattail.time import timezone +from rattail.time import timezone, make_utc def pretty_datetime(config, value): @@ -52,11 +54,13 @@ def pretty_datetime(config, value): if not value.tzinfo: value = pytz.utc.localize(value) - # Convert value to local timezone, and make a naive copy. + # Calculate time diff using UTC. + time_ago = datetime.datetime.utcnow() - make_utc(value) + + # Convert value to local timezone. local = timezone(config) value = local.normalize(value.astimezone(local)) - naive_value = value.replace(tzinfo=None) return HTML.tag('span', title=value.strftime('%Y-%m-%d %H:%M:%S %Z%z'), - c=humanize.naturaltime(naive_value)) + c=humanize.naturaltime(time_ago))