PersianCalendar extends AbstractCalendar { @Override public DateTimeUnit plusDays( DateTimeUnit dateTimeUnit, int days ) { if ( days < 0 ) { return minusDays( dateTimeUnit, Math.abs( days ) ); } int curYear = dateTimeUnit.getYear(); int curMonth = dateTimeUnit.getMonth(); int curDay = dateTimeUnit.getDay(); int dayOfWeek = dateTimeUnit.getDayOfWeek(); int newDays = days; while ( newDays != 0 ) { if ( curDay < getDaysFromMap( curYear, curMonth ) ) { curDay++; } else { curMonth++; curDay = 1; if ( curMonth == 13 ) { curMonth = 1; curYear++; } } newDays--; dayOfWeek++; if ( dayOfWeek == 8 ) { dayOfWeek = 1; } } return new DateTimeUnit( curYear, curMonth, curDay, dayOfWeek, false ); }  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 testPlusDays() { DateTimeUnit dateTimeUnit = new DateTimeUnit( 1382, 1, 1 ); DateTimeUnit testDateTimeUnit = calendar.plusDays( dateTimeUnit, 31 ); assertEquals( 1382, testDateTimeUnit.getYear() ); assertEquals( 2, testDateTimeUnit.getMonth() ); assertEquals( 1, testDateTimeUnit.getDay() ); testDateTimeUnit = calendar.plusDays( dateTimeUnit, 366 ); assertEquals( 1383, testDateTimeUnit.getYear() ); assertEquals( 1, testDateTimeUnit.getMonth() ); assertEquals( 2, testDateTimeUnit.getDay() ); dateTimeUnit = new DateTimeUnit( 1403, 12, 29 ); testDateTimeUnit = calendar.plusDays( dateTimeUnit, 1 ); assertEquals( 1403, testDateTimeUnit.getYear() ); assertEquals( 12, testDateTimeUnit.getMonth() ); assertEquals( 30, testDateTimeUnit.getDay() ); dateTimeUnit = new DateTimeUnit( 1403, 12, 30 ); testDateTimeUnit = calendar.plusDays( dateTimeUnit, -1 ); assertEquals( 1403, testDateTimeUnit.getYear() ); assertEquals( 12, testDateTimeUnit.getMonth() ); assertEquals( 29, testDateTimeUnit.getDay() ); dateTimeUnit = new DateTimeUnit( 1371, 1, 1 ); testDateTimeUnit = calendar.plusDays( dateTimeUnit, -1 ); assertEquals( 1370, testDateTimeUnit.getYear() ); assertEquals( 12, testDateTimeUnit.getMonth() ); assertEquals( 30, testDateTimeUnit.getDay() ); }