<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def parse_duration(duration, start=None, end=None):
 """ Attepmt to parse an ISO8601 formatted duration. Accepts a ``duration`` and optionally a start or end ``datetime``. ``duration`` must be an ISO8601 formatted string. Returns a ``datetime.timedelta`` object. """

    if not start and not end:
        return parse_simple_duration(duration)

    if start:
        return parse_duration_with_start(start, duration)

    if end:
        return parse_duration_with_end(duration, end)