2
>>> from datetime import datetime, timedelta
3
>>> from django.utils.timesince import timesince, timeuntil
4
>>> from django.utils.tzinfo import LocalTimezone, FixedOffset
6
>>> t = datetime(2007, 8, 14, 13, 46, 0)
8
>>> onemicrosecond = timedelta(microseconds=1)
9
>>> onesecond = timedelta(seconds=1)
10
>>> oneminute = timedelta(minutes=1)
11
>>> onehour = timedelta(hours=1)
12
>>> oneday = timedelta(days=1)
13
>>> oneweek = timedelta(days=7)
14
>>> onemonth = timedelta(days=30)
15
>>> oneyear = timedelta(days=365)
21
# Microseconds and seconds are ignored.
22
>>> timesince(t, t+onemicrosecond)
24
>>> timesince(t, t+onesecond)
28
>>> timesince(t, t+oneminute)
30
>>> timesince(t, t+onehour)
32
>>> timesince(t, t+oneday)
34
>>> timesince(t, t+oneweek)
36
>>> timesince(t, t+onemonth)
38
>>> timesince(t, t+oneyear)
41
# Test multiple units.
42
>>> timesince(t, t+2*oneday+6*onehour)
44
>>> timesince(t, t+2*oneweek+2*oneday)
47
# If the two differing units aren't adjacent, only the first unit is displayed.
48
>>> timesince(t, t+2*oneweek+3*onehour+4*oneminute)
50
>>> timesince(t, t+4*oneday+5*oneminute)
53
# When the second date occurs before the first, we should always get 0 minutes.
54
>>> timesince(t, t-onemicrosecond)
56
>>> timesince(t, t-onesecond)
58
>>> timesince(t, t-oneminute)
60
>>> timesince(t, t-onehour)
62
>>> timesince(t, t-oneday)
64
>>> timesince(t, t-oneweek)
66
>>> timesince(t, t-onemonth)
68
>>> timesince(t, t-oneyear)
70
>>> timesince(t, t-2*oneday-6*onehour)
72
>>> timesince(t, t-2*oneweek-2*oneday)
74
>>> timesince(t, t-2*oneweek-3*onehour-4*oneminute)
76
>>> timesince(t, t-4*oneday-5*oneminute)
79
# When using two different timezones.
80
>>> now = datetime.now()
81
>>> now_tz = datetime.now(LocalTimezone(now))
82
>>> now_tz_i = datetime.now(FixedOffset((3 * 60) + 15))
87
>>> timeuntil(now_tz, now_tz_i)