def add_months(src_time, amount):
    """Adds specified amount of months to datetime value.
    Specifying negative amount will result in subtraction of months.
    """
    return src_time.replace(
        # To find the year correction we convert the month from 1..12 to
        # 0..11 value, add amount of months and find the integer
        # part of division by 12.
        year=src_time.year + (src_time.month - 1 + amount) // 12,
        # To find the new month we convert the month from 1..12 to
        # 0..11 value, add amount of months, find the remainder
        # part after division by 12 and convert the month back
        # to the 1..12 form.
        month=(src_time.month - 1 + amount) % 12 + 1)