mirror of https://github.com/snachodog/mybuddy.git
Add a short string duration utility function.
This commit is contained in:
parent
83aaab5bde
commit
f4d94a3ca0
|
@ -16,7 +16,7 @@ def filter_by_params(request, model, available_params):
|
||||||
|
|
||||||
|
|
||||||
def duration_string(duration):
|
def duration_string(duration):
|
||||||
"""Format hours, minutes and seconds in a human-friendly way (e.g. "2
|
"""Format hours, minutes and seconds as a human-friendly string (e.g. "2
|
||||||
hours, 25 minutes, 31 seconds")"""
|
hours, 25 minutes, 31 seconds")"""
|
||||||
h, m, s = duration_parts(duration)
|
h, m, s = duration_parts(duration)
|
||||||
|
|
||||||
|
@ -33,6 +33,12 @@ def duration_string(duration):
|
||||||
return duration
|
return duration
|
||||||
|
|
||||||
|
|
||||||
|
def duration_string_short(duration):
|
||||||
|
"""Format hours, minutes and seconds as a short string (e.g. "0h2m35s")."""
|
||||||
|
h, m, s = duration_parts(duration)
|
||||||
|
return '{}h{}m{}s'.format(h, m, s)
|
||||||
|
|
||||||
|
|
||||||
def duration_parts(duration):
|
def duration_parts(duration):
|
||||||
"""Get hours, minutes and seconds from a timedelta."""
|
"""Get hours, minutes and seconds from a timedelta."""
|
||||||
if not isinstance(duration, timezone.timedelta):
|
if not isinstance(duration, timezone.timedelta):
|
||||||
|
|
Loading…
Reference in New Issue