From baed9663388e6d1b792f8da402e26739113ee3e6 Mon Sep 17 00:00:00 2001
From: ayleph <ayleph@thisshitistemp.com>
Date: Tue, 10 Mar 2015 23:55:51 -0700
Subject: [PATCH] Use UTC for all timesince comparisons
---
mediagoblin/tests/test_timesince.py | 2 +-
mediagoblin/tools/timesince.py | 14 +-------------
2 files changed, 2 insertions(+), 14 deletions(-)
diff --git a/mediagoblin/tests/test_timesince.py b/mediagoblin/tests/test_timesince.py
index 6579eb0..99ae31d 100644
a
|
b
|
|
16 | 16 | |
17 | 17 | from datetime import datetime, timedelta |
18 | 18 | |
19 | | from mediagoblin.tools.timesince import is_aware, timesince |
| 19 | from mediagoblin.tools.timesince import timesince |
20 | 20 | |
21 | 21 | |
22 | 22 | def test_timesince(): |
diff --git a/mediagoblin/tools/timesince.py b/mediagoblin/tools/timesince.py
index b761c1b..7a8b3ff 100644
a
|
b
|
import pytz
|
33 | 33 | |
34 | 34 | from mediagoblin.tools.translate import pass_to_ugettext, lazy_pass_to_ungettext as _ |
35 | 35 | |
36 | | """UTC time zone as a tzinfo instance.""" |
37 | | utc = pytz.utc if pytz else UTC() |
38 | | |
39 | | def is_aware(value): |
40 | | """ |
41 | | Determines if a given datetime.datetime is aware. |
42 | | |
43 | | The logic is described in Python's docs: |
44 | | http://docs.python.org/library/datetime.html#datetime.tzinfo |
45 | | """ |
46 | | return value.tzinfo is not None and value.tzinfo.utcoffset(value) is not None |
47 | | |
48 | 36 | def timesince(d, now=None, reversed=False): |
49 | 37 | """ |
50 | 38 | Takes two datetime objects and returns the time between d and now |
… |
… |
def timesince(d, now=None, reversed=False):
|
73 | 61 | now = datetime.datetime(now.year, now.month, now.day) |
74 | 62 | |
75 | 63 | if not now: |
76 | | now = datetime.datetime.now(utc if is_aware(d) else None) |
| 64 | now = datetime.datetime.utcnow() |
77 | 65 | |
78 | 66 | delta = (d - now) if reversed else (now - d) |
79 | 67 | # ignore microseconds |