Source

django-fitlog / fitlog / utils.py

Full commit
from datetime import time

def addDateTimes(time_1,time_2):
    """
        Take in two datetime.time objects, add them up and return the total
        
        >>> addDateTimes(datetime.time(hour=1,minute=1,second=1),datetime.time(hour=1,minute=1,second=1))
        datetime.time(2,2,2)
        
    """
    if time_1 and not time_2:
        return time_1
    elif time_2 and not time_1:
        return time_2
    elif not time_1 and not time_2:
        return None
    else:
        t1_h = time_1.hour
        t2_h = time_2.hour
        t1_m = time_1.minute
        t2_m = time_2.minute
        t1_s = time_1.second
        t2_s = time_2.second
        
        t_h = t1_h + t2_h
        t_m = t1_m + t2_m
        t_s = t1_s + t2_s
        
        s_r = t_s/60
        s = t_s%60
        
        t_m = t_m + s_r
        m_r = t_m / 60
        m = t_m%60
        
        h = t_h + m_r
        
        return_time = time(hour=h,minute=m,second=s)
        return return_time