IMMDateLogic { public static LocalDate getPrevIMMDate(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 != 3) { return LocalDate.of(year, month - 3, IMM_DAY); } else { return LocalDate.of(year - 1, IMM_MONTHS[3], IMM_DAY); } } } else { final int i = month / 3; if (i == 0) { return LocalDate.of(year - 1, IMM_MONTHS[3], IMM_DAY); } else { return LocalDate.of(year, IMM_MONTHS[i - 1], 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 prevIMMTest() { LocalDate today = LocalDate.of(2011, Month.JUNE, 21); LocalDate prevIMM = getPrevIMMDate(today); assertEquals(LocalDate.of(2011, Month.JUNE, 20), prevIMM); today = LocalDate.of(2011, Month.JUNE, 20); prevIMM = getPrevIMMDate(today); assertEquals(LocalDate.of(2011, Month.MARCH, 20), prevIMM); prevIMM = getPrevIMMDate(prevIMM); assertEquals(LocalDate.of(2010, Month.DECEMBER, 20), prevIMM); today = LocalDate.of(2011, Month.JUNE, 18); prevIMM = getPrevIMMDate(today); assertEquals(LocalDate.of(2011, Month.MARCH, 20), prevIMM); today = LocalDate.of(1976, Month.JULY, 30); prevIMM = getPrevIMMDate(today); assertEquals(LocalDate.of(1976, Month.JUNE, 20), prevIMM); today = LocalDate.of(1977, Month.FEBRUARY, 13); prevIMM = getPrevIMMDate(today); assertEquals(LocalDate.of(1976, Month.DECEMBER, 20), prevIMM); today = LocalDate.of(2013, Month.MARCH, 1); prevIMM = getPrevIMMDate(today); assertEquals(LocalDate.of(2012, Month.DECEMBER, 20), prevIMM); }