Dec-22-2022, 09:09 AM
Hope perfingo doesn't mind me infringing on his excellent function.
I was interested to see what happens when hour > 23 or time > 23:59:59
I was interested to see what happens when hour > 23 or time > 23:59:59
from datetime import timedelta add_time = {"23:00:15", "6:15:15", "5:15:15"} def convert(time_str): hrs, mins, secs = (int(unit) for unit in time_str.split(':')) return timedelta(hours=hrs, minutes=mins, seconds=secs) total = sum(map(convert, add_time), timedelta()) minute = 60 hour = minute * 60 seconds = total.seconds hours = divmod(seconds, hour) minutes = divmod(hours[1], minute) rem_seconds = minutes[1] print(f'the total time is {hours[0]}:{minutes[0]}:{minutes[1]}')Sure enough, looks like you won't get more than 23 hours!