From bbe37492dcc8abbbb023307e6433b9b3f03a31f1 Mon Sep 17 00:00:00 2001 From: Jacob Kaplan-Moss Date: Tue, 7 Apr 2009 22:12:53 +0000 Subject: [PATCH] Added some tests to show that #9672 has been fixed ever since [10215]. Refs #9672. git-svn-id: http://code.djangoproject.com/svn/django/trunk@10440 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- tests/regressiontests/utils/timesince.py | 35 +++++++++++++++--------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/tests/regressiontests/utils/timesince.py b/tests/regressiontests/utils/timesince.py index d4c671f2e2..04878b272a 100644 --- a/tests/regressiontests/utils/timesince.py +++ b/tests/regressiontests/utils/timesince.py @@ -1,18 +1,18 @@ """ ->>> from datetime import datetime, timedelta +>>> import datetime >>> from django.utils.timesince import timesince, timeuntil >>> from django.utils.tzinfo import LocalTimezone, FixedOffset ->>> t = datetime(2007, 8, 14, 13, 46, 0) +>>> t = datetime.datetime(2007, 8, 14, 13, 46, 0) ->>> onemicrosecond = timedelta(microseconds=1) ->>> onesecond = timedelta(seconds=1) ->>> oneminute = timedelta(minutes=1) ->>> onehour = timedelta(hours=1) ->>> oneday = timedelta(days=1) ->>> oneweek = timedelta(days=7) ->>> onemonth = timedelta(days=30) ->>> oneyear = timedelta(days=365) +>>> onemicrosecond = datetime.timedelta(microseconds=1) +>>> onesecond = datetime.timedelta(seconds=1) +>>> oneminute = datetime.timedelta(minutes=1) +>>> onehour = datetime.timedelta(hours=1) +>>> oneday = datetime.timedelta(days=1) +>>> oneweek = datetime.timedelta(days=7) +>>> onemonth = datetime.timedelta(days=30) +>>> oneyear = datetime.timedelta(days=365) # equal datetimes. >>> timesince(t, t) @@ -77,13 +77,22 @@ u'0 minutes' 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)) +>>> now = datetime.datetime.now() +>>> now_tz = datetime.datetime.now(LocalTimezone(now)) +>>> now_tz_i = datetime.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' + +# Timesince should work with both date objects (#9672) +>>> today = datetime.date.today() +>>> timeuntil(today+oneday, today) +u'1 day' +>>> timeuntil(today-oneday, today) +u'0 minutes' +>>> timeuntil(today+oneweek, today) +u'1 week' """