def try_parse_timedelta_with_formats(
    timedelta_str: str,
    timedelta_formats: List[str]
) -> Tuple[Optional[timedelta], Optional[str], Optional[Exception]]:
    """Try parsing the datetime delta string with a list of formats
    Parameters
    ----------
    timedelta_str: str
        The timedelta string needs to be parsed (e.g. 12:34:56)
    timedelta_formats: List[str]
        A list of datetime formats that the parser would try to match

    Returns
    -------
    dict_obj: A serializable dictionary with enough metadata to reconstruct
              `obj`

    Exceptions
    ----------
    Tuple[Optional[timedelta], Optional[str], Optional[Exception]]:
        If the timedelta can be successfully parsed, the first element is the
        paresd timedelta object and the second is the matched format.
        If the timedelta cannot be parsed, the first and second element will be
        None, and the third is the exception from the datetime.strptime()
        method.
    """

    for fmt in timedelta_formats:
        try:
            # If singular form %S, %M, %H, will just return the timedelta
            if fmt == '%S':
                td = timedelta(seconds=int(timedelta_str))
            elif fmt == '%M':
                td = timedelta(minutes=int(timedelta_str))
            elif fmt == '%H':
                td = timedelta(hours=int(timedelta_str))
            else:
                dt = datetime.strptime(timedelta_str, fmt)
                td = timedelta(hours=dt.hour,
                               minutes=dt.minute,
                               seconds=dt.second)
            return (td, fmt, None)
        except ValueError as ve:
            last_exception = ve

    return (None, None, last_exception)
Try parsing the datetime delta string with a list of formats
    Parameters
    ----------
    timedelta_str: str
        The timedelta string needs to be parsed (e.g. 12:34:56)
    timedelta_formats: List[str]
        A list of datetime formats that the parser would try to match

    Returns
    -------
    dict_obj: A serializable dictionary with enough metadata to reconstruct
              `obj`

    Exceptions
    ----------
    Tuple[Optional[timedelta], Optional[str], Optional[Exception]]:
        If the timedelta can be successfully parsed, the first element is the
        paresd timedelta object and the second is the matched format.
        If the timedelta cannot be parsed, the first and second element will be
        None, and the third is the exception from the datetime.strptime()
        method.
    
Solutions/CyberArkAudit/Data Connectors/.python_packages/lib/site-packages/azure/functions/_utils.py