Opened 9 years ago

Closed 9 years ago

#26317 closed Bug (invalid)

django.utils.duration.duration_string() doesn't support negative durations

Reported by: Nikolas N Owned by: nobody
Component: Utilities Version: 1.9
Severity: Normal Keywords: duration, timedelta
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

duration_string() formats timedeltas like this:

duration_string(timedelta(hours=1))
'01:00:00'

Given a negative hour, I would expect duration_string() to return something like "-01:00:00". Instead, you get this:

duration_string(timedelta(hours=-1))
'-1 23:00:00'

Change History (1)

comment:1 by Tim Graham, 9 years ago

Resolution: invalid
Status: newclosed

The behavior seems consistent with str(timedelta(hours=-1)) which gives '-1 day, 23:00:00'. See Python's docs that explains normalization of negative values.

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