Opened 15 years ago

Closed 15 years ago

Last modified 12 years ago

#9672 closed (fixed)

timeuntil filters doesn't work with DateField since [8579]

Reported by: anonymous Owned by: mcroydon
Component: Template system Version: dev
Severity: Keywords: timeuntil timesince
Cc: ross@… Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Timeuntil filter doesn't work anymore since changset [8579] when using DateField:

>>> import datetime
>>> from django.template.defaultfilters import timeuntil,timesince
>>> timeuntil(datetime.datetime.now() + datetime.timedelta(1))
u'1 day'
>>> timesince(datetime.datetime.now()- datetime.timedelta(1))
u'1 day'
>>> timeuntil(datetime.date.today() + datetime.timedelta(1))
u''
>>> timesince(datetime.date.today() - datetime.timedelta(1))
u'1 day, 23 hours' 

With patch applied :

>>> import datetime
>>> from django.template.defaultfilters import timeuntil,timesince
>>> timeuntil(datetime.datetime.now() + datetime.timedelta(1))
u'1 day'
>>> timesince(datetime.datetime.now()- datetime.timedelta(1))
u'1 day'
>>> timeuntil(datetime.date.today() + datetime.timedelta(1))
u'33 minutes'
>>> timesince(datetime.date.today() - datetime.timedelta(1)) 
u'1 day, 23 hours'

timeuntil function should also convert input to datetime.datetime instance.

Attachments (2)

patch.timesince.diff (445 bytes ) - added by anonymous 15 years ago.
timeuntil.date.diff (1.6 KB ) - added by Ross Poulton 15 years ago.
Moved fix into timesince block so any use of timesince() will apply it, and added unit tests. Against Django r9739.

Download all attachments as: .zip

Change History (12)

by anonymous, 15 years ago

Attachment: patch.timesince.diff added

comment:1 by Collin Grady, 15 years ago

Needs tests: set

by Ross Poulton, 15 years ago

Attachment: timeuntil.date.diff added

Moved fix into timesince block so any use of timesince() will apply it, and added unit tests. Against Django r9739.

comment:2 by Ross Poulton, 15 years ago

Cc: ross@… added
Needs tests: unset

In my attachment I have moved the anonymous fix into the timesince block rather than timeuntil, so that any use of timesince from other places (eg direct usage in a view) will also pick up the same change. It also has the impact of causing timesince with a now input of type date (rather than datetime) to work correctly.

I've also added some unit tests to the patch, hopefully they are sufficient for checkin.

comment:3 by Jacob, 15 years ago

milestone: 1.1
Triage Stage: UnreviewedAccepted

comment:4 by mcroydon, 15 years ago

This patch still applies cleanly. New tests fail before fix is applied and pass afterward. This should be ready for checkin.

comment:5 by mcroydon, 15 years ago

Owner: changed from nobody to mcroydon

Looking at this a little closer.

comment:6 by Jacob, 15 years ago

This actually appears to have been fixed in [10215].

comment:7 by Jacob, 15 years ago

Resolution: fixed
Status: newclosed

comment:8 by Jacob, 15 years ago

(In [10440]) Added some tests to show that #9672 has been fixed ever since [10215]. Refs #9672.

comment:9 by Jacob, 15 years ago

(In [10441]) [1.0.X] Added some tests to show that #9672 has been fixed ever since [10215]. Refs #9672. Backport of r10440 from trunk.

comment:10 by Jacob, 12 years ago

milestone: 1.1

Milestone 1.1 deleted

Note: See TracTickets for help on using tickets.
Back to Top