from datetime import datetime


def encode_datetime(obj, typecode, packb, ext_type):
    """Encode a Python 'datetime' object into a MessagePack ExtType."""
    delta = obj - datetime(1970, 1, 1, tzinfo=obj.tzinfo)
    data = delta.seconds + delta.days * 24 * 3600, delta.microseconds
    return ext_type(typecode, packb(data))