DateParser { public static CSLDate toDateSingle(String year, String month) { int m = toMonth(month); int y = -1; Boolean circa = null; if (year != null && year.length() >= 4) { if (StringUtils.isNumeric(year)) { y = Integer.parseInt(year); } else { String fourDigit = year.substring(year.length() - 4); if (StringUtils.isNumeric(fourDigit)) { y = Integer.parseInt(fourDigit); if (year.length() > 4) { circa = Boolean.TRUE; } } } } CSLDateBuilder builder = new CSLDateBuilder(); if (y < 0) { return null; } if (m < 0) { return builder.dateParts(y).circa(circa).build(); } return builder.dateParts(y, m).circa(circa).build(); }  static CSLDate toDate(String dateString); static CSLDate toDate(String year, String month); static CSLDate toDateRange(String year, String month); static CSLDate toDateSingle(String year, String month); static int toMonth(String month);  }
@Test public void toSingleDate() { CSLDate d = DateParser.toDateSingle("2013", "Aug"); assertArrayEquals(new int[][] { new int[] { 2013, 8 } }, d.getDateParts()); d = DateParser.toDateSingle("2013", "march"); assertArrayEquals(new int[][] { new int[] { 2013, 3 } }, d.getDateParts()); d = DateParser.toDateSingle("2000", "1"); assertArrayEquals(new int[][] { new int[] { 2000, 1 } }, d.getDateParts()); d = DateParser.toDateSingle("2013", "Januar"); assertArrayEquals(new int[][] { new int[] { 2013, 1 } }, d.getDateParts()); d = DateParser.toDateSingle("2013", null); assertArrayEquals(new int[][] { new int[] { 2013 } }, d.getDateParts()); d = DateParser.toDateSingle("2013", "nothing"); assertArrayEquals(new int[][] { new int[] { 2013 } }, d.getDateParts()); d = DateParser.toDateSingle("in 2013", null); assertArrayEquals(new int[][] { new int[] { 2013 } }, d.getDateParts()); assertTrue(d.getCirca()); d = DateParser.toDateSingle(null, null); assertNull(d); }