ScheduleCalculator { public static double[] getTimes(final ZonedDateTime[] dates, final DayCount dayCount, final ZonedDateTime fromDate) { ArgumentChecker.notEmpty(dates, "dates"); ArgumentChecker.notNull(dayCount, "day count"); ArgumentChecker.notNull(fromDate, "from date"); final int n = dates.length; final double[] result = new double[n]; double yearFrac; for (int i = 0; i < (n); i++) { if (dates[i].isAfter(fromDate)) { yearFrac = dayCount.getDayCountFraction(fromDate, dates[i]); } else { yearFrac = -dayCount.getDayCountFraction(dates[i], fromDate); } result[i] = yearFrac; } return result; } private  ScheduleCalculator(); static ZonedDateTime getAdjustedDate(final ZonedDateTime date, final int shiftDays, final Calendar calendar); static ZonedDateTime[] getAdjustedDate(final ZonedDateTime[] dates, final int shiftDays, final Calendar calendar); static ZonedDateTime getAdjustedDate(final ZonedDateTime date, final Period shiftDays, final Calendar calendar); static LocalDate getAdjustedDate(final LocalDate date, final int shiftDays, final Calendar calendar); static ZonedDateTime getAdjustedDate(final ZonedDateTime startDate, final Period tenor, final BusinessDayConvention convention, final Calendar calendar); static ZonedDateTime getAdjustedDate(final ZonedDateTime startDate, final Period tenor, final BusinessDayConvention convention, final Calendar calendar,
      final boolean endOfMonthRule); static ZonedDateTime getAdjustedDate(
      final ZonedDateTime startDate,
      final Period period,
      final BusinessDayConvention convention,
      final Calendar calendar,
      final RollDateAdjuster rollDateAdjuster); static ZonedDateTime getAdjustedDate(final ZonedDateTime startDate, final Tenor tenor, final BusinessDayConvention convention, final Calendar calendar,
      final boolean endOfMonthRule); static ZonedDateTime getAdjustedDate(final ZonedDateTime startDate, final Period tenor, final GeneratorDeposit generator); static ZonedDateTime getAdjustedDate(final ZonedDateTime startDate, final Period tenor, final IborIndex index, final Calendar calendar); static ZonedDateTime getAdjustedDate(final ZonedDateTime startDate, final IborIndex index, final Calendar calendar); static ZonedDateTime[] getAdjustedDate(final ZonedDateTime[] startDates, final IborIndex index, final Calendar calendar); static ZonedDateTime[] getUnadjustedDateSchedule(final ZonedDateTime startDate, final ZonedDateTime endDate, final Period tenorPeriod, final StubType stub); static ZonedDateTime[] getUnadjustedDateSchedule(final ZonedDateTime startDate, final ZonedDateTime endDate, final Period tenorPeriod, final boolean stubShort,
      final boolean fromEnd); static ZonedDateTime[] getAdjustedDateSchedule(final ZonedDateTime[] dates, final BusinessDayConvention convention, final Calendar calendar,
      final boolean eomApply); static ZonedDateTime[] getAdjustedDateSchedule(final ZonedDateTime[] dates, final BusinessDayConvention convention, final Calendar calendar,
      final boolean eomApply, final RollDateAdjuster adjuster); static ZonedDateTime[] getAdjustedDateSchedule(final ZonedDateTime startDate, final ZonedDateTime endDate, final Period schedulePeriod, final boolean stubShort,
      final boolean fromEnd, final BusinessDayConvention convention, final Calendar calendar, final boolean eomRule); static ZonedDateTime[] getAdjustedDateSchedule(final ZonedDateTime startDate, final ZonedDateTime endDate, final Period schedulePeriod, final boolean stubShort,
      final boolean fromEnd, final BusinessDayConvention convention, final Calendar calendar, final boolean eomRule, final RollDateAdjuster adjuster); static ZonedDateTime[] getAdjustedDateSchedule(final ZonedDateTime startDate, final ZonedDateTime endDate, final Period schedulePeriod, final StubType stub,
      final BusinessDayConvention convention, final Calendar calendar, final boolean eomRule); static ZonedDateTime[] getAdjustedDateSchedule(final ZonedDateTime startDate, final ZonedDateTime endDate, final Period schedulePeriod, final StubType stub,
      final BusinessDayConvention convention, final Calendar calendar, final boolean eomRule, final RollDateAdjuster adjuster); static ZonedDateTime[] getAdjustedDateSchedule(
      ZonedDateTime startDate,
      ZonedDateTime endDate,
      Period schedulePeriod,
      StubType stub,
      BusinessDayConvention convention,
      Calendar calendar,
      RollDateAdjuster adjuster); static ZonedDateTime[] getAdjustedDateSchedule(
      final ZonedDateTime[] startDates,
      final Period schedulePeriod,
      final BusinessDayConvention businessDayConvention,
      final Calendar calendar,
      final RollDateAdjuster adjuster); static ZonedDateTime[] getAdjustedDateSchedule(final ZonedDateTime startDate, final ZonedDateTime endDate, final Frequency scheduleFrequency,
      final boolean stubShort, final boolean fromEnd, final BusinessDayConvention convention, final Calendar calendar, final boolean eomRule); static ZonedDateTime[] getAdjustedDateSchedule(final ZonedDateTime startDate, final Period tenorTotal, final Period tenorPeriod, final boolean stubShort,
      final boolean fromEnd, final BusinessDayConvention convention, final Calendar calendar, final boolean eomRule); static ZonedDateTime[] getAdjustedDateSchedule(final ZonedDateTime startDate, final Period tenorTotal, final boolean stubShort, final boolean fromEnd,
      final IborIndex index, final Calendar calendar); static ZonedDateTime[] getUnadjustedDateSchedule(final ZonedDateTime effectiveDate, final ZonedDateTime maturityDate, final Frequency frequency); static ZonedDateTime[] getUnadjustedDateSchedule(final ZonedDateTime effectiveDate, final ZonedDateTime accrualDate, final ZonedDateTime maturityDate,
      final Frequency frequency); static ZonedDateTime[] getUnadjustedDateSchedule(final ZonedDateTime effectiveDate, final ZonedDateTime accrualDate, final ZonedDateTime maturityDate,
      final Period period); static ZonedDateTime[] getBackwardsUnadjustedDateSchedule(final ZonedDateTime effectiveDate, final ZonedDateTime maturityDate, final Frequency frequency); static ZonedDateTime[] getAdjustedDateSchedule(final ZonedDateTime[] dates, final BusinessDayConvention convention, final Calendar calendar); static ZonedDateTime[] getAdjustedDateSchedule(final ZonedDateTime[] dates, final BusinessDayConvention convention, final Calendar calendar,
      final int settlementDays); static ZonedDateTime getAdjustedDate(final ZonedDateTime originalDate, final BusinessDayConvention convention, 
      final Calendar calendar, final int offset); static ZonedDateTime[] getAdjustedDateSchedule(final ZonedDateTime startDate, final ZonedDateTime endDate, final Period period,
      final BusinessDayConvention businessDayConvention, final Calendar calendar, final boolean isEOM, final boolean stubShort); static ZonedDateTime[] getAdjustedDateSchedule(final ZonedDateTime startDate, final ZonedDateTime endDate, final Frequency frequency,
      final BusinessDayConvention businessDayConvention, final Calendar calendar, final boolean isEOM); static ZonedDateTime[] getAdjustedDateSchedule(final ZonedDateTime startDate, final ZonedDateTime endDate, final Period period,
      final BusinessDayConvention businessDayConvention, final Calendar calendar, final boolean isEOM); static ZonedDateTime[] getAdjustedDateSchedule(final ZonedDateTime startDate, final Period tenor, final Period period,
      final BusinessDayConvention businessDayConvention, final Calendar calendar, final boolean isEOM, final boolean shortStub); static ZonedDateTime[] getAdjustedDateSchedule(final ZonedDateTime startDate, final Period tenorAnnuity, final Period periodPayments,
      final BusinessDayConvention businessDayConvention, final Calendar calendar, final boolean isEOM); static ZonedDateTime[] getSettlementDateSchedule(final ZonedDateTime[] dates, final Calendar calendar, final BusinessDayConvention businessDayConvention,
      final int settlementDays); static LocalDate[] getSettlementDateSchedule(final LocalDate[] dates, final Calendar calendar, final BusinessDayConvention businessDayConvention,
      final int settlementDays); static ZonedDateTime[] getAdjustedResetDateSchedule(final ZonedDateTime effectiveDate, final ZonedDateTime[] dates, final BusinessDayConvention convention,
      final Calendar calendar, final int settlementDays); static ZonedDateTime[] getAdjustedMaturityDateSchedule(final ZonedDateTime effectiveDate, final ZonedDateTime[] dates, final BusinessDayConvention convention,
      final Calendar calendar, final Frequency frequency); static double[] getTimes(final ZonedDateTime[] dates, final DayCount dayCount, final ZonedDateTime fromDate); static int numberOfNegativeValues(final double[] periods); static double[] removeFirstNValues(final double[] data, final int n); static double[] getYearFractions(final ZonedDateTime[] dates, final DayCount dayCount, final ZonedDateTime fromDate); static ZonedDateTime[] getStartDates(final ZonedDateTime startDate, final ZonedDateTime[] endDates);  }
