from datetime import datetime


def to_datetime(image_time: str, image_date: str) -> datetime:
    """builds datetime object

    Args:
        image_time (:obj:`string`): time when the image was captured
        image_date (:obj:`string`): date when the image was captured

    Returns:
        :obj:`datetime`: contructed datetime object

    Throws:
        :obj:`ValueError`: if length of date string is not 8 or length  of time string is not 6
    """

    if len(image_date) != 8 or len(image_time) != 6:
        raise ValueError('ERROR: Invalid length of input dates.')

    try:
        year = int(image_date[0:4])
        month = int(image_date[4:6])
        day = int(image_date[6:8])
        hour = int(image_time[0:2])
        minute = int(image_time[2:4])
        second = int(image_time[4:6])

        return datetime(year, month, day, hour, minute, second)
    except ValueError:
        # add error logging
        raise