a project I'm building takes different time lengths from album tracklists in as strings, and I want to add them up cumulatively. The inputs can vary in unpredictability, such as the following list of input time strings:
inputs = ['0:32', '3:19', '11:22']
So I would want to add all these times up like so:
0:32 + 3:19 + 11:22 = = 15:13
I need to make sure the resulting time is a valid timestamp, so incrementing the second/minute/hours realistically is necessary
I figured the best way to do this would be to convert each string time to a python datetime object, but I'm having trouble thinking of how to do this realistically, since all my knowledge and examples I can find of converting a string to a datetime use hard-coded datetime templates, such as:
datetime_str = '09/19/18 13:55:26'
datetime_object = datetime.strptime(datetime_str, '%m/%d/%y %H:%M:%S')
I need to identify multiple different possible string-times, such as :
0:32 = %m:%S
23:19 = %M:%S
01:22:23 = %H:%M:%S
01:2:23 = %H:%m:%S
is there a way to automate this process of adding up multiple different timestamps? My thought process was take the time-string, convert to datetime, convert that datetimeObject to seconds, add them up, then convert it back to dateTime HH:MM:SS format. But I'm getting hung up on how many different possible time inputs I can receive. Any advice is much appreciated as to how I can solve this problem