def merge_usage_periods(periods, new_period):
    """Merge a time period into an existing set of usage periods"""
    outlist = []
    for period in periods:
        if new_period[0] > period[1]:
            # No overlap - past the end
            outlist.append(period)
            continue
        if new_period[1] < period[0]:
            # No overlap - before the beginning
            outlist.append(period)
            continue
        # There must now be some overlap
        merged = True
        if new_period[0] < period[0]:
            period[0] = new_period[0]
        if new_period[1] > period[1]:
            period[1] = new_period[1]
        new_period = period

    outlist.append(new_period)
    return outlist