def try_parse_datetime_with_formats(
    datetime_str: str,
    datetime_formats: List[str]
) -> Tuple[Optional[datetime], Optional[str], Optional[Exception]]:
    """Try parsing the datetime string with a list of formats
    Parameters
    ----------
    datetime_str: str
        The datetime string needs to be parsed (e.g. 2018-12-12T03:16:34.2191Z)
    datetime_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[datetime], Optional[str], Optional[Exception]]:
        If the datetime can be successfully parsed, the first element is the
        paresd datetime object and the second is the matched format.
        If the datetime 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 datetime_formats:
        try:
            dt = datetime.strptime(datetime_str, fmt)
            return (dt, fmt, None)
        except ValueError as ve:
            last_exception = ve

    return (None, None, last_exception)
Try parsing the datetime string with a list of formats
    Parameters
    ----------
    datetime_str: str
        The datetime string needs to be parsed (e.g. 2018-12-12T03:16:34.2191Z)
    datetime_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[datetime], Optional[str], Optional[Exception]]:
        If the datetime can be successfully parsed, the first element is the
        paresd datetime object and the second is the matched format.
        If the datetime 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