Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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
  • Loading branch information...
commit bbe37492dcc8abbbb023307e6433b9b3f03a31f1 1 parent 6d6bbb6
Jacob Kaplan-Moss jacobian authored
Showing with 22 additions and 13 deletions.
  1. +22 −13 tests/regressiontests/utils/timesince.py
35 tests/regressiontests/utils/timesince.py
View
@@ -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'
# 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'
"""
Please sign in to comment.
Something went wrong with that request. Please try again.