-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
⚡✨ feat(utils): Add ormat_elapsed_time Utility for Human-Readable Tim…
…e Formatting #### Key Features: - Handles time durations less than a minute by returning only seconds. - For durations of one minute or more, returns the time in the format of 'X minute(s) and Y second(s)'. - Provides a clean and formatted output, ensuring clarity in time representation. This utility is useful for improving the readability of elapsed time in logging and performance measurement contexts.
- Loading branch information
1 parent
6367c51
commit 055424a
Showing
2 changed files
with
22 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
def format_elapsed_time(elapsed_time: float) -> str: | ||
"""Formats the elapsed time into a human-readable string. | ||
If the time is less than a minute, returns only seconds. Otherwise, | ||
returns the time in minutes and seconds. | ||
Args: | ||
elapsed_time: Time in seconds as a float. | ||
Returns: | ||
A string representing the formatted time. | ||
""" | ||
minutes, seconds = divmod(elapsed_time, 60) | ||
|
||
if minutes > 0: | ||
return f"{int(minutes)} minute(s) and {seconds:.2f} second(s)" | ||
return f"{seconds:.2f} second(s)" |