#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)
Change History (12)
by , 17 years ago
| Attachment: | patch.timesince.diff added |
|---|
comment:1 by , 17 years ago
| Needs tests: | set |
|---|
by , 17 years ago
| Attachment: | timeuntil.date.diff added |
|---|
comment:2 by , 17 years ago
| Cc: | 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 , 17 years ago
| milestone: | → 1.1 |
|---|---|
| Triage Stage: | Unreviewed → Accepted |
comment:4 by , 17 years ago
This patch still applies cleanly. New tests fail before fix is applied and pass afterward. This should be ready for checkin.
comment:7 by , 17 years ago
| Resolution: | → fixed |
|---|---|
| Status: | new → closed |
Moved fix into timesince block so any use of timesince() will apply it, and added unit tests. Against Django r9739.