def get_cool_off_iso8601(delta: timedelta) -> str:
    """
    Return datetime.timedelta translated to ISO 8601 formatted duration for use in e.g. cool offs.
    """

    seconds = delta.total_seconds()
    minutes, seconds = divmod(seconds, 60)
    hours, minutes = divmod(minutes, 60)
    days, hours = divmod(hours, 24)

    days_str = f'{days:.0f}D' if days else ''

    time_str = ''.join(
        f'{value:.0f}{designator}'
        for value, designator
        in [
            [hours, 'H'],
            [minutes, 'M'],
            [seconds, 'S'],
        ]
        if value
    )

    if time_str:
        return f'P{days_str}T{time_str}'
    return f'P{days_str}'
def get_cool_off_iso8601 ( delta : timedelta ) -> str : seconds = delta . total_seconds ( ) minutes , seconds = divmod ( seconds , 60 ) hours , minutes = divmod ( minutes , 60 ) days , hours = divmod ( hours , 24 ) days_str = f'{days:.0f}D' if days else '' time_str = '' . join ( f'{value:.0f}{designator}' for value , designator in [ [ hours , 'H' ] , [ minutes , 'M' ] , [ seconds , 'S' ] , ] if value ) if time_str : return f'P{days_str}T{time_str}' return f'P{days_str}'
Return datetime.timedelta translated to ISO 8601 formatted duration for use in e.g. cool offs.