(frequency, period)
return (end_of_period - relativedelta(days=1)).date()
period = "2004W10" for week 10, 2004, frequency = SEND_FREQUENCY_WEEKLY.
    period = "200403" for March 2004, frequency = SEND_FREQUENCY_MONTHLY.
    period = "2004Q1" for January-March 2004, frequency = SEND_FREQUENCY_QUARTERLY
period = "2004W10" for week 10, 2004, frequency = SEND_FREQUENCY_WEEKLY.
    period = "200403" for March 2004, frequency = SEND_FREQUENCY_MONTHLY.
    period = "2004Q1" for January-March 2004, frequency = SEND_FREQUENCY_QUARTERLY
period = 2004W10 for week 10 2004 frequency = SEND_FREQUENCY_WEEKLY . period = 200403 for March 2004 frequency = SEND_FREQUENCY_MONTHLY . period = 2004Q1 for January - March 2004 frequency = SEND_FREQUENCY_QUARTERLY
def get_end_of_period(frequency, period):
    """
    period = "2004W10" for week 10, 2004, frequency = SEND_FREQUENCY_WEEKLY.
    period = "200403" for March 2004, frequency = SEND_FREQUENCY_MONTHLY.
    period = "2004Q1" for January-March 2004, frequency = SEND_FREQUENCY_QUARTERLY
    """

    if frequency == SEND_FREQUENCY_WEEKLY:
        (year, week) = period.split('W')
        start_of_year = datetime(int(year), 1, 1)
        days_in_n_weeks = int(week) * 7
        end_of_period = start_of_year + relativedelta(days=days_in_n_weeks)

    elif frequency == SEND_FREQUENCY_MONTHLY:
        year = period[0:4]  # '2004' in '200403'
        month = period[4:7]  # '03' in '200403'
        start_of_year = datetime(int(year), 1, 1)
        end_of_period = start_of_year + relativedelta(months=int(month))

    elif frequency == SEND_FREQUENCY_QUARTERLY:
        (year, quarter) = period.split('Q')
        start_of_year = datetime(int(year), 1, 1)
        months = int(quarter) * 3
        end_of_period = start_of_year + relativedelta(months=months)
    else:
        return None

    # Subtract 1 day for last day of month/week instead of 1st day of
    # next month/week
    return (end_of_period - relativedelta(days=1)).date()
def get_end_of_period ( frequency , period ) : if frequency == SEND_FREQUENCY_WEEKLY : ( year , week ) = period . split ( 'W' ) start_of_year = datetime ( int ( year ) , 1 , 1 ) days_in_n_weeks = int ( week ) * 7 end_of_period = start_of_year + relativedelta ( days = days_in_n_weeks ) elif frequency == SEND_FREQUENCY_MONTHLY : year = period [ 0 : 4 ] # '2004' in '200403' month = period [ 4 : 7 ] # '03' in '200403' start_of_year = datetime ( int ( year ) , 1 , 1 ) end_of_period = start_of_year + relativedelta ( months = int ( month ) ) elif frequency == SEND_FREQUENCY_QUARTERLY : ( year , quarter ) = period . split ( 'Q' ) start_of_year = datetime ( int ( year ) , 1 , 1 ) months = int ( quarter ) * 3 end_of_period = start_of_year + relativedelta ( months = months ) else : return None # Subtract 1 day for last day of month/week instead of 1st day of # next month/week return ( end_of_period - relativedelta ( days = 1 ) ) . date ( )