DateTimeUtils { public static boolean suffixCorrect(Integer date, String suffix) { if (Strings.isNullOrEmpty(suffix)) { return true; } String correctSuffix = "th"; if (date % 10 == 1 && date % 100 != 11) { return "st".equalsIgnoreCase(suffix); } else if (date % 10 == 2 && date % 100 != 12) { return "nd".equalsIgnoreCase(suffix); } else if (date % 10 == 3 && date % 100 != 13) { return "rd".equalsIgnoreCase(suffix); } return correctSuffix.equalsIgnoreCase(suffix); } private  DateTimeUtils(); static DayOfWeek asDay(String day); static Month asMonth(String month); static Year asYear(String s); static boolean suffixCorrect(Integer date, String suffix);  }
@Test public void testSuffixCorrect() { assertTrue(DateTimeUtils.suffixCorrect(3, "")); assertTrue(DateTimeUtils.suffixCorrect(3, null)); assertTrue(DateTimeUtils.suffixCorrect(1, "st")); assertTrue(DateTimeUtils.suffixCorrect(21, "st")); assertTrue(DateTimeUtils.suffixCorrect(2, "nd")); assertTrue(DateTimeUtils.suffixCorrect(22, "nd")); assertTrue(DateTimeUtils.suffixCorrect(3, "rd")); assertTrue(DateTimeUtils.suffixCorrect(23, "rd")); assertTrue(DateTimeUtils.suffixCorrect(1642341, "st")); assertTrue(DateTimeUtils.suffixCorrect(11, "th")); assertTrue(DateTimeUtils.suffixCorrect(2011, "th")); assertFalse(DateTimeUtils.suffixCorrect(1, "th")); assertFalse(DateTimeUtils.suffixCorrect(2, "rd")); assertFalse(DateTimeUtils.suffixCorrect(3, "st")); assertFalse(DateTimeUtils.suffixCorrect(4, "nd")); assertFalse(DateTimeUtils.suffixCorrect(11, "st")); assertFalse(DateTimeUtils.suffixCorrect(12, "nd")); assertFalse(DateTimeUtils.suffixCorrect(13, "rd")); assertFalse(DateTimeUtils.suffixCorrect(2011, "st")); assertFalse(DateTimeUtils.suffixCorrect(2012, "nd")); assertFalse(DateTimeUtils.suffixCorrect(2013, "rd")); }