Ticket #5054: 0001-Use-UTC-for-all-timesince-comparisons.patch

File 0001-Use-UTC-for-all-timesince-comparisons.patch, 1.9 KB (added by ayleph, 10 years ago)
  • mediagoblin/tests/test_timesince.py

    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  
    1616
    1717from datetime import datetime, timedelta
    1818
    19 from mediagoblin.tools.timesince import is_aware, timesince
     19from mediagoblin.tools.timesince import timesince
    2020
    2121
    2222def test_timesince():
  • mediagoblin/tools/timesince.py

    diff --git a/mediagoblin/tools/timesince.py b/mediagoblin/tools/timesince.py
    index b761c1b..7a8b3ff 100644
    a b import pytz  
    3333
    3434from mediagoblin.tools.translate import pass_to_ugettext, lazy_pass_to_ungettext as _
    3535
    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 
    4836def timesince(d, now=None, reversed=False):
    4937    """
    5038    Takes two datetime objects and returns the time between d and now
    def timesince(d, now=None, reversed=False):  
    7361        now = datetime.datetime(now.year, now.month, now.day)
    7462
    7563    if not now:
    76         now = datetime.datetime.now(utc if is_aware(d) else None)
     64        now = datetime.datetime.utcnow()
    7765
    7866    delta = (d - now) if reversed else (now - d)
    7967    # ignore microseconds