Ticket #9672: timeuntil.date.diff
File timeuntil.date.diff, 1.6 KB (added by , 16 years ago) |
---|
-
django/utils/timesince.py
34 34 now = datetime.datetime.now(LocalTimezone(d)) 35 35 else: 36 36 now = datetime.datetime.now() 37 38 # Convert datetime.date to datetime.datetime for comparison 39 if now.__class__ is not datetime.datetime: 40 now = datetime.datetime(now.year, now.month, now.day) 37 41 38 42 # ignore microsecond part of 'd' since we removed it from 'now' 39 43 delta = now - (d - datetime.timedelta(0, 0, d.microsecond)) … … 64 68 now = datetime.datetime.now(LocalTimezone(d)) 65 69 else: 66 70 now = datetime.datetime.now() 71 67 72 return timesince(now, d) -
tests/regressiontests/utils/timesince.py
1 1 """ 2 >>> from datetime import datetime, timedelta 2 >>> from datetime import datetime, timedelta, date 3 3 >>> from django.utils.timesince import timesince, timeuntil 4 4 >>> from django.utils.tzinfo import LocalTimezone, FixedOffset 5 5 … … 86 86 u'0 minutes' 87 87 >>> timeuntil(now_tz, now_tz_i) 88 88 u'0 minutes' 89 90 # Timeuntil should work with both date and datetime objects 91 >>> today = date.today() 92 >>> timeuntil(today+oneday, today) 93 u'1 day' 94 >>> timeuntil(today-oneday, today) 95 u'0 minutes' 96 >>> timeuntil(today+oneweek, today) 97 u'1 week' 89 98 """