From 28a4a9c4dc40c4ba1ff4af8386f5aabedea64426 Mon Sep 17 00:00:00 2001 From: Egor Kostan Date: Mon, 4 Nov 2024 20:02:15 -0800 Subject: [PATCH] Update format_duration.py --- .../format_duration.py | 30 +++++++++++++++++-- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/kyu_4/human_readable_duration_format/format_duration.py b/kyu_4/human_readable_duration_format/format_duration.py index 49dbd564312..94f39286b35 100644 --- a/kyu_4/human_readable_duration_format/format_duration.py +++ b/kyu_4/human_readable_duration_format/format_duration.py @@ -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