def wrappable_range_overlaps(start, end, test,
                             wrap_after=59, wrap_to=0,
                             overlap=False
                             ):

    """Figure out whether a range of numbers (specified by 'start' and
    'end') has any overlap with the set of numbers in the set 'test'.
    The numbers in the range may wrap (e.g., the 60th minute wraps to
    the 0th or the 12th month wraps to the 1st); where the wrap occurs
    is governed by 'wrap_after' (default 59) and where it wraps is
    governed by 'wrap_to' (default 0).  If 'overlap' is true, the
    start and end must simply overlap with the test set, otherwise it
    must be completely contained within it.
    """

    if not isinstance(test, set):
        raise ValueError("Type of 'test' must be 'set'")

    if wrap_to >= wrap_after:
        raise ValueError("Unusuable wrap values.")

    if not ( (wrap_to <= start <= wrap_after)
             and (wrap_to <= end <= wrap_after) ):
        raise ValueError("Start and end must be in [%d..%d]" \
                         % (wrap_to, wrap_after))

    ranges = []
    if end >= start:
        ranges.extend(list(range(start, end+1)))
    else:
        ranges.extend(list(range(start, wrap_after+1)))
        ranges.extend(list(range(0, wrap_to+1)))
    ranges = set(ranges)

    return bool(test.intersection(ranges)) if overlap \
        else ranges.issubset(test)