Add parameters force_hours, force_minutes.
This commit is contained in:
parent
5d9bbd68ee
commit
bfb06d46c9
1 changed files with 3 additions and 3 deletions
|
@ -19,7 +19,7 @@ def hms_to_seconds(hms):
|
||||||
seconds += float(parts[0])
|
seconds += float(parts[0])
|
||||||
return seconds
|
return seconds
|
||||||
|
|
||||||
def seconds_to_hms(seconds):
|
def seconds_to_hms(seconds, force_minutes=False, force_hours=False):
|
||||||
'''
|
'''
|
||||||
Convert integer number of seconds to an hh:mm:ss string.
|
Convert integer number of seconds to an hh:mm:ss string.
|
||||||
Only the necessary fields are used.
|
Only the necessary fields are used.
|
||||||
|
@ -28,9 +28,9 @@ def seconds_to_hms(seconds):
|
||||||
(minutes, seconds) = divmod(seconds, 60)
|
(minutes, seconds) = divmod(seconds, 60)
|
||||||
(hours, minutes) = divmod(minutes, 60)
|
(hours, minutes) = divmod(minutes, 60)
|
||||||
parts = []
|
parts = []
|
||||||
if hours:
|
if hours or force_hours:
|
||||||
parts.append(hours)
|
parts.append(hours)
|
||||||
if hours or minutes:
|
if hours or minutes or force_hours or force_minutes:
|
||||||
parts.append(minutes)
|
parts.append(minutes)
|
||||||
parts.append(seconds)
|
parts.append(seconds)
|
||||||
hms = ':'.join(f'{part:02d}' for part in parts)
|
hms = ':'.join(f'{part:02d}' for part in parts)
|
||||||
|
|
Loading…
Reference in a new issue