from datetime import datetime


def parse_time(dt_str):
    """
    Parse a YYYYMMDD[HH[MM]] type string. HH and MM are optional.

    :param dt_str: datetime string to parse
    :return: interpreted datetime
    """
    year = int(dt_str[:4])
    month = int(dt_str[4:6] or 1)
    day = int(dt_str[6:8] or 1)
    hour = int(dt_str[8:10] or 0)
    minute = int(dt_str[10:12] or 0)
    return datetime(year, month, day, hour, minute)