from typing import Tuple


def calc_time(time: Tuple[int, int], start_time: str, start_tod: bool,
              end_time: str, end_tod: bool) -> Tuple[int, int]:
    """Calculates times. Takes previous hour and minute totals via time
    argument tuple, as well as arguments for calculating a new hour and
    minute total. It then adds them together and returns the resulting
    hours and minutes as a tuple.

    :param Tuple[int, int] time: Previous hour and minute total integers.
    :param str start_time: Formatted start time string.
    :param bool start_tod: Start time PM boolean identifier.
    :param str end_time: Formatted end time string.
    :param bool end_tod: End time PM boolean identifier.
    :return: Newly updated hour and minute total integers.
    :rtype: Tuple[int, int]

    USAGE:

        >>> add_time = calc_time((2, 17), "1015", False, "0230", True)
        >>> assert add_time == (6, 32)
    """
    old_start: str
    old_end: str
    hours: int
    minutes: int
    previous_hours: int = time[0]
    previous_minutes: int = time[1]

    # Deal with new day hour rollover conversion.
    old_start, old_end = start_time, end_time
    if start_time == "1200":
        start_time = "0000"
    if end_time == "1200" and end_tod is False:
        end_time = "2400"
    if old_start == "1200" or old_end == "1200" and start_tod == end_tod:
        start_time = "00" + old_start[2:]
        end_time = "00" + old_end[2:]
    if old_start == old_end and start_tod == end_tod:
        start_time = "0000"
        end_time = "2400"

    start_hours: int = int(start_time[:2])  # Split up hours and minutes
    start_minutes: int = int(start_time[2:])  # and typecast.
    end_hours: int = int(end_time[:2])
    end_minutes: int = int(end_time[2:])

    # Convert from 12 to 24 hour format.
    if start_tod is True and end_tod is False:
        start_hours += 12
    if end_tod is True and start_tod is False:
        end_hours += 12

    if start_hours > end_hours:  # Adjustment when end time is in a new day.
        hours = (end_hours + 24) - start_hours
        hours += previous_hours
    else:
        hours = end_hours - start_hours  # Calculate hours worked.
        hours += previous_hours

    if start_minutes > end_minutes:  # Adjustment when minutes roll over hour.
        hours -= 1
        minutes = (end_minutes + 60) - start_minutes
        minutes += previous_minutes
    else:
        minutes = end_minutes - start_minutes  # Calculate minutes worked.
        minutes += previous_minutes

    if minutes >= 60:  # Adjustment when minutes roll over hour.
        hours += minutes // 60
        minutes = minutes % 60

    return (hours, minutes)