import re


def validate_date(date: str) -> dict:
    """
    Validate provided date data.
    Desired format: YYYY or YYYY-MM (2021 or 2021-12).
    """
    # regex patters
    rp_year_month = re.compile('^(20[0-9]{2})-((0[1-9])|(1[0-2]))$')
    rp_year = re.compile('^(20[0-9]{2})$')
    # Match year-month object
    mo = rp_year_month.match(date)
    if mo:
        return {
            'year': mo.groups()[0],
            'month': mo.groups()[1]
        }
    # Match year object
    mo = rp_year.match(date)
    if mo:
        return {
            'year': mo.groups()[0]
        }
    return {}