Opened 6 years ago
Closed 6 years ago
#30918 closed Cleanup/optimization (fixed)
timesince() ignores time_strings argument for the same dates.
| Reported by: | Bas Van Gaalen | Owned by: | Hasan Ramezani |
|---|---|---|---|
| Component: | Utilities | Version: | dev |
| Severity: | Normal | Keywords: | timesince |
| Cc: | Triage Stage: | Accepted | |
| Has patch: | yes | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | yes | UI/UX: | no |
Description
In the code, when delta is datetime.timedelta(0) (line 66), the condition since <= 0 becomes true (line 70) and the function will return this:
return avoid_wrapping(gettext('0 minutes')) (line 72)
This should probably be:
return avoid_wrapping(time_strings['minute'] % 0)
Or alternatively the condition could be changed to since < 0.
Change History (4)
comment:1 by , 6 years ago
| Summary: | django.utils.timesince.timesince may return "0 minutes" ignoring the time_strings → timesince() ignores time_strings argument for the same dates. |
|---|---|
| Triage Stage: | Unreviewed → Accepted |
| Type: | Bug → Cleanup/optimization |
| Version: | 2.2 → master |
comment:2 by , 6 years ago
| Owner: | changed from to |
|---|---|
| Status: | new → assigned |
comment:3 by , 6 years ago
| Has patch: | set |
|---|
Note: naturaltime doesn't fall back to timesince() if the value is less than a day old, moreover the time_string argument is not documented, so it's not an issue in supported use cases. However, I agree that we can change this for consistency because someone can use timesince()/timeuntil() in custom filters.
Thanks for this report. I'm not sure if it's an issue for any language but I agree that we should use
time_strings['minute'] % 0.