However, when user inputs durations > "23:59", re-displaying those
durations is kind of broken ("1 ..."). Customizing `prepare_value` is
rather straightforward, however I'd like to avoid rewriting the whole
`django.utils.duration.duration_string`. If that function would accept a
`use_days` argument, it would be a lot easier to achieve my use case.
--
Ticket URL: <https://code.djangoproject.com/ticket/33349>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* status: new => closed
* resolution: => wontfix
Comment:
Thanks for this ticket, however `duration_string` is a private
undocumented API and I don't think that adding a new option is justified
here. You can also re-use `_get_duration_components` to simplify your
implementation, e.g.:
{{{
def custom_duration_string(duration):
days, hours, minutes, seconds, microseconds =
_get_duration_components(duration)
if days:
hours += days * 24
string = '{:02d}:{:02d}:{:02d}'.format(hours, minutes, seconds)
if microseconds:
string += '.{:06d}'.format(microseconds)
return string
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/33349#comment:1>
Comment (by Claude Paroz):
OK, thanks for the code proposal.
--
Ticket URL: <https://code.djangoproject.com/ticket/33349#comment:2>
Comment (by Claude Paroz):
For my use case, I think the shorter would be:
{{{
def prepare_value(self, value):
if isinstance(value, datetime.timedelta):
seconds = value.days * 24 * 3600 + value.seconds
hours = seconds // 3600
minutes = seconds % 3600 // 60
value = '{:02d}:{:02d}'.format(hours, minutes)
return value
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/33349#comment:3>