timedelta_str = '1 days, 0:00:00'
timedelta_str = '1:30:00'
def parse_timedelta(timedelta_str):
pattern = re.compile(r'((?P<days>\d+) days, )?(?P<hours>\d+):(?P<minutes>\d+):(?P<seconds>\d+)')
m = pattern.match(timedelta_str)
params = {key: float(val) for key, val in m.groupdict(0).items()}
return timedelta(**params)
print(parse_timedelta('1 days, 0:00:25'))
print(parse_timedelta('0:00:25'))
from datetime import timedelta
timedelta_str = '1 days, 0:00:00'
days,hours,minutes,seconds = map(float, timedelta_str.replace('days,', ":").split(':'))
t_delta = timedelta(days=days,hours=hours, minutes=minutes, seconds=seconds)
print(t_delta,type(t_delta))
1 day, 0:00:00 <class 'datetime.timedelta'>