Example usage for org.joda.time.format ISODateTimeFormat dateTimeParser

List of usage examples for org.joda.time.format ISODateTimeFormat dateTimeParser

Introduction

In this page you can find the example usage for org.joda.time.format ISODateTimeFormat dateTimeParser.

Prototype

public static DateTimeFormatter dateTimeParser() 

Source Link

Document

Returns a generic ISO datetime parser which parses either a date or a time or both.

Usage

From source file:com.zauberlabs.commons.mom.converter.impl.jodatime.StringToXMLGregorianCalendarTypeConverter.java

License:Apache License

/**
 * Answers a constant {@link JodaStringToXMLGregorianCalendarTypeConverter}
 * that uses {@code ISODateTimeFormat.dateTimeParser()} as formatter
 *
 * @return a constant {@link TypeConverter}
 *//* ww  w  . j a  v  a2 s  .c o  m*/
@Constant
public static TypeConverter isoDateTime() {
    return from(ISODateTimeFormat.dateTimeParser());
}

From source file:de.zib.gndms.common.model.gorfx.types.io.SliceOrderPropertyReader.java

License:Apache License

@Override
public void read() {

    super.read();

    Properties properties = getProperties();
    SliceOrder sliceOrder = getProduct();

    final String sliceId = properties.getProperty(SliceOrderProperties.SLICE_ID.key);
    final String sliceSize = properties.getProperty(SliceOrderProperties.SLICE_SIZE.key);
    final String sliceTermTime = properties.getProperty(SliceOrderProperties.SLICE_TERMINATION_TIME.key);

    if (sliceId != null)
        sliceOrder.setSliceId(sliceId);//w w w.  j a  v a 2  s.  c  o  m
    else if (sliceSize != null || sliceTermTime != null) {
        Long _sliceSize = null;
        DateTime _sliceTermTime = null;
        if (sliceSize != null)
            _sliceSize = Long.parseLong(sliceSize);
        if (sliceTermTime != null)
            _sliceTermTime = ISODateTimeFormat.dateTimeParser().parseDateTime(sliceTermTime);

        sliceOrder.setSliceConfiguration(new SliceConfiguration(_sliceSize, _sliceTermTime));
    }
}

From source file:de.zib.gndms.dspace.service.SubspaceServiceImpl.java

License:Apache License

@Override
@RequestMapping(value = "/_{subspaceId}/_{sliceKindId}", method = RequestMethod.POST)
@Secured("ROLE_USER")
public ResponseEntity<Specifier<Void>> createSlice(@PathVariable final String subspaceId,
        @PathVariable final String sliceKindId, @RequestBody final String config,
        @RequestHeader("DN") final String dn) {
    GNDMSResponseHeader headers = getSliceKindHeaders(subspaceId, sliceKindId, dn);

    SliceKind sliceKind;//from  w  w w . j a  v a  2s .c o  m
    try {
        sliceKind = slicekindProvider.get(subspaceId, sliceKindId);
    } catch (NoSuchElementException e) {
        logger.warn("Tried to access non existing SliceKind " + subspaceId + "/" + sliceKindId, e);
        return new ResponseEntity<Specifier<Void>>(null, headers, HttpStatus.NOT_FOUND);
    }

    try {
        Map<String, String> parameters = new HashMap<String, String>();
        ParameterTools.parseParameters(parameters, config, null);

        DateTimeFormatter fmt = ISODateTimeFormat.dateTimeParser();
        DateTime terminationTime;
        long sliceSize;

        if (parameters.containsKey(SliceConfiguration.TERMINATION_TIME))
            terminationTime = fmt.parseDateTime(parameters.get(SliceConfiguration.TERMINATION_TIME));
        else
            terminationTime = new DateTime().plus(sliceKind.getDefaultTimeToLive());

        if (parameters.containsKey(SliceConfiguration.SLICE_SIZE))
            sliceSize = Long.parseLong(parameters.get(SliceConfiguration.SLICE_SIZE));
        else
            sliceSize = sliceKind.getDefaultTimeToLive();

        // use provider to create slice
        String slice = sliceProvider.createSlice(subspaceId, sliceKindId, dn, terminationTime, sliceSize);

        subspaceProvider.invalidate(subspaceId);

        // generate specifier and return it
        Specifier<Void> spec = new Specifier<Void>();

        HashMap<String, String> urimap = new HashMap<String, String>(2);
        urimap.put(UriFactory.SERVICE, "dspace");
        urimap.put(UriFactory.SUBSPACE, subspaceId);
        urimap.put(UriFactory.SLICE_KIND, sliceKindId);
        urimap.put(UriFactory.SLICE, slice);
        urimap.put(UriFactory.BASE_URL, baseUrl);
        spec.setUriMap(new HashMap<String, String>(urimap));
        spec.setUrl(uriFactory.sliceUri(urimap, null));

        return new ResponseEntity<Specifier<Void>>(spec, headers, HttpStatus.CREATED);
    } catch (WrongConfigurationException e) {
        logger.warn(e.getMessage());
        return new ResponseEntity<Specifier<Void>>(null, headers, HttpStatus.BAD_REQUEST);
    } catch (NoSuchElementException e) {
        logger.warn(e.getMessage());
        return new ResponseEntity<Specifier<Void>>(null, headers, HttpStatus.NOT_FOUND);
    } catch (ParameterTools.ParameterParseException e) {
        logger.info("Illegal request: Could not parse paramter string \"" + ParameterTools.escape(config)
                + "\". " + e.getMessage());
        return new ResponseEntity<Specifier<Void>>(null, headers, HttpStatus.BAD_REQUEST);
    }
}

