Commits

Anonymous committed f6df699

Fixed #2163 -- Corrected typo when handling datetimes with timezones in the timesince filter. Thanks, Alex Dedul.

  • Participants
  • Parent commits 198485c

Comments (0)

Files changed (2)

django/utils/timesince.py

     else:
         t = time.localtime()
     if d.tzinfo:
-        tz = LocalTimezone()
+        tz = LocalTimezone(d)
     else:
         tz = None
     now = datetime.datetime(t[0], t[1], t[2], t[3], t[4], t[5], tzinfo=tz)

tests/othertests/templates.py

 from django import template
 from django.template import loader
 from django.utils.translation import activate, deactivate, install
+from django.utils.tzinfo import LocalTimezone
 from datetime import datetime, timedelta
 import traceback
 
     def method(self):
         return "OtherClass.method"
 
-# NOW used by timesince tag tests.
+# NOW and NOW_tz are used by timesince tag tests.
 NOW = datetime.now()
+NOW_tz = datetime.now(LocalTimezone(datetime.now()))
 
 # SYNTAX --
 # 'template_name': ('template contents', 'context dict', 'expected string output' or Exception class)
     'timesince04' : ('{{ a|timesince:b }}', {'a':NOW + timedelta(days=2), 'b':NOW + timedelta(days=1)}, '1 day'),
     'timesince05' : ('{{ a|timesince:b }}', {'a':NOW + timedelta(days=2), 'b':NOW + timedelta(days=2)}, '0 minutes'),
 
+    # Check that timezone is respected
+    'timesince06' : ('{{ a|timesince:b }}', {'a':NOW_tz + timedelta(hours=8), 'b':NOW_tz}, '8 hours'),
+
     ### TIMEUNTIL TAG ##################################################
     # Default compare with datetime.now()
     'timeuntil01' : ('{{ a|timeuntil }}', {'a':datetime.now()}, '0 minutes'),