Ticket #1385: timesince.patch

File timesince.patch, 1.0 KB (added by matt, 10 years ago)

Enable timesince with datetime.date

  • django/utils/timesince.py

     
    1515      (60 * 60, lambda n: ngettext('hour', 'hours', n)),
    1616      (60, lambda n: ngettext('minute', 'minutes', n))
    1717    )
     18    # Convert datetime.date to datetime.datetime for comparison   
     19    if d.__class__ is not datetime.datetime:
     20        d = datetime.datetime(d.year, d.month, d.day)
    1821    if now:
    1922        t = now.timetuple()
    2023    else:
  • tests/othertests/defaultfilters.py

     
    237237>>> timesince(datetime.datetime.now() - datetime.timedelta(1))
    238238'1 day'
    239239
     240# datetime.date compataibility with timesince
     241>>> timesince(datetime.date.today() - datetime.timedelta(1))
     242'1 day, 23 hours'
     243
    240244>>> default("val", "default")
    241245'val'
    242246
Back to Top