From source file:de.zib.gndms.kit.config.AbstractConfig.java

License:Apache License

/**
 * Parse a String in ISO8601-format to DateTime-Object
 *
 * @param optionParam a String in ISO8601-format 
 * @return a DateTime-Object retrieved from the String
 *//*from   w w w  .  j  a v a 2  s . c  o  m*/
public static @NotNull DateTime parseISO8601(final @NotNull String optionParam) {
    if (optionParam.length() == 0)
        throw new IllegalArgumentException("Empty ISO 8601 timestamp");
    return optionParam.charAt(0) == 'P'
            ? new DateTime(0L).plus(ISOPeriodFormat.standard().parsePeriod(optionParam))
            : ISODateTimeFormat.dateTimeParser().parseDateTime(optionParam);
}

From source file:edu.jhu.hlt.concrete.ingesters.webposts.WebPostIngester.java

License:Open Source License

/**
 *
 */
public WebPostIngester() {
    this.inF = XMLInputFactory.newInstance();
    this.dtf = ISODateTimeFormat.dateTimeParser();
}

From source file:edu.unc.lib.dl.cdr.services.model.EnhancementApplication.java

License:Apache License

public void setLastAppliedFromISO8601(String lastApplied) {
    this.lastApplied = ISODateTimeFormat.dateTimeParser().withOffsetParsed().parseDateTime(lastApplied)
            .toDate();/*w  ww.j a  v a  2  s. co  m*/
}

From source file:edu.unc.lib.dl.util.DateTimeUtil.java

License:Apache License

/**
 * Parse a date in any ISO 8601 format. Default TZ is based on Locale.
 *
 * @param isoDate/*from  ww w  . j  a v  a  2 s. c om*/
 *           ISO8601 date/time string with or without TZ offset
 * @return a Joda DateTime object in UTC (call toString() to print)
 */
public static DateTime parseISO8601toUTC(String isoDate) {
    DateTime result = null;
    DateTimeFormatter fmt = ISODateTimeFormat.dateTimeParser().withOffsetParsed();
    // TODO what about preserving the precision of the original?
    DateTime isoDT = fmt.parseDateTime(isoDate);
    if (isoDT.year().get() > 9999) {
        // you parsed my month as part of the year!
        try {
            fmt = DateTimeFormat.forPattern("yyyyMMdd");
            fmt = fmt.withZone(DateTimeZone.forID("America/New_York"));
            isoDT = fmt.parseDateTime(isoDate);
        } catch (IllegalArgumentException e) {
            try {
                fmt = DateTimeFormat.forPattern("yyyyMM");
                fmt = fmt.withZone(DateTimeZone.forID("America/New_York"));
                isoDT = fmt.parseDateTime(isoDate);
            } catch (IllegalArgumentException e1) {
                try {
                    fmt = DateTimeFormat.forPattern("yyyy");
                    fmt = fmt.withZone(DateTimeZone.forID("America/New_York"));
                    isoDT = fmt.parseDateTime(isoDate);
                } catch (IllegalArgumentException ignored) {
                    // I guess we go with first parse?
                }
            }
        }
    }
    result = isoDT.withZoneRetainFields(DateTimeZone.forID("Etc/UTC"));
    return result;
}

From source file:ee.ria.xroad.common.conf.globalconf.ConfigurationUtils.java

License:Open Source License

/**
 * @param expireDateStr the ISO date as string
 * @return DateTime object//  ww  w. j a  v  a2s . co  m
 */
public static DateTime parseISODateTime(String expireDateStr) {
    return ISODateTimeFormat.dateTimeParser().parseDateTime(expireDateStr);
}

From source file:es.pode.adl.datamodels.datatypes.DateTimeValidator.java

License:Open Source License

/**
 * Compares two valid data model elements for equality.
 * //  w w w.j av  a2 s . com
 * @param iFirst  The first value being compared.
 * 
 * @param iSecond The second value being compared.
 * 
 * @param iDelimiters The common set of delimiters associated with the
 * values being compared.
 * 
 * @return Returns <code>true</code> if the two values are equal, otherwise
 *         <code>false</code>.
 */
