def identify_datetime_format()

in libs/libcommon/src/libcommon/utils.py [0:0]


def identify_datetime_format(datetime_string: str) -> Optional[str]:
    # Common datetime formats
    common_formats = [
        "%Y-%m-%dT%H:%M:%S%Z",
        "%Y-%m-%dT%H:%M:%S%z",
        "%Y-%m-%dT%H:%M:%S",
        "%Y-%m-%dT%H:%M:%S.%f",
        "%Y-%m-%d %H:%M:%S%Z",
        "%Y-%m-%d %H:%M:%S%z",
        "%Y-%m-%d %H:%M:%S",
        "%Y-%m-%d %H:%M",
        "%Y-%m-%d",
        "%d-%m-%Y %H:%M:%S%Z",
        "%d-%m-%Y %H:%M:%S%z",
        "%d-%m-%Y %H:%M:%S",
        "%d-%m-%Y %H:%M",
        "%d-%m-%Y",
        "%m-%d-%Y %H:%M:%S%Z",
        "%m-%d-%Y %H:%M:%S%z",
        "%m-%d-%Y %H:%M:%S",
        "%m-%d-%Y %H:%M",
        "%m-%d-%Y",
        "%Y/%m/%d %H:%M:%S%Z",
        "%Y/%m/%d %H:%M:%S%z",
        "%Y/%m/%d %H:%M:%S",
        "%Y/%m/%d %H:%M",
        "%Y/%m/%d",
        "%d/%m/%Y %H:%M:%S%Z",
        "%d/%m/%Y %H:%M:%S%z",
        "%d/%m/%Y %H:%M:%S",
        "%d/%m/%Y %H:%M",
        "%d/%m/%Y",
        "%m/%d/%Y %H:%M:%S%Z",
        "%m/%d/%Y %H:%M:%S%z",
        "%m/%d/%Y %H:%M:%S",
        "%m/%d/%Y %H:%M",
        "%m/%d/%Y",
        "%B %d, %Y",
        "%d %B %Y",
        "%m-%Y",
        "%Y-%m",
        "%m/%Y",
        "%Y/%m",
        "%Y",
    ]

    for fmt in common_formats:
        try:
            _ = datetime.strptime(datetime_string, fmt)
            return fmt
        except ValueError:
            continue
    return None