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:org.ojbc.bundles.adapters.staticmock.StaticMockQuery.java

License:RPL License

List<IdentifiableDocumentWrapper> incidentSearchDocumentsAsList(Document incidentSearchRequestMessage,
        DateTime baseDate) throws Exception {

    Element rootElement = incidentSearchRequestMessage.getDocumentElement();
    String rootNamespaceURI = rootElement.getNamespaceURI();
    String rootLocalName = rootElement.getLocalName();
    if (!(OjbcNamespaceContext.NS_INCIDENT_SEARCH_REQUEST_DOC.equals(rootNamespaceURI)
            && "IncidentSearchRequest".equals(rootLocalName))) {
        throw new IllegalArgumentException("Invalid message, must have {"
                + OjbcNamespaceContext.NS_INCIDENT_SEARCH_REQUEST_DOC + "}IncidentSearchRequest as the root "
                + "instead of {" + rootNamespaceURI + "}" + rootLocalName);
    }/*from w w w. j  a v  a 2 s .com*/

    NodeList systemElements = XmlUtils.xPathNodeListSearch(rootElement, "isr:SourceSystemNameText");
    if (systemElements == null || systemElements.getLength() == 0) {
        throw new IllegalArgumentException(
                "Invalid query request message:  must specify at least one system to query.");
    }

    List<IdentifiableDocumentWrapper> ret = new ArrayList<IdentifiableDocumentWrapper>();

    String searchXPath = buildIncidentSearchXPathFromIncidentSearchMessage(incidentSearchRequestMessage);

    String dateLowerString = XmlUtils.xPathStringSearch(incidentSearchRequestMessage,
            "/isr-doc:IncidentSearchRequest/isr:Incident/nc:ActivityDateRange/nc:StartDate/nc:DateTime");
    String dateUpperString = XmlUtils.xPathStringSearch(incidentSearchRequestMessage,
            "/isr-doc:IncidentSearchRequest/isr:Incident/nc:ActivityDateRange/nc:EndDate/nc:DateTime");

    LOG.debug("dateLowerString=" + dateLowerString);
    LOG.debug("dateUpperString=" + dateUpperString);

    if (searchXPath == null && isMissing(dateLowerString) && isMissing(dateUpperString)) {
        return ret;
    }

    DateTimeFormatter dateTimeFormatter = ISODateTimeFormat.dateTimeParser();

    for (IdentifiableDocumentWrapper dw : incidentDataSource.getDocuments()) {

        Document d = dw.getDocument();
        LOG.debug("Searching document " + dw.getId());

        boolean match = (searchXPath == null || XmlUtils.xPathNodeSearch(d, searchXPath) != null);
        LOG.debug("Match=" + match + " based on xpath eval");

        if (match && (!(isMissing(dateLowerString) && isMissing(dateUpperString)))) {

            LOG.debug("In date evaluation");

            String incidentStartDateString = XmlUtils.xPathStringSearch(d,
                    "/ir:IncidentReport/lexspd:doPublish/lexs:PublishMessageContainer/lexs:PublishMessage/lexs:DataItemPackage/lexs:Digest/lexsdigest:EntityActivity/nc:Activity[nc:ActivityCategoryText='Incident']/nc:ActivityDateRange/nc:StartDate/nc:DateTime");
            String incidentEndDateString = XmlUtils.xPathStringSearch(d,
                    "/ir:IncidentReport/lexspd:doPublish/lexs:PublishMessageContainer/lexs:PublishMessage/lexs:DataItemPackage/lexs:Digest/lexsdigest:EntityActivity/nc:Activity[nc:ActivityCategoryText='Incident']/nc:ActivityDateRange/nc:EndDate/nc:DateTime");

            if (isMissing(incidentStartDateString) && isMissing(incidentEndDateString)) {
                match = false;
            } else {
                DateTime incidentStartDateTime = null;
                DateTime incidentEndDateTime = null;
                try {
                    incidentStartDateTime = dateTimeFormatter.parseDateTime(incidentStartDateString);
                    incidentEndDateTime = dateTimeFormatter.parseDateTime(incidentEndDateString);
                } catch (Exception e) {
                    e.printStackTrace();
                    LOG.warn("Unable to parse date (either " + incidentStartDateString + " or "
                            + incidentEndDateString
                            + "). Note that null dates are ok...just means it's not part of the incident");
                }
                LOG.debug("incidentStartDateTime=" + incidentStartDateTime);
                LOG.debug("incidentEndDateTime=" + incidentEndDateTime);
                if (incidentStartDateTime == null && incidentEndDateTime == null) {
                    match = false;
                } else {
                    if (!isMissing(dateLowerString)) {
                        DateTime lowerDateTime = dateTimeFormatter.parseDateTime(dateLowerString);
                        if (incidentEndDateTime != null && incidentEndDateTime.isBefore(lowerDateTime)) {
                            match = false;
                        } else if (incidentEndDateTime == null
                                && incidentStartDateTime.isBefore(lowerDateTime)) {
                            match = false;
                        }
                    }
                    if (!isMissing(dateUpperString)) {
                        DateTime upperDateTime = dateTimeFormatter.parseDateTime(dateUpperString);
                        if (incidentStartDateTime != null && incidentStartDateTime.isAfter(upperDateTime)) {
                            match = false;
                        } else if (incidentStartDateTime == null
                                && incidentEndDateTime.isBefore(upperDateTime)) {
                            match = false;
                        }
                    }
                }
            }

        }

        if (match) {
            ret.add(dw);
        }

    }

    return ret;

}

