Example usage for org.joda.time DateTime parse

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

Introduction

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

Prototype

@FromString
public static DateTime parse(String str) 

Source Link

Document

Parses a DateTime from the specified string.

Usage

From source file:de.localtoast.launchit.db.SQLiteHelper.java

License:Open Source License

private AppMetaData getAppMetaData(Cursor cursor) {
    DateTime lastIncrement = DateTime.parse(cursor.getString(2));
    return new AppMetaData(cursor.getString(0), lastIncrement, cursor.getInt(1));
}

From source file:de.minecrawler.cache.CacheManager.java

License:Open Source License

/**
 * Parses the cache index and loads the needed information from the cache
 * to the map./* w w w . j a va 2  s  .  c o  m*/
 */
private void loadIndex() {
    try {
        File cacheIndexFile = new File(CACHE_INDEX_FILENAME);
        if (!cacheIndexFile.exists())
            return;

        BufferedReader bReader = new BufferedReader(new FileReader(cacheIndexFile));
        String line = "";

        int maxIndex = 0;

        while ((line = bReader.readLine()) != null) {
            if (line.isEmpty())
                continue;

            String[] split = line.split(" ");
            int pos = 0;
            URL url = new URL(split[pos++]);
            int depth = Integer.valueOf(split[pos++]);
            DateTime date = DateTime.parse(split[pos++]);
            int fileNumber = Integer.valueOf(split[pos++]);

            List<CacheIndex> list = urlIndex.get(url);
            if (list == null) {
                list = new ArrayList<CacheIndex>();
                urlIndex.put(url, list);
            }

            list.add(new CacheIndex(fileNumber, depth, date, url));

            if (fileNumber > maxIndex)
                maxIndex = fileNumber;
        }

        bReader.close();
        this.currentIndex = maxIndex;
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:di.uniba.it.tee2.util.TEEUtils.java

License:Open Source License

/**
 * @param oldDate/*from  w w  w  .  ja  v a2  s  .  co  m*/
 * @return
 * @throws java.text.ParseException
 */
public static String normalizeTime(String oldDate) throws Exception {
    Date now = new Date();
    if (oldDate.equals("PRESENT_REF")) {
        oldDate = new SimpleDateFormat("yyyy-MM-dd").format(now);
    } else if (oldDate.endsWith("FA")) {
        oldDate = oldDate.replace("FA", "09-23");
    } else if (oldDate.endsWith("WI")) {
        oldDate = oldDate.replace("WI", "12-21");
    } else if (oldDate.endsWith("SU")) {
        oldDate = oldDate.replace("SU", "06-20");
    } else if (oldDate.endsWith("SP")) {
        oldDate = oldDate.replace("SP", "03-20");
    } else if (oldDate.equals("PAST_REF") || (oldDate.endsWith("WE"))) {
        return "";
    } else if (oldDate.equals("FUTURE_REF")) {
        return new SimpleDateFormat("yyyyMMdd").format(now);
    }

    DateTime oldD = DateTime.parse(oldDate);

    DateTimeFormatter OldDFmt = ISODateTimeFormat.date();
    String str = OldDFmt.print(oldD);

    Date date = new SimpleDateFormat("yyyy-MM-dd").parse(str);
    String newDate = DateTools.dateToString(date, DateTools.Resolution.DAY);

    return newDate;
}

From source file:dk.dma.ais.view.rest.QueryParameterHelper.java

License:Apache License

private static DateTime findAt(UriInfo info) {
    String at = QueryParameterValidators.getParameter(info, "at", null);
    return isBlank(at) ? null : DateTime.parse(at);
}

From source file:dk.nsi.minlog.export.dao.splunk.LogEntrySearchDaoSplunk.java

License:Open Source License

private static LogEntry transformMapToEntity(final Map<String, String> map) {
    if (logger.isTraceEnabled()) {
        logger.trace("Mapping to entity: \n" + map);
    }//w  w w .  j  a v  a 2s  . c om
    LogEntry logEntry = new LogEntry();

    logEntry.setRegKode(UUID.randomUUID().toString());
    logEntry.setTidspunkt(DateTime.parse(map.get("EventDateTime")));
    logEntry.setCprNrBorger(map.get("PersonCivilRegistrationIdentifier"));
    logEntry.setBruger(map.get("UserIdentifier"));
    logEntry.setAnsvarlig(map.get("UserIdentifierOnBehalfOf"));
    logEntry.setOrgUsingID(map.get("HealthcareProfessionalOrganization"));
    logEntry.setSystemName(map.get("SourceSystemIdentifier"));
    logEntry.setHandling(map.get("Activity"));
    logEntry.setSessionId(map.get("SessionId"));

    //Notice splunk return in seconds since epoch, datetime uses millis.
    long indexTime = Long.parseLong(map.get("_indextime")) * 1000;
    logEntry.setLastUpdated(new DateTime(indexTime));
    return logEntry;
}

From source file:dm2e2edm.Dm2e2Edm.java

private synchronized void addToTarget(Resource targetSubject, Property targetProp, RDFNode targetObject,
        Property origProp) {/*from  www.j  av a 2  s  .  c o  m*/
    //      log.debug("STMT");
    //      log.debug("  S: {}", targetSubject);
    //      log.debug("  P: {}", targetProp);
    //      log.debug("  O: {}", targetObject);
    //      log.debug("ORIGINAL PROPERTY {} ", origProp);

    // If this flag is set, skip adding the statement using the generic solution 
    boolean skipGeneric = false;

    if (targetObject.isResource() && targetProp.getURI().equals(NS.EDM.PROP_PROVIDER)) {
        //
        // HACK
        // Hard-code edm:provider to DM2E (Some providers didn't specify a skos:prefLabel here)
        //
        outputModel.add(targetSubject, targetProp, "DM2E");
        skipSet.add(targetObject.asResource());
        skipGeneric = true;
    } else if (origProp.getURI().equals(NS.DM2E_UNVERSIONED.PROP_HOLDING_INSTITUTION)) {
        //
        // https://github.com/DM2E/dm2e-mappings/issues/111#issuecomment-60372863
        //
        Resource res = targetObject.asResource();
        String label = getLiteralString(res, res(NS.SKOS.PROP_PREF_LABEL));
        outputModel.add(targetSubject, outputModel.createProperty(NS.DCTERMS.PROP_PROVENANCE),
                "Current holding institution: " + label);
        skipSet.add(res);
        skipGeneric = true;
    } else if (targetProp.getURI().equals(NS.EDM.PROP_TYPE)) {
        //
        // HACK
        // Hard-code edm:type to "TEXT" (Some providers had the case wrong)
        //
        outputModel.add(targetSubject, targetProp, "TEXT");
        skipGeneric = true;
    } else if (getRdfTypes(targetSubject).contains(res(NS.ORE.CLASS_AGGREGATION))
            && (dm2eSuperProperties.get(res(targetProp.getURI())).contains(res(NS.EDM.PROP_HAS_MET)))) {
        //
        // Don't add any edm:hasMet superproperties to an ore:Aggregation
        //
        if (targetObject.isResource())
            skipSet.add(targetObject.asResource());
        skipGeneric = true;
    } else if (targetObject.isResource()
            && (getRdfTypes(targetObject.asResource()).contains(res(NS.EDM.CLASS_TIMESPAN))
                    || getRdfTypes(targetObject.asResource()).contains(res(NS.EDM.BASE + "timeSpan")))) {
        //
        // Turn one-year timespans into xsd:gYear literals 
        //
        log.debug("{} is a timestamp", targetObject);
        Resource res = targetObject.asResource();
        String begin = getLiteralString(res, res(NS.EDM.PROP_BEGIN));
        String end = getLiteralString(res, res(NS.EDM.PROP_END));
        String timeSpanPrefLabel = getLiteralString(res, res(NS.SKOS.PROP_PREF_LABEL));
        //         if ("true".equals(configProps.getProperty("shortenYear", "true"))) {
        if (null != begin && null != end && begin.length() >= 10 && end.length() >= 10) {
            //            log.debug("TIMESTAMP");
            final String beginYear = begin.substring(0, 4);
            final String endYear = end.substring(0, 4);
            final String beginDM = begin.substring(5, 10);
            final String endDM = end.substring(5, 10);
            if (beginYear.equals(endYear)) {
                // one year timespan
                if (beginDM.equals("01-01") && endDM.equals("12-31")) {
                    //                  log.debug("ONEYEAR TIMESTAMP");
                    outputModel.add(targetSubject, targetProp, outputModel.createLiteral(beginYear));
                    skipSet.add(res);
                    skipGeneric = true;
                    // one day timespan
                } else if (beginDM.equals(endDM)) {
                    //                  log.debug("ONEDAY TIMESTAMP");
                    outputModel.add(targetSubject, targetProp, outputModel.createLiteral(end.substring(0, 10)));
                    skipSet.add(res);
                    skipGeneric = true;
                }
            }
        } else if (null == timeSpanPrefLabel) {
            log.error("Bad Timespan: " + res);
        }
        //         log.error("SKIPPING " + res);
        //         skipGeneric = true;
        //         }
    } else if (targetObject.isLiteral() && (
    //                  (targetObject.asLiteral().getDatatype() !=null &&  targetObject.asLiteral().getDatatypeURI().equals(NS.XSD.DATETIME))
    //                  ||
    targetObject.asLiteral().getLexicalForm().matches("\\d{4}-\\d{2}-\\d{2}.*"))) {
        //
        // xsd:datetime -> xsd:date
        //
        String newVal = targetObject.asLiteral().getLexicalForm().substring(0, "2000-01-01".length());
        //         targetObject = inputModel.createTypedLiteral(newVal, XSDDatatype.XSDdate);
        targetObject = inputModel.createLiteral(newVal);
        outputModel.add(targetSubject, targetProp, targetObject);
        skipGeneric = true;
    } else if (targetObject.isResource() && targetProp.getURI().equals(NS.DC.PROP_TYPE)) {

        // Now add the data about the dc:type class here
        StmtIterator iter = dcTypesModel.listStatements(targetObject.asResource(), null, (RDFNode) null);
        while (iter.hasNext()) {
            outputModel.add(iter.next());
        }

    } else if (targetObject.isResource() && targetProp.getURI().equals(NS.EDM.PROP_DATA_PROVIDER)) {
        //
        // edm:provider and edm:dataProvider -> skos:prefLabel
        //
        Literal prefLabelLiteral = getLiteral(targetObject, inputModel.createProperty(NS.SKOS.PROP_PREF_LABEL));
        if (null == prefLabelLiteral) {
            log.error("No skos:prefLabel for dataProvider <%s>", targetObject);
        } else {
            outputModel.add(targetSubject, targetProp, prefLabelLiteral);
        }
        skipSet.add(targetObject.asResource());
        skipGeneric = true;
    } else if (targetProp.getURI().equals(NS.OWL.SAME_AS)
            && getRdfTypes(targetSubject.asResource()).contains(res(NS.SKOS.CLASS_CONCEPT))) {

        //
        // If prop is owl:sameAs and rdf:type of subject is skos:Concept, replace owl:sameAs with skos:exactMatch
        //
        outputModel.add(targetSubject, outputModel.createProperty(NS.SKOS.PROP_EXACT_MATCH), targetObject);
        skipGeneric = true;
    } /* else if (targetProp.getURI().equals(NS.DCTERMS.PROP_IS_PART_OF) && targetObject.isResource()
      && getRdfTypes(targetSubject.asResource()).contains(res(NS.EDM.CLASS_PROVIDED_CHO))) {
              
       //
       // If prop is dcterms:isPartOf, add the inverse dcterms:hasPart
       //
       outputModel.add(targetObject.asResource(), outputModel.createProperty(NS.DCTERMS.PROP_HAS_PART), targetSubject);
      } */
    else if (targetProp.getURI().equals(NS.SKOS.PROP_PREF_LABEL) && targetObject.isLiteral()) {

        //
        // Make sure that every thing in the output graph has at most 1 skos:prefLabel
        //
        String key = targetSubject.getURI() + targetObject.asLiteral().getLanguage();
        if (skosPrefLabelCache.contains(key)) {
            targetProp = outputModel.createProperty(NS.SKOS.PROP_ALT_LABEL);
        } else {
            skosPrefLabelCache.add(key);
        }
    } else if (targetObject.isResource()
            && inputModel.contains(targetObject.asResource(), inputModel.createProperty(NS.OWL.SAME_AS))) {

        //
        // If object is owl:sameAs as something else and that something else is either a GND or VIAF link:
        // don't link to the object but the the GND or VIAF URI.
        //
        Set<Resource> sameAsSet = new HashSet<>();
        StmtIterator iter = targetObject.asResource().listProperties(inputModel.createProperty(NS.OWL.SAME_AS));
        while (iter.hasNext()) {
            RDFNode o = iter.next().getObject();
            if (o.isResource())
                sameAsSet.add(o.asResource());
        }
        String[] arr = { "gnd", "viaf" };
        SAME_AS_LOOP: for (String krz : arr) {
            for (Resource sameAsRes : sameAsSet) {
                if (sameAsRes.getURI().contains(krz)) {
                    outputModel.add(targetSubject, targetProp, sameAsRes);
                    skipGeneric = true;
                    skipSet.add(targetObject.asResource());
                    //
                    // Also skip all the resources that were being linked to by the obsolete local agent
                    //
                    //                  StmtIterator resIter = inputModel.listStatements(targetObject.asResource(), null, (RDFNode)null);
                    //                  while (resIter.hasNext()) {
                    //                     RDFNode res = resIter.next().getObject();
                    //                     if (res.isResource()) {
                    //                        skipSet.add(res.asResource());
                    //                     }
                    //                  }
                    break SAME_AS_LOOP;
                }
            }
        }

        //
        // Public Domain cutoff date
        //
    } else if (this.publicDomainCutoffDate != null && targetProp.equals(prop(NS.EDM.PROP_RIGHTS))) {

        boolean subjectIsAggregation = getRdfTypes(targetSubject).contains(res(NS.ORE.CLASS_AGGREGATION));
        boolean subjectIsWebResource = getRdfTypes(targetSubject).contains(res(NS.EDM.CLASS_WEBRESOURCE));

        Resource agg = null;
        Resource cho = null;

        if (!subjectIsWebResource && !subjectIsAggregation) {
            log.error("<{}> has edm:rights but is neither aggregation nor webresource", targetSubject);
            throw new RuntimeException();
        } else if (subjectIsAggregation) {
            log.debug("it's an aggregation.");
            agg = targetSubject;
        } else if (subjectIsWebResource) {
            StmtIterator iterAgg = inputModel.listStatements(null, null, targetSubject);
            while (iterAgg.hasNext()) {
                Resource possibleAgg = iterAgg.next().getSubject();
                log.debug("possibleAgg: {}", possibleAgg);
                if (getRdfTypes(possibleAgg).contains(res(NS.ORE.CLASS_AGGREGATION))) {
                    agg = possibleAgg;
                    // TODO find the right aggregation. this is complicated and must probably
                    // be handled with global state. We need to know the right aggregation and
                    // mustn't produce contradicting right statements
                    break;
                }
            }
        }
        StmtIterator iterCHO = agg.asResource().listProperties(prop(NS.EDM.PROP_AGGREGATED_CHO));
        if (iterCHO.hasNext()) {
            cho = iterCHO.next().getObject().asResource();
        }
        if (null == agg || null == cho) {
            log.error("Couldnt find CHO  or Agg for <{}> (CHO: <{}>)", targetSubject, cho);
            throw new RuntimeException();
        }

        // Check properties
        List<Property> publicDomainProperties = new ArrayList<>();
        publicDomainProperties.add(prop(NS.DM2E.PROP_SENT_ON));
        publicDomainProperties.add(prop(NS.DCTERMS.PROP_ISSUED));
        for (Property pdProp : publicDomainProperties) {
            StmtIterator iter = cho.listProperties(pdProp);
            DateTime dateToCheck = null;
            while (iter.hasNext()) {
                dateToCheck = DateTime.parse(iter.next().getObject().toString());
                break;
            }
            if (dateToCheck != null && dateToCheck.isBefore(this.publicDomainCutoffDate)) {
                log.debug(String.format("Public Domain because '%s' on <%s> was before '%s'", dateToCheck,
                        pdProp, this.publicDomainCutoffDate));
                log.info("Changing rights statement of <{}> to Public Domain.", targetSubject);
                skipGeneric = true;
                outputModel.add(targetSubject, targetProp, PUBLIC_DOMAIN_MARK);
                // TODO
                //               if (subjectIsWebResource) {
                //                  log.info("Skipping edm:rights for this Public Domain WebResource <{}>", targetSubject);
                //                  outputModel.add(targetSubject, targetProp, PUBLIC_DOMAIN_MARK);
                //               }
            }
        }
    }

    log.debug("PROP: {}", targetProp.getURI());

    //
    // Generic copying of statements from input to outpu
    //
    if (!skipGeneric) {

        // NOTE: Strip all rdf:datatypes, Europeana cannot handle them :(
        if (targetObject.isLiteral() && targetObject.asLiteral().getDatatype() != null) {
            Literal cleanedLiteral;
            if (targetObject.asLiteral().getLanguage().equals("")) {
                cleanedLiteral = outputModel.createLiteral(targetObject.asLiteral().getLexicalForm());
            } else {
                cleanedLiteral = outputModel.createLiteral(targetObject.asLiteral().getLexicalForm(),
                        targetObject.asLiteral().getLanguage());
            }
            outputModel.add(targetSubject, targetProp, cleanedLiteral);
        } else {
            outputModel.add(targetSubject, targetProp, targetObject);
        }
    }

}

From source file:editors.DateTimeEditor.java

@Override
public void setAsText(String text) {
    DateTime dateTime = DateTime.parse(text);
    setValue(dateTime);
}

From source file:edu.mit.ll.graphulo.pig.backend.AccumuloBinaryConverter.java

License:Apache License

/**
 * NOT IMPLEMENTED//w w  w.  j ava 2s . com
 */
@Override
public DateTime bytesToDateTime(byte[] b) throws IOException {
    String s = new String(b, UTF8);
    return DateTime.parse(s);
}

From source file:eu.esdihumboldt.hale.common.convert.core.StringToJodaDateTimeConverter.java

License:Open Source License

@Override
public DateTime convert(String source) {
    if (source == null || NULL_VALUES.contains(source)) {
        return null;
    }/*ww  w  .  j  a  v a 2  s  .c om*/
    // parse ISO format
    return DateTime.parse(source);
}

From source file:eu.esdihumboldt.hale.common.headless.impl.WorkspaceServiceImpl.java

License:Open Source License

/**
 * @see WorkspaceService#getLeaseEnd(String)
 *///from ww w. ja va 2  s  .c  om
@Override
public DateTime getLeaseEnd(String workspaceId) throws IOException {
    PropertiesFile config = getConfiguration(workspaceId);
    String leaseEnd = config.getProperty(PROPERTY_LEASE_END);
    return DateTime.parse(leaseEnd);
}