IMMDateLogic { public static LocalDate getNextIMMDate(final LocalDate date) { final int day = date.getDayOfMonth(); final int month = date.getMonthValue(); final int year = date.getYear(); if (month % 3 == 0) { if (day < IMM_DAY) { return LocalDate.of(year, month, IMM_DAY); } else { if (month != 12) { return LocalDate.of(year, month + 3, IMM_DAY); } else { return LocalDate.of(year + 1, IMM_MONTHS[0], IMM_DAY); } } } else { return LocalDate.of(year, IMM_MONTHS[month / 3], IMM_DAY); } }  static boolean isIMMDate(final LocalDate date); static boolean isIndexRollDate(final LocalDate date); static LocalDate[] getIMMDateSet(final LocalDate baseIMMDate, final Period[] tenors); static LocalDate[] getIMMDateSet(final LocalDate startIMMDate, final int size); static LocalDate getNextIMMDate(final LocalDate date); static LocalDate getPrevIMMDate(final LocalDate date); static LocalDate getNextIndexRollDate(final LocalDate date);  }
@Test public void nextIMMTest() { LocalDate today = LocalDate.of(2011, Month.JUNE, 21); LocalDate nextIMM = getNextIMMDate(today); assertEquals(LocalDate.of(2011, Month.SEPTEMBER, 20), nextIMM); today = LocalDate.of(2011, Month.JUNE, 20); nextIMM = getNextIMMDate(today); assertEquals(LocalDate.of(2011, Month.SEPTEMBER, 20), nextIMM); today = LocalDate.of(2011, Month.DECEMBER, 20); nextIMM = getNextIMMDate(today); assertEquals(LocalDate.of(2012, Month.MARCH, 20), nextIMM); today = LocalDate.of(2011, Month.JUNE, 18); nextIMM = getNextIMMDate(today); assertEquals(LocalDate.of(2011, Month.JUNE, 20), nextIMM); today = LocalDate.of(1976, Month.JULY, 30); nextIMM = getNextIMMDate(today); assertEquals(LocalDate.of(1976, Month.SEPTEMBER, 20), nextIMM); today = LocalDate.of(1977, Month.FEBRUARY, 13); nextIMM = getNextIMMDate(today); assertEquals(LocalDate.of(1977, Month.MARCH, 20), nextIMM); today = LocalDate.of(2013, Month.MARCH, 1); nextIMM = getNextIMMDate(today); assertEquals(LocalDate.of(2013, Month.MARCH, 20), nextIMM); today = LocalDate.of(2013, Month.DECEMBER, 25); nextIMM = getNextIMMDate(today); assertEquals(LocalDate.of(2014, Month.MARCH, 20), nextIMM); }