def _iter_month_interest(start_date, end_date, year_interest):
    year_interest = Decimal(year_interest) / 100

    prev = None
    day_interest = None
    for cur in _iter_months(start_date, end_date):
        if prev is None:
            day_interest = year_interest / year_days(cur.year)
            prev = cur
            continue

        if cur.year == prev.year:
            interest = day_interest * (cur - prev).days
        else:
            assert prev.month == 12
            assert cur.month == 1

            prev_days = (Date(prev.year, prev.month, 31) - prev).days
            cur_days = (cur - Date(cur.year, cur.month, 1)).days + 1
            assert prev_days + cur_days == (cur - prev).days

            interest = day_interest * prev_days

            day_interest = year_interest / year_days(cur.year)
            interest += day_interest * cur_days

        yield MonthInterest(cur, interest)
        prev = cur
def _iter_month_interest(start_date, end_date, year_interest):
    year_interest = Decimal(year_interest) / 100

    prev = None
    day_interest = None
    for cur in _iter_months(start_date, end_date):
        if prev is None:
            day_interest = year_interest / year_days(cur.year)
            prev = cur
            continue

        if cur.year == prev.year:
            interest = day_interest * (cur - prev).days
        else:
            assert prev.month == 12
            assert cur.month == 1

            prev_days = (Date(prev.year, prev.month, 31) - prev).days
            cur_days = (cur - Date(cur.year, cur.month, 1)).days + 1
            assert prev_days + cur_days == (cur - prev).days

            interest = day_interest * prev_days

            day_interest = year_interest / year_days(cur.year)
            interest += day_interest * cur_days

        yield MonthInterest(cur, interest)
        prev = cur
def test_year_days():
    assert year_days(2012) == 366
    assert year_days(2013) == 365
def test_year_days():
    assert year_days(2012) == 366
    assert year_days(2013) == 365