@Test(dataProvider = "previous") public void test_previous(RollConvention conv, LocalDate input, Frequency freq, LocalDate expected) { assertEquals(conv.previous(input, freq), expected); }
public void test_ofDayOfMonth_previous_oneMonth() { for (int start = 1; start <= 5; start++) { for (int i = 1; i <= 30; i++) { RollConvention test = RollConvention.ofDayOfMonth(i); LocalDate expected = date(2014, JUNE, i); assertEquals(test.previous(date(2014, JULY, start), P1M), expected); } } }
/** * Checks if this period is regular according to the specified frequency and roll convention. * <p> * A schedule period is normally created from a frequency and roll convention. * These can therefore be used to determine if the period is regular, which simply * means that the period end date can be generated from the start date and vice versa. * * @param frequency the frequency * @param rollConvention the roll convention * @return true if the period is regular */ public boolean isRegular(Frequency frequency, RollConvention rollConvention) { ArgChecker.notNull(frequency, "frequency"); ArgChecker.notNull(rollConvention, "rollConvention"); return rollConvention.next(unadjustedStartDate, frequency).equals(unadjustedEndDate) && rollConvention.previous(unadjustedEndDate, frequency).equals(unadjustedStartDate); }
public void test_ofDayOfMonth_previous_oneDay() { for (int start = 1; start <= 5; start++) { for (int i = 1; i <= 30; i++) { RollConvention test = RollConvention.ofDayOfMonth(i); LocalDate expected = date(2014, JULY, i); if (i >= start) { expected = expected.minusMonths(1); } assertEquals(test.previous(date(2014, JULY, start), P1D), expected); } } }
public void test_ofDayOfWeek_previous_oneMonth() { for (DayOfWeek dow : DayOfWeek.values()) { RollConvention test = RollConvention.ofDayOfWeek(dow); assertEquals( test.previous(date(2014, AUGUST, 14), P1W), date(2014, AUGUST, 7).with(TemporalAdjusters.previousOrSame(dow))); } }
public void test_ofDayOfWeek_previous_oneDay() { for (DayOfWeek dow : DayOfWeek.values()) { RollConvention test = RollConvention.ofDayOfWeek(dow); assertEquals( test.previous(date(2014, AUGUST, 14), P1D), date(2014, AUGUST, 13).with(TemporalAdjusters.previousOrSame(dow))); } }
private static List<LocalDate> generateBackwards( PeriodicSchedule schedule, LocalDate start, LocalDate end, Frequency frequency, RollConvention rollConv, StubConvention stubConv, LocalDate explicitStartDate) { // validate if (rollConv.matches(end) == false) { throw new ScheduleException( schedule, "Date '{}' does not match roll convention '{}' when starting to roll backwards", end, rollConv); } // generate BackwardsList dates = new BackwardsList(estimateNumberPeriods(start, end, frequency)); dates.addFirst(end); LocalDate temp = rollConv.previous(end, frequency); while (temp.isAfter(start)) { dates.addFirst(temp); temp = rollConv.previous(temp, frequency); } // convert to long stub, but only if we actually have a stub boolean stub = temp.equals(start) == false; if (stub && dates.size() > 1 && stubConv.isStubLong(start, dates.get(0))) { dates.removeFirst(); } dates.addFirst(explicitStartDate); return dates; }
@Test(dataProvider = "types") public void test_null(RollConvention type) { assertThrowsIllegalArg(() -> type.adjust(null)); assertThrowsIllegalArg(() -> type.matches(null)); assertThrowsIllegalArg(() -> type.next(date(2014, JULY, 1), null)); assertThrowsIllegalArg(() -> type.next(null, P3M)); assertThrowsIllegalArg(() -> type.previous(date(2014, JULY, 1), null)); assertThrowsIllegalArg(() -> type.previous(null, P3M)); }