def timedelta_to_ms(td):
    """Converts a `datetime.timedelta` to milliseconds.

    Args:
        td: a `datetime.timedelta`

    Returns:
        the number of milliseconds
    """
    return int(
        86400000 * td.days + 1000 * td.seconds + td.microseconds // 1000
    )