CSLDateParser { public CSLDate parse(String str) { Map<String, Object> res; try { @SuppressWarnings("unchecked") Map<String, Object> m = runner.callMethod( parser, "parseDateToArray", Map.class, str); res = m; } catch (ScriptRunnerException e) { throw new IllegalArgumentException("Could not update items", e); } CSLDate r = CSLDate.fromJson(res); if (r.getDateParts().length == 2 && Arrays.equals(r.getDateParts()[0], r.getDateParts()[1])) { r = new CSLDateBuilder(r).dateParts(r.getDateParts()[0]).build(); } return r; } CSLDateParser(); CSLDate parse(String str);  }
@Test public void simple() { CSLDateParser parser = new CSLDateParser(); CSLDate date = parser.parse("2013-11-17"); assertArrayEquals(new int[][] { new int[] { 2013, 11, 17 } }, date.getDateParts()); date = parser.parse("2013-11"); assertArrayEquals(new int[][] { new int[] { 2013, 11 } }, date.getDateParts()); date = parser.parse("2013"); assertArrayEquals(new int[][] { new int[] { 2013 } }, date.getDateParts()); date = parser.parse(""); assertArrayEquals(new int[][] { new int[0] }, date.getDateParts()); }
@Test public void alpha() { CSLDateParser parser = new CSLDateParser(); CSLDate date = parser.parse("November 2013"); assertArrayEquals(new int[][] { new int[] { 2013, 11 } }, date.getDateParts()); }
@Test public void slash() { CSLDateParser parser = new CSLDateParser(); CSLDate date = parser.parse("2013/11/17"); assertArrayEquals(new int[][] { new int[] { 2013, 11, 17 } }, date.getDateParts()); date = parser.parse("11/17/2013"); assertArrayEquals(new int[][] { new int[] { 2013, 11, 17 } }, date.getDateParts()); }