@Test(expectedExceptions = IllegalArgumentException.class) public void testNullDateArray2() { ScheduleCalculator.getTimes(null, new ThirtyEThreeSixty(), NOW); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testEmtpyDateArray2() { ScheduleCalculator.getTimes(new ZonedDateTime[0], new ThirtyEThreeSixty(), NOW); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testNullDayCount() { ScheduleCalculator.getTimes(new ZonedDateTime[] {DateUtils.getUTCDate(2010, 6, 1) }, null, NOW); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testNullTime() { ScheduleCalculator.getTimes(new ZonedDateTime[] {DateUtils.getUTCDate(2010, 6, 1) }, new ThirtyEThreeSixty(), null); }
@Test public void testPaymentTimes() { final DayCount daycount = new DayCount() { @Override public String getConventionName() { return ""; } @Override public double getDayCountFraction(final ZonedDateTime firstDate, final ZonedDateTime secondDate) { return ((double) (secondDate.getMonthValue() - firstDate.getMonthValue())) / 12; } @Override public double getAccruedInterest(final ZonedDateTime previousCouponDate, final ZonedDateTime date, final ZonedDateTime nextCouponDate, final double coupon, final double paymentsPerYear) { return 0; } @Override public double getDayCountFraction(final LocalDate firstDate, final LocalDate secondDate) { return ((double) (secondDate.getMonthValue() - firstDate.getMonthValue())) / 12; } @Override public double getAccruedInterest(final LocalDate previousCouponDate, final LocalDate date, final LocalDate nextCouponDate, final double coupon, final double paymentsPerYear) { return 0; } @Override public double getDayCountFraction(LocalDate firstDate, LocalDate secondDate, Calendar calendar) { return 0; } @Override public double getDayCountFraction(ZonedDateTime firstDate, ZonedDateTime secondDate, Calendar calendar) { return 0; } @Override public String getName() { return ""; } }; final ZonedDateTime now = DateUtils.getUTCDate(2010, 1, 1); final ZonedDateTime dates[] = new ZonedDateTime[] {DateUtils.getUTCDate(2010, 1, 1), DateUtils.getUTCDate(2010, 2, 1), DateUtils.getUTCDate(2010, 3, 1), DateUtils.getUTCDate(2010, 4, 1), DateUtils.getUTCDate(2010, 5, 1), DateUtils.getUTCDate(2010, 6, 1), DateUtils.getUTCDate(2010, 7, 1), DateUtils.getUTCDate(2010, 8, 1), DateUtils.getUTCDate(2010, 9, 1), DateUtils.getUTCDate(2010, 10, 1), DateUtils.getUTCDate(2010, 11, 1), DateUtils.getUTCDate(2010, 12, 1) }; final double[] times = ScheduleCalculator.getTimes(dates, daycount, now); assertEquals(times.length, dates.length); for (int i = 0; i < times.length; i++) { assertEquals(times[i], i / 12., 1e-15); } }