django-fitlog / fitlog / utils.py

from datetime import time


def addDateTimes(time_1, time_2):
    """
        Take in two datetime.time objects, add them up and return the total

        >>> datetime1 = datetime.time(hour=1,minute=1,second=1)
        >>> datetime2 = datetime.time(hour=1,minute=1,second=1)
        >>> addDateTimes(datetime1, datetime2)
        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
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.