Upload files to "modules"

main
kami 2025-02-01 11:07:36 +00:00
parent 72fb3f2a7d
commit ed54bf69ba
2 changed files with 34 additions and 0 deletions

Binary file not shown.

34
modules/utility.py Normal file
View File

@ -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)"