def timedelta_to_iso_duration(value: timedelta) -> str:
    seconds = value.total_seconds()
    sign = ('-' if (seconds < 0) else '')
    seconds = abs(seconds)
    (minutes, seconds) = divmod(seconds, 60)
    (hours, minutes) = divmod(minutes, 60)
    (days, hours) = divmod(hours, 24)
    (weeks, days) = divmod(days, 7)
    (weeks, days, hours, minutes) = map(int, (weeks, days, hours, minutes))
    seconds = round(seconds, 6)
    iso_8601 = (sign + 'P')
    iso_8601_date = ''
    iso_8601_time = ''
    if weeks:
        iso_8601_date += f'{weeks}W'
    if days:
        iso_8601_date += f'{days}D'
    if hours:
        iso_8601_time += f'{hours}H'
    if minutes:
        iso_8601_time += f'{minutes}M'
    if seconds:
        if seconds.is_integer():
            iso_8601_time += f'{int(seconds)}S'
        else:
            iso_8601_time += f'{seconds}S'
    return (f'{iso_8601}{iso_8601_date}' + (f'T{iso_8601_time}' if iso_8601_time else ''))
def timedelta_to_iso_duration(value: timedelta) -> str:
    seconds = value.total_seconds()
    sign = ('-' if (seconds < 0) else )
    seconds = abs(seconds)
    (minutes, seconds) = divmod(seconds, 60)
    (hours, minutes) = divmod(minutes, 60)
    (days, hours) = divmod(hours, 24)
    (weeks, days) = divmod(days, 7)
    (weeks, days, hours, minutes) = map(int, (weeks, days, hours, minutes))
    seconds = round(seconds, 6)
    iso_8601 = (sign + 'P')
    iso_8601_date = 
    iso_8601_time = 
    if weeks:
        iso_8601_date += f'{weeks}W'
    if days:
        iso_8601_date += f'{days}D'
    if hours:
        iso_8601_time += f'{hours}H'
    if minutes:
        iso_8601_time += f'{minutes}M'
    if seconds:
        if seconds.is_integer():
            iso_8601_time += f'{int(seconds)}S'
        else:
            iso_8601_time += f'{seconds}S'
    return (f'{iso_8601}{iso_8601_date}' + (f'T{iso_8601_time}' if iso_8601_time else ))