PersianCalendar extends AbstractCalendar { @Override public DateTimeUnit toIso( DateTimeUnit dateTimeUnit ) { if ( dateTimeUnit.getYear() >= START_ISO.getYear() && dateTimeUnit.getYear() <= STOP_ISO.getYear() ) { return new DateTimeUnit( dateTimeUnit.getYear(), dateTimeUnit.getMonth(), dateTimeUnit.getDay(), dateTimeUnit.getDayOfWeek(), true ); } if ( dateTimeUnit.getYear() > STOP_PERSIAN.getYear() || dateTimeUnit.getYear() < START_PERSIAN.getYear() ) { throw new InvalidCalendarParametersException( "Illegal PERSIAN year, must be between " + START_PERSIAN.getYear() + " and " + STOP_PERSIAN.getYear() + ", was given " + dateTimeUnit.getYear() ); } DateTime dateTime = START_ISO.toJodaDateTime(); int totalDays = 0; for ( int year = START_PERSIAN.getYear(); year < dateTimeUnit.getYear(); year++ ) { totalDays += getYearTotal( year ); } for ( int month = START_PERSIAN.getMonth(); month < dateTimeUnit.getMonth(); month++ ) { totalDays += getDaysFromMap( dateTimeUnit.getYear(), month ); } totalDays += dateTimeUnit.getDay() - START_PERSIAN.getDay(); dateTime = dateTime.plusDays( totalDays ); return new DateTimeUnit( DateTimeUnit.fromJodaDateTime( dateTime ), true ); }  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 testToIso() { assertEquals( new DateTimeUnit( 1993, 3, 21, true ), calendar.toIso( new DateTimeUnit( 1372, 1, 1 ) ) ); assertEquals( new DateTimeUnit( 2020, 3, 20, true ), calendar.toIso( new DateTimeUnit( 1399, 1, 1 ) ) ); assertEquals( new DateTimeUnit( 2020, 3, 20, true ), calendar.toIso( new DateTimeUnit( 2020, 3, 20 ) ) ); }