Opened 5 years ago

Closed 5 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 Mariusz Felisiak, 5 years ago

Summary: django.utils.timesince.timesince may return "0 minutes" ignoring the time_stringstimesince() ignores time_strings argument for the same dates.
Triage Stage: UnreviewedAccepted
Type: BugCleanup/optimization
Version: 2.2master

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.

comment:2 by Hasan Ramezani, 5 years ago

Owner: changed from nobody to Hasan Ramezani
Status: newassigned
Last edited 5 years ago by Mariusz Felisiak (previous) (diff)

comment:3 by Mariusz Felisiak, 5 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.

comment:4 by Mariusz Felisiak <felisiak.mariusz@…>, 5 years ago

Resolution: fixed
Status: assignedclosed

In 52cb4190:

Fixed #30918 -- Made timesince()/timeuntil() respect custom time strings for future and the same datetimes.

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