method performs simple increment/decrement of the timeperiods
    For instance: 2010010119 with delta=1 -> 2010010120
    Or 2010010000 with delta=-1 -> 2009120000, etc

def increment_timeperiod(time_qualifier, timeperiod, delta=1):
    """ method performs simple increment/decrement of the timeperiods
    For instance: 2010010119 with delta=1 -> 2010010120
    Or 2010010000 with delta=-1 -> 2009120000, etc"""

    pattern = define_pattern(timeperiod)
    t = datetime.strptime(timeperiod, pattern)

    if time_qualifier == QUALIFIER_HOURLY:
        t = t + timedelta(hours=delta)
        return t.strftime(SYNERGY_HOURLY_PATTERN)

    elif time_qualifier == QUALIFIER_DAILY:
        t = t + timedelta(days=delta)
        return t.strftime(SYNERGY_DAILY_PATTERN)

    elif time_qualifier == QUALIFIER_MONTHLY:
        yearly_increment = abs(delta) // 12
        yearly_increment = yearly_increment if delta >= 0 else -yearly_increment
        monthly_increment = delta - yearly_increment * 12

        if t.month + monthly_increment > 12:
            new_month = t.month + monthly_increment - 12
            new_year = t.year + yearly_increment + 1
            t = t.replace(year=new_year, month=new_month)
        elif t.month + monthly_increment < 1:
            new_month = t.month + monthly_increment + 12
            new_year = t.year + yearly_increment - 1
            t = t.replace(year=new_year, month=new_month)
        else:
            t = t.replace(year=t.year + yearly_increment, month=t.month + monthly_increment)
        return t.strftime(SYNERGY_MONTHLY_PATTERN)

    elif time_qualifier == QUALIFIER_YEARLY:
        t = t.replace(year=t.year + delta)
        return t.strftime(SYNERGY_YEARLY_PATTERN)
    else:
        raise ValueError('unknown time qualifier: {0}'.format(time_qualifier))