DateRange { public static DateRange parseDateRange(String dateRange) throws ParseException { String[] splits = dateRange.split(SEPARATOR); String startString = splits[0].replace(OPENING_BRACKET, ""); String stopString = splits[1].replace(CLOSING_BRACKET, ""); return new DateRange(parseDate(startString), parseDate(stopString)); } DateRange(Date startDate, Date stopDate); Date getStartDate(); Date getStopDate(); @Override String toString(); static DateRange parseDateRange(String dateRange); static final DateRange OPEN_RANGE; static final DateFormat DATE_FORMAT; }
@Test public void testParseDateRange() throws Exception { DateRange dateRange = DateRange.parseDateRange("[1245-04-22:1245-04-23]"); DateFormat dateFormat = DateRange.DATE_FORMAT; Date expectedStartDate = dateFormat.parse("1245-04-22"); Date expectedStopDate = dateFormat.parse("1245-04-23"); assertEquals(expectedStartDate, dateRange.getStartDate()); assertEquals(expectedStopDate, dateRange.getStopDate()); }