Code

Opened 8 years ago

Closed 8 years ago

Last modified 7 years ago

#1385 closed defect (fixed)

[PATCH] allow timesince filter to work with datetime.date objects

Reported by: matt Owned by: adrian
Component: Template system Version: master
Severity: normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

The timesince filter currently throws an AttributeError when applied to a datetime.date object:

'defaultfilters' module: API test raised an exception
=====================================================
Code: 'timesince(datetime.date.today() - datetime.timedelta(1))'
Line: 232
Exception:   File "/Users/mcroydon/django/django_src.trunk/tests/doctest.py", line 1243, in __run
    compileflags, 1) in test.globs
  File "<doctest defaultfilters[76]>", line 1, in ?
    timesince(datetime.date.today() - datetime.timedelta(1))
  File "/Users/mcroydon/django/django_src.trunk/django/core/template/defaultfilters.py", line 343, in timesince
    return timesince(value)
  File "/Users/mcroydon/django/django_src.trunk/django/utils/timesince.py", line 22, in timesince
    if d.tzinfo:
AttributeError: 'datetime.date' object has no attribute 'tzinfo'

The patch includes a test to confirm this behavior. The test passes after applying this patch.

Attachments (1)

timesince.patch (1.0 KB) - added by matt 8 years ago.
Enable timesince with datetime.date

Download all attachments as: .zip

Change History (3)

Changed 8 years ago by matt

Enable timesince with datetime.date

comment:1 Changed 8 years ago by adrian

  • Resolution set to fixed
  • Status changed from new to closed

(In [2375]) Fixed #1385 -- Allowed timesince filter to accept datetime.date objects. Thanks, Matt

comment:2 Changed 7 years ago by anonymous

  • milestone Version 1.0 deleted

Milestone Version 1.0 deleted

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.