public void testContinuousInterval() throws ParseException { TimeKvpParser timeKvpParser = new TimeKvpParser("TIME"); List l = new ArrayList((Collection) timeKvpParser.parse(CONTINUOUS_PERIOD)); // Verify that the list contains at least one element. assertFalse(l.isEmpty()); assertTrue(l.get(0) instanceof DateRange); final DateRange range = (DateRange) l.get(0); assertEquals(format.parse("2007-01-01T12Z"), range.getMinValue()); Date end = format.parse("2007-01-31T13Z"); end.setTime(end.getTime() - 1); assertEquals(end, range.getMaxValue()); }
public void testInvalidDualDuration() throws ParseException { TimeKvpParser timeKvpParser = new TimeKvpParser("TIME"); boolean exception = false; try { timeKvpParser.parse(CONTINUOUS_PERIOD_INVALID_DURATION); // Verify that an exception was encountered for the invalid duration fail("No exception thrown for invalid duration"); } catch (ParseException ex) { assertTrue(ex.getMessage().startsWith("Invalid time period")); } }
public void testInclusions() throws ParseException { TimeKvpParser timeKvpParser = new TimeKvpParser("TIME"); List l = new ArrayList( (Collection) timeKvpParser.parse( CONTINUOUS_PERIOD + ",2007-01-29T12Z," + "2007-01-12T12Z,2007-01-17T12Z,2007-01-01T12Z/2007-01-15T12Z")); // Verify that the list contains at least one element. assertFalse(l.isEmpty()); assertTrue(l.size() == 1); assertTrue(l.get(0) instanceof DateRange); final DateRange range = (DateRange) l.get(0); assertRange(range, format.parse("2007-01-01T12Z"), format.parse("2007-01-31T13Z")); }
public void testContinuousIntervalDuration() throws ParseException { TimeKvpParser timeKvpParser = new TimeKvpParser("TIME"); List l = new ArrayList((Collection) timeKvpParser.parse(CONTINUOUS_PERIOD_TIME_DURATION)); // Verify that the list contains at least one element. assertFalse(l.isEmpty()); assertTrue(l.get(0) instanceof DateRange); final DateRange range = (DateRange) l.get(0); assertEquals(format.parse("2007-01-01T12Z"), range.getMinValue()); Date end = format.parse("2007-01-02T13Z"); assertEquals(end, range.getMaxValue()); }
public void testMixedValues() throws ParseException { TimeKvpParser timeKvpParser = new TimeKvpParser("TIME"); List l = new ArrayList( (Collection) timeKvpParser.parse(CONTINUOUS_PERIOD + ",2007-02-01T12Z")); // Verify that the list contains at least one element. assertFalse(l.isEmpty()); assertTrue(l.get(0) instanceof DateRange); final DateRange range = (DateRange) l.get(0); assertEquals(format.parse("2007-01-01T12Z"), range.getMinValue()); Date end = format.parse("2007-01-31T13Z"); end.setTime(end.getTime() - 1); assertEquals(end, range.getMaxValue()); assertRange( (DateRange) l.get(1), format.parse("2007-02-01T12Z"), format.parse("2007-02-01T13Z")); }
/** * Compares the dates obtained by parsing the time parameter with the expected values. * * @throws ParseException if the string can't be parsed. */ public void testInterval() throws ParseException { TimeKvpParser timeKvpParser = new TimeKvpParser("TIME"); List l = new ArrayList((Collection) timeKvpParser.parse(PERIOD)); // Verify that the list contains at least one element. assertFalse(l.isEmpty()); assertInstant(format.parse("2007-01-01T12Z"), l.get(0)); assertInstant(format.parse("2007-01-03T00Z"), l.get(1)); assertInstant(format.parse("2007-01-04T12Z"), l.get(2)); assertInstant(format.parse("2007-01-06T00Z"), l.get(3)); assertInstant(format.parse("2007-01-07T12Z"), l.get(4)); assertInstant(format.parse("2007-01-09T00Z"), l.get(5)); assertInstant(format.parse("2007-01-10T12Z"), l.get(6)); assertInstant(format.parse("2007-01-12T00Z"), l.get(7)); l = new ArrayList((Collection) timeKvpParser.parse("2007-01-01T12Z/2007-01-01T13Z/PT10M")); // Verify that the list contains at least one element. assertFalse(l.isEmpty()); assertEquals(12, l.size()); assertInstant(format.parse("2007-01-01T12Z"), l.get(0)); }
public void testOrderedValues() throws Exception { TimeKvpParser timeKvpParser = new TimeKvpParser("TIME"); List l = new ArrayList(
public void testNegativeYearCompliance() throws Exception { TimeKvpParser timeKvpParser = new TimeKvpParser("TIME"); GregorianCalendar cal = new GregorianCalendar(); cal.setTimeZone(TimeZone.getTimeZone("GMT")); // base assertion - 0001 is year 1 DateRange date = (DateRange) ((List) timeKvpParser.parse("01-06-01")).get(0); cal.setTime(date.getMinValue()); assertEquals(1, cal.get(Calendar.YEAR)); assertEquals(GregorianCalendar.AD, cal.get(Calendar.ERA)); date = (DateRange) ((List) timeKvpParser.parse("00-06-01")).get(0); cal.setTime(date.getMinValue()); // calendar calls it year 1, ISO spec means it's year 0 // but we're just parsing here... assertEquals(1, cal.get(Calendar.YEAR)); assertEquals(GregorianCalendar.BC, cal.get(Calendar.ERA)); // so, the next year should be 2 date = (DateRange) ((List) timeKvpParser.parse("-01-06-01")).get(0); cal.setTime(date.getMinValue()); assertEquals(2, cal.get(Calendar.YEAR)); assertEquals(GregorianCalendar.BC, cal.get(Calendar.ERA)); // now, big negative year compliance (see the spec, appendix D 2.2, pp 57-58) date = (DateRange) ((List) timeKvpParser.parse("-18000-06-01")).get(0); cal.setTime(date.getMinValue()); assertEquals(18001, cal.get(Calendar.YEAR)); assertEquals(GregorianCalendar.BC, cal.get(Calendar.ERA)); }
@SuppressWarnings({"rawtypes", "unchecked"}) public void testContinuousRelativeInterval() throws ParseException { final int millisInDay = (int) TimeParser.MILLIS_IN_DAY; TimeKvpParser timeKvpParser = new TimeKvpParser("TIME"); Calendar back; Calendar now;
value = null; } else if (Date.class.isAssignableFrom(dimensionClass)) { value = new TimeKvpParser("whatever").parse(strValue); } else if (Double.class.isAssignableFrom(dimensionClass)) { value = new ElevationKvpParser("whatever").parse(strValue);