converts dictionary representations of datetime back to datetime obj
543377
def convert_dict_to_datetime(obj_map):
    """"""
    converted_map = {}
    for key, value in obj_map.items():
        if isinstance(value, dict) and 'tzinfo' in value.keys():
            converted_map[key] = datetime.datetime(**value)
        elif isinstance(value, dict):
            converted_map[key] = convert_dict_to_datetime(value)
        elif isinstance(value, list):
            updated_list = []
            for internal_item in value:
                if isinstance(internal_item, dict):
                    updated_list.append(convert_dict_to_datetime(internal_item))
                else:
                    updated_list.append(internal_item)
            converted_map[key] = updated_list
        else:
            converted_map[key] = value
    return converted_map
270646
def convert_datetimes_to_timestamps(data, datetime_attrs):
    
    if not data:
        return data

    new_data = {}
    for key, value in data.items():
        if key in datetime_attrs and isinstance(value, datetime):
            new_key = datetime_attrs[key]
            new_data[new_key] = timestamp_from_dt(value)
        else:
            new_data[key] = value

    return new_data
436963
def datetime_from_json(js, manager):
    """"""
    if js is None:
        return None
    else:
        return dt.datetime(
            js['year'],
            js['month'] + 1,  # Months are 1-based in Python
            js['date'],
            js['hours'],
            js['minutes'],
            js['seconds'],
            js['milliseconds'] * 1000
        )
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)
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
593663
def dict_to_object(self, d):
        
        for k, v in list(d.items()):
            if isinstance(v, six.string_types) and len(v) == 19:
                # Decode a datetime string to a datetime object
                try:
                    d[k] = datetime.strptime(v, "%Y-%m-%dT%H:%M:%S")
                except ValueError:
                    pass
            elif isinstance(v, six.string_types) and len(v) > 20:
                try:
                    d[k] = datetime.strptime(v, "%Y-%m-%dT%H:%M:%S.%f")
                except ValueError:
                    pass
            elif isinstance(v, list):
                d[k] = [self.string_to_datetime(elem) for elem in v]
        return DotDict(d)
897077
def _from_json_object_hook(obj):
    

    for key, value in obj.items():
        # Check for datetime objects
        if isinstance(value, str):
            dt_result = datetime_regex.match(value)
            if dt_result:
                year, month, day, hour, minute, second = map(
                    lambda x: int(x), dt_result.groups())
                obj[key] = datetime.datetime(
                    year, month, day, hour, minute, second)
            else:
                dt_result = uuid_regex.match(value)
                if dt_result:
                    obj[key] = uuid.UUID(value)
    return obj
1026463
def to_datetime(data):
    
    my_date_time = None

    if 'published_parsed' in data:
        my_date_time = datetime.datetime.utcfromtimestamp(time.mktime(data.get('published_parsed')))
    elif 'created_parsed' in data:
        my_date_time = datetime.datetime.utcfromtimestamp(time.mktime(data.get('created_parsed')))
    elif 'updated_parsed' in data:
        my_date_time = datetime.datetime.utcfromtimestamp(time.mktime(data.get('updated_parsed')))
    elif 'my_date' in data:
        my_date_time = arrow.get(data['my_date'])

    return my_date_time
1137948
def _reconstruct_data(values, dtype, original):
    
    from pandas import Index
    if is_extension_array_dtype(dtype):
        values = dtype.construct_array_type()._from_sequence(values)
    elif is_datetime64tz_dtype(dtype) or is_period_dtype(dtype):
        values = Index(original)._shallow_copy(values, name=None)
    elif is_bool_dtype(dtype):
        values = values.astype(dtype)

        # we only support object dtypes bool Index
        if isinstance(original, Index):
            values = values.astype(object)
    elif dtype is not None:
        values = values.astype(dtype)

    return values
164422
def _make_object_dict(self, obj):
        
        data = {}
        for attr in dir(obj):
            if attr[0] is not '_' and attr is not 'status':
                datum = getattr(obj, attr)
                if not isinstance(datum, types.MethodType):
                    data.update(self._handle_object(attr,datum))
        return data
489329
def get_as_datetime(self, key):
        
        value = self.get(key)
        return DateTimeConverter.to_datetime(value)
131800
def _decode_datetime(obj):
    """"""

    if '__datetime__' in obj:
        obj = datetime.datetime.strptime(obj['as_str'].decode(), "%Y%m%dT%H:%M:%S.%f")
    return obj
1236867
def from_dict(d):
        """"""
        start = d.get('start')
        end = d.get('end')
        if not (start and end):
            raise ValueError('DateRange must have both start and end')
        start = str_to_date(start)
        end = str_to_date(end)
        return DateRange(start, end)
584583
def to_datetime(timestamp):
    """"""
    return dt.fromtimestamp(time.mktime(
        time.localtime(int(str(timestamp)[:10]))))
24867
def transformFromNative(obj):
        
        if not obj.isNative:
            return obj
        obj.isNative = False
        obj.value = timedeltaToString(obj.value)
        return obj
541258
def to_datetime(date):
    
    return datetime.datetime.combine(date, datetime.datetime.min.time())
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