DateTimeUtils { public static Year asYear(String s) { String year = s.replaceAll("[^\\d]", ""); if (year.isEmpty()) { return null; } Year y; if (year.length() == 2) { Integer iYear; try { iYear = Integer.parseInt(year); } catch (NumberFormatException nfe) { LOGGER.warn("Couldn't parse year {}", s, nfe); return null; } if (iYear < 70) { y = Year.of(2000 + iYear); } else { y = Year.of(1900 + iYear); } } else { try { y = Year.parse(year); } catch (DateTimeParseException dtpe) { LOGGER.warn("Couldn't parse year {}", s, dtpe); return null; } } return y; } 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 testAsYear() { assertEquals(Year.of(2006), DateTimeUtils.asYear("2006")); assertEquals(Year.of(2006), DateTimeUtils.asYear("06")); assertEquals(Year.of(1984), DateTimeUtils.asYear("'84")); assertNull(DateTimeUtils.asYear("last year")); }