Opened 7 years ago

Closed 6 years ago

Last modified 4 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: UI/UX:

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 7 years ago.
timeuntil.date.diff (1.6 KB) - added by rossp 7 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 7 years ago by anonymous

comment:1 Changed 7 years ago by cgrady

  • Needs documentation unset
  • Needs tests set
  • Patch needs improvement unset

Changed 7 years ago by rossp

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

comment:2 Changed 7 years ago by rossp

  • 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 7 years ago by jacob

  • milestone set to 1.1
  • Triage Stage changed from Unreviewed to Accepted

comment:4 Changed 6 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 6 years ago by mcroydon

  • Owner changed from nobody to mcroydon

Looking at this a little closer.

comment:6 Changed 6 years ago by jacob

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

comment:7 Changed 6 years ago by jacob

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

comment:8 Changed 6 years ago by jacob

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

comment:9 Changed 6 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 4 years ago by jacob

  • milestone 1.1 deleted

Milestone 1.1 deleted

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