Returns a datetime.datetime object
327097
def _get_expiration_date(cert):
    '''
    
    '''
    cert_obj = _read_cert(cert)

    if cert_obj is None:
        raise CommandExecutionError(
            'Failed to read cert from {0}, see log for details'.format(cert)
        )

    return datetime.strptime(
        salt.utils.stringutils.to_str(cert_obj.get_notAfter()),
        four_digit_year_fmt
    )
243133
def to_datetime(t):
    
    if t is None:
        return None

    # extract values
    year, mon, day, h, m, s = t

    # assume the values are valid
    try:
        return datetime(year, mon, day, h, m, s)
    except ValueError:
        pass

    # sanitize invalid values
    mday = (0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31)
    if mon < 1:
        mon = 1
    if mon > 12:
        mon = 12
    if day < 1:
        day = 1
    if day > mday[mon]:
        day = mday[mon]
    if h > 23:
        h = 23
    if m > 59:
        m = 59
    if s > 59:
        s = 59
    if mon == 2 and day == 29:
        try:
            return datetime(year, mon, day, h, m, s)
        except ValueError:
            day = 28
    return datetime(year, mon, day, h, m, s)
139978
def get_python(self):
        """"""
        value = super(DatetimeField, self).get_python()

        if value is not None:
            # Handle subtypes with matching Pendulum types
            if self.input_type == self._type_time:
                value = value.time()
            if self.input_type == self._type_date:
                value = value.date()

        return value
10028
def _encode_datetime(obj):
    """"""

    if isinstance(obj, datetime.datetime):
        obj = {'__datetime__': True, 'as_str': obj.strftime("%Y%m%dT%H:%M:%S.%f").encode()}
    return obj
645088
def to_datetime(value):
    """"""
    if value is None:
        return None

    if isinstance(value, six.integer_types):
        return parser.parse(value)
    return parser.isoparse(value)
1259011
def _str_to_datetime(self, str_value):
        """"""
        try:
            ldt = [int(f) for f in str_value.split('-')]
            dt = datetime.datetime(*ldt)
        except (ValueError, TypeError):
            return None
        return dt
355925
def datetime(self):
        
        if self._time == '':
            return datetime.strptime(self._date, '%b %d, %Y')
        date_string = '%s %s' % (self._date, self._time)
        return datetime.strptime(date_string, '%b %d, %Y %I:%M %p')
1161540
def timestamp_to_datetime(cls, dt, dt_format=DATETIME_FORMAT):
        """"""
        return cls.convert_datetime(cls.get_datetime(dt), dt_format=dt_format)
1191268
def as_datetime(self):
        '''
        '''
        year = int(self.year)
        month = int(self.month) if self.month else 1
        day = int(self.day) if self.day else 1
        hour = int(self.hour) if self.hour else 0
        minute = int(self.minute) if self.minute else 0
        second = int(self.second) if self.second else 0
        microsecond = int(self.microsecond) if self.microsecond else 0
        return datetime.datetime(year, month, day, hour, minute, second, microsecond)
685170
def TAF_datetime_to_datetime_object(
    datetime_string             = None,
    datetime_for_year_and_month = None  # e.g. datetime.datetime.utcnow()
    ):

    

    if datetime_string.endswith("24"):

        datetime_string = datetime_string[:-2] + "00"

        tmp = datetime.datetime.strptime(datetime_string, "%d%H") +\
              datetime.timedelta(days = 1)

    else:

        tmp = datetime.datetime.strptime(datetime_string, "%d%H")

    return datetime.datetime(
        datetime_for_year_and_month.year,
        datetime_for_year_and_month.month,
        tmp.day,
        tmp.hour,
        tmp.minute
    )
81825
def naive(
    year, month, day, hour=0, minute=0, second=0, microsecond=0
):  # type: (int, int, int, int, int, int, int) -> DateTime
    
    return DateTime(year, month, day, hour, minute, second, microsecond)
495781
def datetime(self):
        
        date_string = '%s %s' % (self._date, self._year)
        date_string = re.sub(r' \(\d+\)', '', date_string)
        return datetime.strptime(date_string, '%A, %b %d %Y')
1065602
def _datetime_to_json(value):
    """"""
    if isinstance(value, datetime.datetime):
        value = value.strftime(_RFC3339_MICROS_NO_ZULU)
    return value
275635
def _get_date(data, position, dummy0, opts, dummy1):
    """"""
    end = position + 8
    millis = _UNPACK_LONG(data[position:end])[0]
    return _millis_to_datetime(millis, opts), end
569167
def time_to_datetime(x):
    """"""
    if isinstance(x, time):
        return datetime.combine(date(1970, 1, 1), x)
    return x
689169
def datetime(self):
        """"""
        return dt.datetime(
            self.year(), self.month(), self.day(),
            self.hour(), self.minute(), self.second(),
            int(self.millisecond() * 1e3))
898204
def _deserialize_datetime(self, data):
        
        for key in data:
            if isinstance(data[key], dict):
                if data[key].get('type') == 'datetime':
                    data[key] = \
                        datetime.datetime.fromtimestamp(data[key]['value'])
        return data