diff options
| author | Malcolm Tredinnick <malcolm.tredinnick@gmail.com> | 2008-08-26 08:08:55 +0000 |
|---|---|---|
| committer | Malcolm Tredinnick <malcolm.tredinnick@gmail.com> | 2008-08-26 08:08:55 +0000 |
| commit | 3111d7f60b67d5aefa4d891d1d9a86ba56d7607c (patch) | |
| tree | 347fb6354a1108a9435d01a6740f756dc9f50a82 /tests | |
| parent | 61957df17f5555409f689c29b8d75bef9f998c21 (diff) | |
Fixed #7201 -- Fixed the timeuntil filter to work correctly with timezone-aware
times. Patch from Jeremy Carbaugh.
This is backwards incompatible in the sense that previously, if you tried to
compare timezone-aware and timezone-naive values, you got an incorrect result.
Now you get an empty string. So your previously incorrect code returns a
different incorrect result.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@8579 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/regressiontests/templates/filters.py | 14 | ||||
| -rw-r--r-- | tests/regressiontests/utils/timesince.py | 14 |
2 files changed, 26 insertions, 2 deletions
diff --git a/tests/regressiontests/templates/filters.py b/tests/regressiontests/templates/filters.py index bb92336dcc..bee568698c 100644 --- a/tests/regressiontests/templates/filters.py +++ b/tests/regressiontests/templates/filters.py @@ -9,7 +9,7 @@ consistent. from datetime import datetime, timedelta -from django.utils.tzinfo import LocalTimezone +from django.utils.tzinfo import LocalTimezone, FixedOffset from django.utils.safestring import mark_safe # These two classes are used to test auto-escaping of __unicode__ output. @@ -27,6 +27,7 @@ class SafeClass: def get_filter_tests(): now = datetime.now() now_tz = datetime.now(LocalTimezone(now)) + now_tz_i = datetime.now(FixedOffset((3 * 60) + 15)) # imaginary time zone return { # Default compare with datetime.now() 'filter-timesince01' : ('{{ a|timesince }}', {'a': datetime.now() + timedelta(minutes=-1, seconds = -10)}, '1 minute'), @@ -46,6 +47,14 @@ def get_filter_tests(): 'filter-timesince09': ('{{ later|timesince }}', { 'later': now + timedelta(days=7) }, '0 minutes'), 'filter-timesince10': ('{{ later|timesince:now }}', { 'now': now, 'later': now + timedelta(days=7) }, '0 minutes'), + # Ensures that differing timezones are calculated correctly + 'filter-timesince11' : ('{{ a|timesince }}', {'a': now}, '0 minutes'), + 'filter-timesince12' : ('{{ a|timesince }}', {'a': now_tz}, '0 minutes'), + 'filter-timesince13' : ('{{ a|timesince }}', {'a': now_tz_i}, '0 minutes'), + 'filter-timesince14' : ('{{ a|timesince:b }}', {'a': now_tz, 'b': now_tz_i}, '0 minutes'), + 'filter-timesince15' : ('{{ a|timesince:b }}', {'a': now, 'b': now_tz_i}, ''), + 'filter-timesince16' : ('{{ a|timesince:b }}', {'a': now_tz_i, 'b': now}, ''), + # Default compare with datetime.now() 'filter-timeuntil01' : ('{{ a|timeuntil }}', {'a':datetime.now() + timedelta(minutes=2, seconds = 10)}, '2 minutes'), 'filter-timeuntil02' : ('{{ a|timeuntil }}', {'a':(datetime.now() + timedelta(days=1, seconds = 10))}, '1 day'), @@ -61,6 +70,9 @@ def get_filter_tests(): 'filter-timeuntil08': ('{{ later|timeuntil }}', { 'later': now + timedelta(days=7, hours=1) }, '1 week'), 'filter-timeuntil09': ('{{ later|timeuntil:now }}', { 'now': now, 'later': now + timedelta(days=7) }, '1 week'), + # Ensures that differing timezones are calculated correctly + 'filter-timeuntil10' : ('{{ a|timeuntil }}', {'a': now_tz_i}, '0 minutes'), + 'filter-timeuntil11' : ('{{ a|timeuntil:b }}', {'a': now_tz_i, 'b': now_tz}, '0 minutes'), 'filter-addslash01': ("{% autoescape off %}{{ a|addslashes }} {{ b|addslashes }}{% endautoescape %}", {"a": "<a>'", "b": mark_safe("<a>'")}, ur"<a>\' <a>\'"), 'filter-addslash02': ("{{ a|addslashes }} {{ b|addslashes }}", {"a": "<a>'", "b": mark_safe("<a>'")}, ur"<a>\' <a>\'"), diff --git a/tests/regressiontests/utils/timesince.py b/tests/regressiontests/utils/timesince.py index 4f304ec7f7..d4c671f2e2 100644 --- a/tests/regressiontests/utils/timesince.py +++ b/tests/regressiontests/utils/timesince.py @@ -1,6 +1,7 @@ """ >>> from datetime import datetime, timedelta ->>> from django.utils.timesince import timesince +>>> from django.utils.timesince import timesince, timeuntil +>>> from django.utils.tzinfo import LocalTimezone, FixedOffset >>> t = datetime(2007, 8, 14, 13, 46, 0) @@ -74,4 +75,15 @@ u'0 minutes' u'0 minutes' >>> timesince(t, t-4*oneday-5*oneminute) u'0 minutes' + +# When using two different timezones. +>>> now = datetime.now() +>>> now_tz = datetime.now(LocalTimezone(now)) +>>> now_tz_i = datetime.now(FixedOffset((3 * 60) + 15)) +>>> timesince(now) +u'0 minutes' +>>> timesince(now_tz) +u'0 minutes' +>>> timeuntil(now_tz, now_tz_i) +u'0 minutes' """ |
