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

git-svn-id: http://code.djangoproject.com/svn/django/trunk@3186 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Malcolm Tredinnick 2006-06-21 11:11:03 +00:00
parent 239adf83d3
commit ae1234f2a2
2 changed files with 7 additions and 2 deletions

View File

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

View File

@ -4,6 +4,7 @@ from django.conf import settings
from django import template from django import template
from django.template import loader from django.template import loader
from django.utils.translation import activate, deactivate, install from django.utils.translation import activate, deactivate, install
from django.utils.tzinfo import LocalTimezone
from datetime import datetime, timedelta from datetime import datetime, timedelta
import traceback import traceback
@ -57,8 +58,9 @@ class OtherClass:
def method(self): def method(self):
return "OtherClass.method" return "OtherClass.method"
# NOW used by timesince tag tests. # NOW and NOW_tz are used by timesince tag tests.
NOW = datetime.now() NOW = datetime.now()
NOW_tz = datetime.now(LocalTimezone(datetime.now()))
# SYNTAX -- # SYNTAX --
# 'template_name': ('template contents', 'context dict', 'expected string output' or Exception class) # 'template_name': ('template contents', 'context dict', 'expected string output' or Exception class)
@ -545,6 +547,9 @@ TEMPLATE_TESTS = {
'timesince04' : ('{{ a|timesince:b }}', {'a':NOW + timedelta(days=2), 'b':NOW + timedelta(days=1)}, '1 day'), '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'), '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 ################################################## ### TIMEUNTIL TAG ##################################################
# Default compare with datetime.now() # Default compare with datetime.now()
'timeuntil01' : ('{{ a|timeuntil }}', {'a':datetime.now()}, '0 minutes'), 'timeuntil01' : ('{{ a|timeuntil }}', {'a':datetime.now()}, '0 minutes'),