'Convert a time struct to a string'

def to_json(self, value):

    if (value is None):
        return None
    if isinstance(value, time.struct_time):
        return time.strftime('%Y-%m-%dT%H:%M:%SZ', value)
    elif isinstance(value, datetime.datetime):
        if ((value.tzinfo is None) or (value.utcoffset().total_seconds() == 0)):
            if (value.year < 1900):
                return value.isoformat()
            return value.strftime('%Y-%m-%dT%H:%M:%SZ')
        else:
            return value.isoformat()
    else:
        raise TypeError('Cannot    convert    {!r}    to    json'.format(value))
