diff --git a/modules/utility.cpython-312.pyc b/modules/utility.cpython-312.pyc new file mode 100644 index 0000000..e4bf579 Binary files /dev/null and b/modules/utility.cpython-312.pyc differ diff --git a/modules/utility.py b/modules/utility.py new file mode 100644 index 0000000..bec6ebd --- /dev/null +++ b/modules/utility.py @@ -0,0 +1,34 @@ +import time + +def format_uptime(seconds: float) -> str: + """ + Convert seconds into a human-readable string: + e.g. 32 minutes, 8 days, 8 months, etc. + """ + # Convert float seconds to an integer + seconds = int(seconds) + + # We'll break it down + minutes, seconds = divmod(seconds, 60) + hours, minutes = divmod(minutes, 60) + days, hours = divmod(hours, 24) + # For months and years, let's approximate 30 days per month, + # 365 days per year, etc. (just a rough approach) + + months, days = divmod(days, 30) + years, months = divmod(months, 12) + + # Build a short string, only listing the largest units + # If you want more detail, you can keep going + if years > 0: + return f"{years} year(s), {months} month(s)" + elif months > 0: + return f"{months} month(s), {days} day(s)" + elif days > 0: + return f"{days} day(s), {hours} hour(s)" + elif hours > 0: + return f"{hours} hour(s), {minutes} minute(s)" + elif minutes > 0: + return f"{minutes} minute(s)" + else: + return f"{seconds} second(s)" \ No newline at end of file