From source file:org.opencastproject.metadata.dublincore.EncodingSchemeUtils.java

License:Educational Community License

/**
 * @throws IllegalArgumentException/*w  w  w  .ja v a2s  .c  o m*/
 *           if the value cannot be parsed
 */
private static Date parseW3CDTF(String value) {
    return ISODateTimeFormat.dateTimeParser().parseDateTime(value).toDate();
}

From source file:org.opencastproject.util.jaxb.UtcDateAdapter.java

License:Educational Community License

@Override
public Date unmarshal(String date) throws Exception {
    return ISODateTimeFormat.dateTimeParser().parseDateTime(date).toDate();
}

From source file:org.openehr.rm.datatypes.quantity.datetime.DvDateTimeParser.java

License:LGPL

public static DateTime parseDateTime(String value) {
    if (value == null) {
        throw new IllegalArgumentException("null value for datetime");
    }/*from   w  w  w.j  a  va 2s .  c o m*/
    if (!value.matches(EXT_DATETIME) && !value.matches(BDATETIME)) {
        throw new IllegalArgumentException("invalid pattern for datetime: " + value);
    }
    DateTime dt = null;
    if (value.indexOf("-") > 0) {
        try {
            dt = ISODateTimeFormat.dateTimeParser().withOffsetParsed().parseDateTime(value);
        } catch (Exception e) {
            throw new IllegalArgumentException("invalid value for datetime: " + value);
        }
    } else {
        value = value.replace(".", ",");
        int tEleSize = analyseTimeString(value.substring(9));
        String pattern = "";
        switch (tEleSize) {
        case 1:
            pattern = "yyyyMMdd'T'HH";
            break;
        case 2:
            pattern = "yyyyMMdd'T'HHmm";
            break;
        case 3:
            pattern = "yyyyMMdd'T'HHmmss";
            break;
        case 4:
            pattern = "yyyyMMdd'T'HHmmss,SSSSSSSSS";
            break;
        }
        if (tZonePresent(value) > 0) {
            pattern = pattern + "Z";
        }
        dt = DateTimeFormat.forPattern(pattern).withOffsetParsed().parseDateTime(value);
    }
    return dt;
}

From source file:org.opennms.newts.stress.TimestampOptionHandler.java

License:Apache License

@Override
protected Timestamp parse(String argument) throws NumberFormatException, CmdLineException {
    DateTimeFormatter parser = ISODateTimeFormat.dateTimeParser();
    DateTime dateTime = parser.parseDateTime(argument);
    return Timestamp.fromEpochMillis(dateTime.getMillis());
}

From source file:org.opentestsystem.delivery.testadmin.domain.TZBasedDateTimeDeserialier.java

License:Open Source License

@Override
public DateTime deserialize(JsonParser jp, DeserializationContext ctxt)
        throws IOException, JsonProcessingException {
    String stringValue = jp.getText().trim();
    if (stringValue == null || stringValue.trim().isEmpty())
        return null;
    return ISODateTimeFormat.dateTimeParser().parseDateTime(stringValue);
}

From source file:org.opentestsystem.delivery.testreg.domain.search.AssessmentSearchRequest.java

License:Open Source License

private static String getDateTime(String dateTime) {
    return ISODateTimeFormat.dateTimeParser().parseLocalDate(dateTime).toDateTimeAtStartOfDay().toString();
}

From source file:org.osiam.resources.helper.SingularFilterChain.java

License:Apache License

private Object tryToGetDate(String result) {
    DateTime time = ISODateTimeFormat.dateTimeParser().parseDateTime(result);
    return time.toDate();
}

From source file:org.ow2.proactive.scheduler.common.util.ISO8601DateUtil.java

License:Open Source License

private static final Date parseWithISO8601Time(String dateString) {
    return ISODateTimeFormat.dateTimeParser().parseDateTime(dateString).toDate();

}

From source file:org.sweble.wom3.impl.Toolbox.java

License:Open Source License

public static DateTime stringToDateTime(String datetime) {
    DateTimeFormatter parser = ISODateTimeFormat.dateTimeParser();
    return parser.parseDateTime(datetime);
}