def date_cast(date):
    if date is None:
        return datetime.datetime.now()
    elif isinstance(date, datetime.datetime):
        return date

    # fuzzy date
    try:
        if isinstance(date, six.string_types):
            try:
                if HAS_TIMELIB:
                    # py3: yes, timelib.strtodatetime wants bytes, not str :/
                    return timelib.strtodatetime(to_bytes(date))
            except ValueError:
                pass

            # not parsed yet, obviously a timestamp?
            if date.isdigit():
                date = int(date)
            else:
                date = float(date)

        return datetime.datetime.fromtimestamp(date)
    except Exception:
        if HAS_TIMELIB:
            raise ValueError('Unable to parse {0}'.format(date))

        raise RuntimeError('Unable to parse {0}.'
            ' Consider installing timelib'.format(date))
Extracts the gssapi authentication token from the appropriate header
dataset/ETHPy150Open saltstack/salt/salt/utils/__init__.py/date_cast--crossover with--dataset/ETHPy150Open cloudera/hue/desktop/core/ext-py/requests-kerberos-0.6.1/requests_kerberos/kerberos_.py/_negotiate_value