Serialize a DateTime object to its proper ISO-8601 representation.
553026
def _serialize_datetime(value):
    """"""
    if not isinstance(value, (datetime, arrow.Arrow)):
        raise ValueError(u'The received object was not a datetime: '
                         u'{} {}'.format(type(value), value))
    return value.isoformat()
881236
def encode_datetime(o):
    
    r = o.isoformat()
    if o.microsecond:
        r = r[:23] + r[26:]
    if r.endswith('+00:00'):
        r = r[:-6] + 'Z'
    return r
591185
private String _serializeDateTime(DateTime dateTime) {
	// try {

	String strDate = new lucee.runtime.format.DateFormat(Locale.US).format(dateTime, "yyyy-m-d", TimeZoneConstants.UTC);
	String strTime = new lucee.runtime.format.TimeFormat(Locale.US).format(dateTime, "H:m:s", TimeZoneConstants.UTC);

	return goIn() + "<dateTime>" + strDate + "T" + strTime + "+0:0" + "</dateTime>";

	/*
	 * } catch (PageException e) { throw new ConverterException(e); }
	 */
    }
434004
def iso8601_datetime(s):
    
    try:
        return datetime.datetime.strptime(s, ISO8601_DATETIME_FORMAT).replace(tzinfo=pytz.utc)
    except (TypeError, ValueError):
        return s
13658
def serialize(obj):
    """"""
    # Record class and module information for deserialization
    result = {'__class__': obj.__class__.__name__}
    try:
        result['__module__'] = obj.__module__
    except AttributeError:
        pass
    # Convert objects to dictionary representation based on type
    if isinstance(obj, datetime.datetime):
        result['year'] = obj.year
        result['month'] = obj.month
        result['day'] = obj.day
        result['hour'] = obj.hour
        result['minute'] = obj.minute
        result['second'] = obj.second
        result['microsecond'] = obj.microsecond
        return result
    if isinstance(obj, StreamingBody):
        result['body'] = obj.read()
        obj._raw_stream = StringIO(result['body'])
        obj._amount_read = 0
        return result
    # Raise a TypeError if the object isn't recognized
    raise TypeError("Type not serializable")
1149799
def isoformat(dt):
    """"""
    if not isinstance(dt, datetime.datetime):
        raise TypeError("Must provide datetime.datetime object to isoformat")

    if dt.tzinfo is None:
        raise ValueError("naive datetime objects are not allowed beyond the library boundaries")

    return dt.isoformat().replace("+00:00", "Z")
749170
def json_serialize(obj):
    
    if isinstance(obj, datetime):
        return obj.isoformat()

    if hasattr(obj, 'id'):
        return jsonify(obj.id)

    if hasattr(obj, 'name'):
        return jsonify(obj.name)

    raise TypeError('{0} is not JSON serializable'.format(obj))
593246
def serialize(data, format: str = 'json', pretty: bool = False):
    """"""
    def encode(obj):
        if isinstance(obj, stellata.model.Model):
            return obj.to_dict()
        elif isinstance(obj, datetime.datetime):
            return int(obj.timestamp())
        elif isinstance(obj, datetime.date):
            return obj.isoformat()
        elif isinstance(obj, decimal.Decimal):
            return float(obj)
        elif hasattr(obj, 'serialize'):
            return obj.serialize()

        return obj

    if format == 'msgpack':
        return msgpack.packb(data, default=encode)

    if format == 'json':
        if pretty:
            return json.dumps(data, default=encode, indent=4)
        return json.dumps(data, default=encode)

    return data
694976
def as_iso8601(self):
        
        if self.__date is None or self.__time is None:
            return None

        return "20%s-%s-%sT%s:%s:%s0Z" % \
               (self.__date[4:], self.__date[2:4], self.__date[:2], self.__time[:2], self.__time[2:4], self.__time[4:])
455888
def datetime_to_httpdate(dt):
    """"""
    if isinstance(dt, (int, float)):
        return format_date_time(dt)
    elif isinstance(dt, datetime):
        return format_date_time(datetime_to_timestamp(dt))
    else:
        raise TypeError("expected datetime.datetime or timestamp (int/float),"
                        " got '%s'" % dt)
347918
def _convert_datetime_str(response):
    '''
    
    '''
    if response:
        return dict([(k, '{0}'.format(v)) if isinstance(v, datetime.date) else (k, v) for k, v in six.iteritems(response)])
    return None
1154057
def clean_up_datetime(obj_map):
    """"""
    clean_map = {}
    for key, value in obj_map.items():
        if isinstance(value, datetime.datetime):
            clean_map[key] = {
                'year': value.year,
                'month': value.month,
                'day': value.day,
                'hour': value.hour,
                'minute': value.minute,
                'second': value.second,
                'microsecond': value.microsecond,
                'tzinfo': value.tzinfo
            }
        elif isinstance(value, dict):
            clean_map[key] = clean_up_datetime(value)
        elif isinstance(value, list):
            if key not in clean_map:
                clean_map[key] = []
            if len(value) > 0:
                for index, list_value in enumerate(value):
                    if isinstance(list_value, dict):
                        clean_map[key].append(clean_up_datetime(list_value))
                    else:
                        clean_map[key].append(list_value)
            else:
                clean_map[key] = value
        else:
            clean_map[key] = value
    return clean_map
743884
def _sanitizer(self, obj):
        """"""
        if isinstance(obj, datetime.datetime):
            return obj.isoformat()
        if hasattr(obj, "to_dict"):
            return obj.to_dict()
        return obj
804049
def json_serial(obj):
    """"""
    if isinstance(obj, datetime):
        serial = obj.isoformat()
        return serial
    raise TypeError("Type not serializable")
569436
def serialize(self, value):
        """"""
        if isinstance(value, str):
            return value
        return value.strftime(DATETIME_FORMAT)
444625
def _serialize(self, value, *args, **kwargs):
        """"""
        if value is not None:
            value = super(MSTimestamp, self)._serialize(value, *args) * 1e3
        return value
701704
def to_datetime(date):
    """"""
    return datetime.datetime(date.year, date.month, date.day)