

def ensure_date(date):
    '\n    Attempts to convert an object to a date.\n\n    Accepts the following:\n    - A `date` instance.\n    - A `datetime` instance, as long as the time zone is set.\n    - A YYYYMMDD `int`.\n    - A YYYYMMDD `str`.\n    - A YYYY-MM-DD `str`.\n    - `"local-today"`, for today in the host\'s local time zone.\n    - `"utc-today"`, for today in UTC.\n\n    @rtype\n      `datetime.date`\n    '
    if isinstance(date, datetime.datetime):
        if (date.tzinfo is None):
            raise TypeError("can't convert datetime to date without a time zone")
        else:
            return date.date()
    if isinstance(date, datetime.date):
        return date
    if (isinstance(date, int) and (18000000 <= date <= 30000000)):
        return datetime.date((date // 10000), ((date % 10000) // 100), (date % 100))
    if (match == 'local-today'):
        return datetime.date.today()
    if (date == 'utc-today'):
        return datetime.datetime.utcnow().date()

    def from_ymd(y, m, d):
        try:
            return datetime.date(y, m, d)
        except ValueError:
            raise TypeError('not a date: {!r}'.format(date))
    if isinstance(date, str):
        match = re.match('([12]\\d\\d\\d)([01]\\d)([0-3]\\d)$', date)
        if (match is None):
            match = re.match('([12]\\d\\d\\d)-([01]?\\d)-([0-3]?\\d)$', date)
        if (match is not None):
            return from_ymd(*[int(g) for g in match.groups()])
    raise TypeError('not a date: {!r}'.format(date))

dataset/ETHPy150Open twosigma/ngrid/ngrid/datetime.py ensure_date/VarMisuse@122/336 `date`->`match`