def ensure_tz(tz):
    if isinstance(tz, datetime.tzinfo):
        return tz

    if tz is None:
        return UTC

    if isinstance(tz, str):
        try:
            return pytz.timezone(tz)
        except pytz.exceptions.UnknownTimeZoneError:
            raise ValueError("not a time zone: {}".format(tz))

    raise TypeError("not a time zone: {!r}".format(tz))
Attempts to convert an object to a time zone.
dataset/ETHPy150Open twosigma/ngrid/ngrid/datetime.py/ensure_tz