Example usage for org.joda.time Interval parse

List of usage examples for org.joda.time Interval parse

Introduction

In this page you can find the example usage for org.joda.time Interval parse.

Prototype

public static Interval parse(String str) 

Source Link

Document

Parses an Interval from the specified string.

Usage

From source file:org.n52.series.api.proxy.v0.srv.DataService.java

License:Open Source License

protected DesignOptions createDesignOptions(ParameterSet parameterSet, ArrayList<TimeseriesProperties> props,
        boolean renderGrid) {
    Interval timespan = Interval.parse(parameterSet.getTimespan());
    long begin = timespan.getStartMillis();
    long end = timespan.getEndMillis();
    return new DesignOptions(props, begin, end, renderGrid);
}

From source file:org.n52.series.api.proxy.v1.srv.DataService.java

License:Open Source License

protected DesignOptions createDesignOptions(UndesignedParameterSet parameterSet,
        ArrayList<TimeseriesProperties> props, boolean renderGrid) {
    Interval timespan = Interval.parse(parameterSet.getTimespan());
    long begin = timespan.getStartMillis();
    long end = timespan.getEndMillis();
    DesignOptions designOptions = new DesignOptions(props, begin, end, renderGrid);
    if (parameterSet.getResultTime() != null) {
        Instant resultTime = Instant.parse(parameterSet.getResultTime());
        designOptions.setResultTime(resultTime.getMillis());
    }// w  w  w. j ava  2  s . c  o m
    return designOptions;
}

From source file:org.n52.tamis.core.javarepresentations.processes.execute.TimespanToSosTemporalFilterConverter.java

License:Open Source License

/**
 * Converts a timespan String that describes a time interval in IS= 8601
 * format to a SOS temporalFilter String.
 * /*from  w ww . j a  v a2 s  .  c  o  m*/
 * E.g.: the timespan "PT12H/2013-08-06" will be converted to the String
 * "2013-08-05T12:00:00.000Z/2013-08-06T00:00:00.000Z", which may serve as
 * temporalFIlter parameter in a SOS GetObservation request.
 * 
 * @param timespan
 *            an ISO 8601 encoded timespan.
 * @return a String, consisting of "{startTime}/{endTime}",which may serve
 *         as temporalFIlter parameter in a SOS GetObservation request
 * @throws IOException
 */
public static String convertIso8601TimespanToSosTemporalFilter(String timespan) throws IOException {
    // /*
    // * if timespan String contains a "Z" then the parsed time shall be
    // interpreted as UTC.
    // * A timespan String like "PT12H/2013-08-06Z" cannot be parsed due to
    // the final Z; parser throws malformed format exception.
    // *
    // * Hence, we set UTC and standard interpretation and remove the Z from
    // the String
    // */
    // if (encodedTimespan.contains("Z")){
    // DateTimeZone.setDefault(DateTimeZone.UTC);
    //
    // encodedTimespan.
    // }

    try {

        // set UTC as standard time
        DateTimeZone.setDefault(DateTimeZone.UTC);

        Interval timeInterval = Interval.parse(timespan);

        DateTime startTime = timeInterval.getStart();
        DateTime endTime = timeInterval.getEnd();

        String sosTemproalFilter = startTime.toString() + "/" + endTime.toString();

        return sosTemproalFilter;

    } catch (IllegalArgumentException e) {
        String message = "Could not parse timespan parameter." + timespan;
        throw new IOException(message, e);
    }
}

From source file:org.n52.web.ctrl.DataController.java

License:Open Source License

private void checkAgainstTimespanRestriction(String timespan) {
    if (requestIntervalRestriction != null) {
        Duration duration = Period.parse(requestIntervalRestriction).toDurationFrom(new DateTime());
        if (duration.getMillis() < Interval.parse(timespan).toDurationMillis()) {
            throw new BadRequestException("Requested timespan is to long, please use a period shorter than '"
                    + requestIntervalRestriction + "'");
        }//from w ww . ja  va  2  s. c  o m
    }
}

From source file:org.n52.web.ctrl.TimeseriesDataController.java

License:Open Source License

private void checkAgainstTimespanRestriction(String timespan) {
    Duration duration = Period.parse(requestIntervalRestriction).toDurationFrom(new DateTime());
    if (duration.getMillis() < Interval.parse(timespan).toDurationMillis()) {
        throw new BadRequestException("Requested timespan is to long, please use a period shorter than '"
                + requestIntervalRestriction + "'");
    }//from   ww w.  j  av a 2 s. c o  m
}

From source file:org.supercsv.cellprocessor.joda.ParseInterval.java

License:Apache License

/**
 * {@inheritDoc}//from ww w  .jav  a2s  .c  o m
 * 
 * @throws SuperCsvCellProcessorException
 *             if value is null or is not a String
 */
public Object execute(final Object value, final CsvContext context) {
    validateInputNotNull(value, context);
    if (!(value instanceof String)) {
        throw new SuperCsvCellProcessorException(String.class, value, context, this);
    }
    final Interval result;
    try {
        result = Interval.parse((String) value);
    } catch (IllegalArgumentException e) {
        throw new SuperCsvCellProcessorException("Failed to parse value as an Interval", context, this, e);
    }
    return next.execute(result, context);
}