public boolean compare(String iFirst, String iSecond, Vector iDelimiters) {

    boolean equal = true;

    DateTimeFormatter dtp = ISODateTimeFormat.dateTimeParser();

    try {
        // Parse the first string and remove the sub-seconds
        DateTime dt1 = dtp.parseDateTime(iFirst);
        dt1 = new DateTime(dt1.getYear(), dt1.getMonthOfYear(), dt1.getDayOfMonth(), dt1.getHourOfDay(),
                dt1.getMinuteOfHour(), dt1.getSecondOfMinute(), 0);

        // Parse the second string and remove the sub-seconds
        DateTime dt2 = dtp.parseDateTime(iSecond);
        dt2 = new DateTime(dt2.getYear(), dt2.getMonthOfYear(), dt2.getDayOfMonth(), dt2.getHourOfDay(),
                dt2.getMinuteOfHour(), dt2.getSecondOfMinute(), 0);

        equal = dt1.equals(dt2);
    } catch (Exception e) {
        // String format error -- these cannot be equal
        equal = false;
    }

    return equal;
}

From source file:in.dream_lab.eventgen.factory.CsvSplitter.java

License:Apache License

public static List<TableClass> roundRobinSplitCsvToMemory(String inputSortedCSVFileName, int numThreads,
        double accFactor, String datasetType) throws IOException {
    CSVReader reader = new CSVReader(new FileReader(inputSortedCSVFileName));
    String[] nextLine;//from w ww.j  a  v  a 2s.co m
    int ctr = 0;
    String[] headers = reader.readNext(); // use .intern() later
    List<String> headerList = new ArrayList<String>();
    for (String s : headers) {
        headerList.add(s);
    }

    List<TableClass> tableList = new ArrayList<TableClass>();
    for (int i = 0; i < numThreads; i++) {
        TableClass tableClass = new TableClass();
        tableClass.setHeader(headerList);
        tableList.add(tableClass);
    }

    TableClass tableClass = null;
    boolean flag = true;
    long startTs = 0, deltaTs = 0;

    //CODE TO ACCOMODATE PLUG DATASET SPECIAL CASE TO RUN IT FOR 10 MINS
    int numMins = 90000; // Keeping it fixed for current set of experiments
    Double cutOffTimeStamp = 0.0;//int msgs=0;
    while ((nextLine = reader.readNext()) != null) {
        // nextLine[] is an array of values from the line
        // System.out.println(nextLine[0] + "  " + nextLine[1] + "   " +
        // nextLine[2] + "  " + nextLine[3] + "  etc...");

        List<String> row = new ArrayList<String>();
        for (int i = 0; i < nextLine.length; i++) {
            row.add(nextLine[i]);
        }

        tableClass = tableList.get(ctr);
        ctr = (ctr + 1) % numThreads;

        int timestampColIndex = 0;
        DateTime date = null;
        if (datasetType.equals("TAXI")) {
            timestampColIndex = 3;
            date = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss").parseDateTime(nextLine[timestampColIndex]);
        } else if (datasetType.equals("SYS")) {
            timestampColIndex = 0;
            date = ISODateTimeFormat.dateTimeParser().parseDateTime(nextLine[timestampColIndex]);
            //date = ISODateTimeFormat.dateTimeParser().parseDateTime(
            //      nextLine[timestampColIndex]);
        } else if (datasetType.equals("PLUG")) {
            timestampColIndex = 1;
            date = new DateTime(Long.parseLong(nextLine[timestampColIndex]) * 1000);
            //date = ISODateTimeFormat.dateTimeParser().parseDateTime(
            //      nextLine[timestampColIndex]);
        }

        else if (datasetType.equals("UIDAI")) {
            timestampColIndex = 1;
            date = new DateTime(Long.parseLong(nextLine[timestampColIndex]) * 1000);
            //date = ISODateTimeFormat.dateTimeParser().parseDateTime(
            //      nextLine[timestampColIndex]);
        }

        long ts = date.getMillis();
        if (flag) {
            startTs = ts;
            flag = false;
            cutOffTimeStamp = startTs + numMins * (1.0 / accFactor) * 60 * 1000; // accFactor is actually the scaling factor or deceleration factor
            //System.out.println("GOTSTART TS : "  + ts + " cut off " + cutOffTimeStamp);
        }

        if (ts > cutOffTimeStamp) {
            //System.out.println("GOT TS : "  + ts + " cut off " + cutOffTimeStamp + "  msgs " + (++msgs));
            break; // No More data to be loaded
        }

        deltaTs = ts - startTs;
        deltaTs = (long) (accFactor * deltaTs);
        tableClass.append(deltaTs, row);
        //System.out.println("ts " + (ts - startTs) + " deltaTs " + deltaTs);
    }

    reader.close();
    return tableList;
}