Refine search
@Test public void testFutureTimeRange() throws Exception { AcceptableRange range = AcceptableRange.getAcceptableRange("P0D/P1D", Date.class); assertEquals(0l, range.getBefore()); assertEquals(DAY_IN_MS, range.getAfter()); Date value = new Date(); DateRange searchRange = (DateRange) range.getSearchRange(value); assertEquals(0l, value.getTime() - searchRange.getMinValue().getTime()); assertEquals(DAY_IN_MS, searchRange.getMaxValue().getTime() - value.getTime()); } }
private static void addDate(Collection result, Date newDate) { for (Iterator<?> it = result.iterator(); it.hasNext(); ) { final Object element = it.next(); if (element instanceof Date) { if (newDate.equals(element)) return; } else if (((DateRange) element).contains(newDate)) { return; } } result.add(newDate); }
/** * Formats the specified object either as a single time, if it's a Date, or as a continuous * interval, if it's a DateRange (and will throw an {@link IllegalArgumentException} otherwise) * * @param date */ public String format(Object date) { if (date instanceof Date) { return format((Date) date); } else if (date instanceof DateRange) { DateRange range = (DateRange) date; StringBuilder sb = new StringBuilder(); format(range.getMinValue(), sb); sb.append("/"); format(range.getMaxValue(), sb); sb.append("/PT1S"); return sb.toString(); } else { throw new IllegalArgumentException( "Date argument should be either a Date or a " + "DateRange, however this one is neither: " + date); } }
if (pos.getIndex() == computedValue.length()) { DateRange range = f.expand(time); if (range.getMinValue().equals(range.getMaxValue())) { return range.getMinValue(); } else { return range;
if (range.contains((Date) o)) { result.add(o); if (range.intersects((DateRange) o)) { result.add(o);
public static void assertRangeLength(DateRange range, long expectedLength) { if (range.getMinValue() == null) fail("Expected finite range, saw: " + range); if (range.getMaxValue() == null) fail("Expected finite range, saw: " + range); long min = range.getMinValue().getTime(); long max = range.getMaxValue().getTime(); assertEquals("Range " + range + " should have length", expectedLength, max - min); }
? (Date) feature.getAttribute(endTimeAttribute) : startDate; DateRange range = new DateRange(startDate, endDate); subRequest.setTemporalSubset(range); if (classDataType.endsWith("Timestamp")) { value = new DateRange( new Date(((Timestamp) value).getTime()), new Date(((Timestamp) endValue).getTime())); } else if (classDataType.endsWith("Date")) { value = new DateRange((Date) value, (Date) endValue); } else { value = new NumberRange(objectClass, (Number) value, (Number) endValue);
String isoDate = toISODate(new Date()); writer.addGroupAttribute(null, new Attribute("date_created", isoDate)); writer.addGroupAttribute( DateRange startEnd = getDatasetDateRange(); if (startEnd != null) { String startIsoTime = toISODate(startEnd.getMinValue()); writer.addGroupAttribute(null, new Attribute("start_time", startIsoTime)); writer.addGroupAttribute(null, new Attribute("time_coverage_start", startIsoTime)); String endIsoTime = toISODate(startEnd.getMaxValue()); writer.addGroupAttribute(null, new Attribute("stop_time", endIsoTime)); writer.addGroupAttribute(null, new Attribute("time_coverage_end", endIsoTime));
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()); }
if (dateOrRange instanceof Date) { Date d = (Date) dateOrRange; if (d.before(toMatch)) { currentDistance = toMatch.getTime() - d.getTime(); if (currentDistance < shortestDistance) { shortestDistance = currentDistance; if (d.getMaxValue().before(toMatch)) { currentDistance = toMatch.getTime() - d.getMaxValue().getTime(); if (currentDistance < shortestDistance) { shortestDistance = currentDistance; candidate = d.getMaxValue(); } else if (d.getMinValue().after(toMatch)) { currentDistance = d.getMinValue().getTime() - toMatch.getTime(); if (currentDistance < shortestDistance) { candidate = d.getMinValue();
throws IOException { TreeSet<Object> domain = accessor.getTimeDomain(); Date slicePoint = timeSubset.getMinValue(); if (!domainContainsPoint(slicePoint, domain)) { if (curr.compareTo(slicePoint) > 0) { if (previous == null) { newSlicePoint = curr; break; } else { long diffPrevious = slicePoint.getTime() - previous.getTime(); long diffCurr = curr.getTime() - slicePoint.getTime(); if (diffCurr > diffPrevious) { newSlicePoint = previous; timeSubset = new DateRange(newSlicePoint, newSlicePoint);
if (low.compareTo(high) > 0) { throw new WCS20Exception( "Low greater than High: " timeSubset = new DateRange(low, high); } else if (dim instanceof DimensionSliceType) { final String slicePointS = slicing.getSlicePoint(); final Date slicePoint = PARSER.parseDateTime(slicePointS); timeSubset = new DateRange(slicePoint, slicePoint); } else { throw new WCS20Exception( && !timeSubset.getMinValue().equals(timeSubset.getMaxValue())) { throw new WCS20Exception( "Trimming on time is not supported at the moment on not StructuredGridCoverage2DReaders, only slicing is"); if (timeSubset != null && timeSubset.getMinValue().equals(timeSubset.getMaxValue())) { timeSubset = interpolateTime(timeSubset, accessor);
public int compare(Object o1, Object o2) { final boolean o1Date = o1 instanceof Date; final boolean o2Date = o2 instanceof Date; if (o1 == o2) { return 0; } // o1 date if (o1Date) { final Date dateLeft = (Date) o1; if (o2Date) { // o2 date return dateLeft.compareTo((Date) o2); } // o2 daterange return dateLeft.compareTo(((DateRange) o2).getMinValue()); } // o1 date range final DateRange left = (DateRange) o1; if (o2Date) { // o2 date return left.getMinValue().compareTo(((Date) o2)); } // o2 daterange return left.getMinValue().compareTo(((DateRange) o2).getMinValue()); } });
/** * Set the 2 strings as a DateRange. Return true in case of success * * @param low * @param high * @param selectedValues */ public boolean setAsDateRange(String low, String high, List<Object> selectedValues) { final Date l = parseAsDate(low); final Date h = parseAsDate(high); if (l != null && h != null) { if (l.compareTo(h) > 0) { throwInvalidRangeException(low, high); } selectedValues.add(new DateRange(l, h)); return true; } return false; }
DimensionInfo timeDimension) throws IOException { DateRange actualTimeSubset = new DateRange(accessor.getMinTime(), accessor.getMaxTime()); if (!requestedTimeSubset.intersects(actualTimeSubset)) { throw new WCS20Exception( "Requested time subset does not intersect the declared range " if (!requestedTimeSubset.getMinValue().equals(requestedTimeSubset.getMaxValue()) && (presentation == DimensionPresentation.LIST || presentation == DimensionPresentation.CONTINUOUS_INTERVAL)) { for (Object o : timeDomain) { if (o instanceof Date) { intersectionFound |= requestedTimeSubset.contains((Date) o); } else if (o instanceof DateRange) { intersectionFound |= requestedTimeSubset.intersects((Range<?>) o);
if (curr instanceof Date) { Date date = (Date) curr; int result = date.compareTo(sliceDate); if (result > 0) { return false; if (range.contains(sliceDate)) { return true; } else if (range.getMaxValue().compareTo(sliceDate) < 0) { return false;
@JsonProperty("temporal") @JacksonXmlProperty() public String[] getTemporalArray() { if (temporal != null) { return new String[] { ISO_INSTANT.format(temporal.getMinValue().toInstant()), ISO_INSTANT.format(temporal.getMaxValue().toInstant()) }; } else { return null; } } }
private String toWmsTimeSpecification(Object parsedTime) { String mapTime; if (parsedTime instanceof Date) { mapTime = formatter.format(((Date) parsedTime).toInstant()); } else if (parsedTime instanceof DateRange) { DateRange range = (DateRange) parsedTime; mapTime = formatter.format(range.getMinValue().toInstant()) + "/" + formatter.format(range.getMinValue().toInstant()); } else { throw new WPSException("Unexpected parsed date type: " + parsedTime); } return mapTime; }
/** * Builds a single time range from the domain, be it made of Date or TimeRange objects * * @param values */ private DateRange getMinMaxTimeInterval(TreeSet<? extends Object> values) { Object minValue = values.first(); Object maxValue = values.last(); Date min, max; if (minValue instanceof DateRange) { min = ((DateRange) minValue).getMinValue(); } else { min = (Date) minValue; } if (maxValue instanceof DateRange) { max = ((DateRange) maxValue).getMaxValue(); } else { max = (Date) maxValue; } return new DateRange(min, max); }