def encode_object(obj):
    if hasattr(obj, '__json__'):
        return obj.__json__()
    elif isinstance(obj, datetime.datetime):
        delta = to_default(obj) - EPOCH
        return {'_type': 'date', 'ms': int(delta.total_seconds() * 1000)}
    elif isinstance(obj, datetime.date):
        return datetime.datetime(*obj.timetuple()[:6])
    else:
        raise TypeError(obj.__class__.__name__ % '%s is not JSON serializable')
dataset/ETHPy150Open Suor/handy/handy/ajax.py/encode_object/swapped operands of `%`