Opened 10 years ago

Closed 9 years ago

Last modified 7 years ago

#9672 closed (fixed)

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

Reported by: anonymous Owned by: mcroydon
Component: Template system Version: master
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 10 years ago.
timeuntil.date.diff (1.6 KB) - added by Ross Poulton 10 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)

Changed 10 years ago by anonymous

Attachment: patch.timesince.diff added

comment:1 Changed 10 years ago by Collin Grady

Needs tests: set

Changed 10 years ago by Ross Poulton

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 Changed 10 years ago by Ross Poulton

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 Changed 10 years ago by Jacob

milestone: 1.1
Triage Stage: UnreviewedAccepted

comment:4 Changed 9 years ago by mcroydon

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

comment:5 Changed 9 years ago by mcroydon

Owner: changed from nobody to mcroydon

Looking at this a little closer.

comment:6 Changed 9 years ago by Jacob

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

comment:7 Changed 9 years ago by Jacob

Resolution: fixed
Status: newclosed

comment:8 Changed 9 years ago by Jacob

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

comment:9 Changed 9 years ago by Jacob

(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 Changed 7 years ago by Jacob

milestone: 1.1

Milestone 1.1 deleted

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