“Prettify” seconds

secsToDHM (seconds)

This “prettifies” seconds by returning a string of the amount of hours and minutes the given seconds convert to. Days are also included, if hours are 24 or over. Example of a returned string:
“3 days, 8 hours, 23 minutes”

def secsToDHM(seconds: int) -> str:
	minutes = round(seconds / 60)
	hours = round(minutes / 60)
	remM = minutes % 60
	days = 0

	if hours >= 24:
		days = round(hours / 24)
		remH = hours % 24

	if (days > 0):
		return f"{days} days, {remH} hours, {remM} minutes"

	return f"{hours} hours, {remM} minutes"

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *