PersianCalendar extends AbstractCalendar { @Override public DateTimeUnit plusMonths( DateTimeUnit dateTimeUnit, int months ) { if ( months < 0 ) { return minusMonths( dateTimeUnit, Math.abs( months ) ); } DateTimeUnit result = new DateTimeUnit( dateTimeUnit ); int newMonths = months; while ( newMonths != 0 ) { result.setMonth( result.getMonth() + 1 ); if ( result.getMonth() > monthsInYear() ) { result.setMonth( 1 ); result.setYear( result.getYear() + 1 ); } newMonths--; } updateDateUnit( result ); return result; }  static Calendar getInstance(); @Override String name(); @Override DateTimeUnit toIso( DateTimeUnit dateTimeUnit ); @Override DateTimeUnit fromIso( Date date ); @Override DateTimeUnit fromIso( DateTimeUnit dateTimeUnit ); @Override DateInterval toInterval( DateTimeUnit dateTimeUnit, DateIntervalType type, int offset, int length ); @Override int daysInYear( int year ); @Override int daysInMonth( int year, int month ); @Override int weeksInYear( int year ); @Override int isoWeek( DateTimeUnit dateTimeUnit ); @Override int week( DateTimeUnit dateTimeUnit ); @Override int isoWeekday( DateTimeUnit dateTimeUnit ); @Override int weekday( DateTimeUnit dateTimeUnit ); @Override String nameOfMonth( int month ); @Override String shortNameOfMonth( int month ); @Override String nameOfDay( int day ); @Override String shortNameOfDay( int day ); @Override DateTimeUnit minusYears( DateTimeUnit dateTimeUnit, int years ); @Override DateTimeUnit minusMonths( DateTimeUnit dateTimeUnit, int months ); @Override DateTimeUnit minusWeeks( DateTimeUnit dateTimeUnit, int weeks ); @Override DateTimeUnit minusDays( DateTimeUnit dateTimeUnit, int days ); @Override DateTimeUnit plusYears( DateTimeUnit dateTimeUnit, int years ); @Override DateTimeUnit plusMonths( DateTimeUnit dateTimeUnit, int months ); @Override DateTimeUnit plusWeeks( DateTimeUnit dateTimeUnit, int weeks ); @Override DateTimeUnit plusDays( DateTimeUnit dateTimeUnit, int days ); @Override DateTimeUnit isoStartOfYear( int year );  }
@Test public void testPlusMonths() { DateTimeUnit dateTimeUnit = new DateTimeUnit( 1382, 1, 20 ); DateTimeUnit testDateTimeUnit = calendar.plusMonths( dateTimeUnit, 4 ); assertEquals( 1382, testDateTimeUnit.getYear() ); assertEquals( 5, testDateTimeUnit.getMonth() ); assertEquals( 20, testDateTimeUnit.getDay() ); dateTimeUnit = new DateTimeUnit( 1382, 1, 20 ); testDateTimeUnit = calendar.plusMonths( dateTimeUnit, -4 ); assertEquals( 1381, testDateTimeUnit.getYear() ); assertEquals( 9, testDateTimeUnit.getMonth() ); assertEquals( 20, testDateTimeUnit.getDay() ); }