Skip to content

Commit

Permalink
Update format_duration.py
Browse files Browse the repository at this point in the history
  • Loading branch information
ikostan committed Nov 5, 2024
1 parent ba3c860 commit 28a4a9c
Showing 1 changed file with 27 additions and 3 deletions.
30 changes: 27 additions & 3 deletions kyu_4/human_readable_duration_format/format_duration.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,19 +59,43 @@ def format_duration(seconds: int) -> str:
if years > 0:
result += f'{year}'

result = format_days(days, day, result)
result = format_hours(hours, hour, result)
result = format_minutes(minutes, seconds, minute, result)
result = format_seconds(seconds, second, result)

return result


def format_days(days: int, day: str, result: str) -> str:
"""
Format days for the final string
:param days:
:param day:
:param result:
:return:
"""
if days > 0 and result != '':
result += f', {day}'
elif days > 0:
result += f'{day}'

return result


def format_hours(hours: int, hour: str, result: str) -> str:
"""
Format hours for the final string
:param hours:
:param hour:
:param result:
:return:
"""
if hours > 0 and result != '':
result += f', {hour}'
elif hours > 0:
result += f'{hour}'

result = format_minutes(minutes, seconds, minute, result)
result = format_seconds(seconds, second, result)

return result


Expand Down

0 comments on commit 28a4a9c

Please sign in to comment.