def parse_duration(value: str) -> datetime.timedelta:
    "Parse a duration string and return a datetime.timedelta.\n\n    Args:\n        value (str): A time duration given as text. The preferred format for\n            durations is '%d %H:%M:%S.%f'. This function also supports ISO 8601\n            representation and PostgreSQL's day-time interval format.\n\n    Returns:\n        datetime.timedelta: An instance representing the duration.\n    "
    match = (standard_duration_re.match(value) or iso8601_duration_re.match(value) or postgres_interval_re.match(value))
    if match:
        kw = match.groupdict()
        days = datetime.timedelta(float((kw.pop('days', 0) or 0)))
        sign = ((- 1) if (kw.pop('sign', '+') == '-') else 1)
        if kw.get('microseconds'):
            kw['microseconds'] = kw['microseconds'].ljust(6, '0')
        if (kw.get('seconds') and kw.get('microseconds') and kw['seconds'].startswith('-')):
            kw['microseconds'] = ('-' + kw['microseconds'])
        kw = {k: float(v) for (k, v) in kw.items() if (v is not None)}
        return (days + (sign * datetime.timedelta(**kw)))
    else:
        raise ValueError(f'The time duration {value} cannot be parsed.')
Parse a duration string and return a datetime.timedelta.

Args:
    value (str): A time duration given as text. The preferred format for
        durations is '%d %H:%M:%S.%f'. This function also supports ISO 8601
        representation and PostgreSQL's day-time interval format.

Returns:
    datetime.timedelta: An instance representing the duration.
def parse_duration(value: str) -> datetime.timedelta:
    "Parse a duration string and return a datetime.timedelta.\n\n    Args:\n        value (str): A time duration given as text. The preferred format for\n            durations is '%d %H:%M:%S.%f'. This function also supports ISO 8601\n            representation and PostgreSQL's day-time interval format.\n\n    Returns:\n        datetime.timedelta: An instance representing the duration.\n    "
    match = (standard_duration_re.match(value) or iso8601_duration_re.match(value) or postgres_interval_re.match(value))
    if match:
        kw = match.groupdict()
        days = datetime.timedelta(float((kw.pop('days', 0) or 0)))
        sign = ((- 1) if (kw.pop('sign', '+') == '-') else 1)
        if kw.get('microseconds'):
            kw['microseconds'] = kw['microseconds'].ljust(6, '0')
        if (kw.get('seconds') and kw.get('microseconds') and kw['seconds'].startswith('-')):
            kw['microseconds'] = ('-' + kw['microseconds'])
        kw = {k: float(v) for (k, v) in kw.items() if (v is not None)}
        return (days + (sign * datetime.timedelta(**kw)))
    else:
        raise ValueError(f'The time duration {value} cannot be parsed.')