Java Code Examples for com.fasterxml.jackson.databind.util.ISO8601Utils#parse()

The following examples show how to use com.fasterxml.jackson.databind.util.ISO8601Utils#parse() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ParamConverters.java    From ameba with MIT License 6 votes vote down vote up
/**
 * <p>parseDate.</p>
 *
 * @param value a {@link java.lang.String} object.
 * @param pos   a {@link java.text.ParsePosition} object.
 * @return a {@link java.util.Date} object.
 */
public static Date parseDate(String value, ParsePosition pos) {
    Long timestamp = parseTimestamp(value);
    if (timestamp != null) {
        return new Date(timestamp);
    }
    if (value.contains(" ")) {
        value = value.replace(" ", "+");
    }
    if (!(value.contains("-") || value.contains("+")) && !value.endsWith("Z")) {
        value += SYS_TZ;
    }
    try {
        return ISO8601Utils.parse(value, pos);
    } catch (ParseException e) {
        throw new ExtractorException(e);
    }
}
 
Example 2
Source File: DynamoDBSolWorker.java    From aws-dynamodb-mars-json-demo with Apache License 2.0 6 votes vote down vote up
/**
 * <p>
 * Parses the ISO-8601 date from the image JSON.
 * </p>
 * <p>
 * Handles the bug in the NASA JSON where not all timestamps comply with ISO-8601 (some are missing the 'Z' for UTC
 * time at the end of the timestamp).
 * </p>
 * Uses Jackson ISO8601Utils to convert the timestamp.
 *
 * @param image
 *            JSON representation of the image
 * @return Java Date object containing the creation time stamp
 */
protected static Date getTimestamp(final JsonNode image) {
    Date date = null;
    String iso8601 = image.get(IMAGE_TIME_KEY).get(CREATION_TIME_STAMP_KEY).asText();
    try {
        date = ISO8601Utils.parse(iso8601);
    } catch (final IllegalArgumentException e) {
        // Don't like this, but not all times have the Z at the end for
        // ISO-8601
        if (iso8601.charAt(iso8601.length() - 1) != 'Z') {
            iso8601 = iso8601 + "Z";
            date = ISO8601Utils.parse(iso8601);
        } else {
            throw e;
        }
    }
    return date;
}
 
Example 3
Source File: AbstractTaskQueryResource.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
private void handleDueBefore(TaskInfoQueryWrapper taskInfoQueryWrapper, JsonNode dueBeforeNode) {
  String date = dueBeforeNode.asText();
  Date d = null;
  try {
    d = ISO8601Utils.parse(date, new ParsePosition(0));
  } catch (ParseException e) {
    e.printStackTrace();
  }
  taskInfoQueryWrapper.getTaskInfoQuery().taskDueBefore(d);
}
 
Example 4
Source File: AbstractTaskQueryResource.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
private void handleDueAfter(TaskInfoQueryWrapper taskInfoQueryWrapper, JsonNode dueAfterNode) {
  String date = dueAfterNode.asText();
  Date d = null;
  try {
    d = ISO8601Utils.parse(date, new ParsePosition(0));
  } catch (ParseException e) {
    e.printStackTrace();
  }
  taskInfoQueryWrapper.getTaskInfoQuery().taskDueAfter(d);
}
 
Example 5
Source File: JsonHelper.java    From emodb with Apache License 2.0 5 votes vote down vote up
/** Parses an ISO 8601 date+time string into a Java Date object. */
public static Date parseTimestamp(@Nullable String string) {
    Date date = null;
    try {
        if (string != null) {
            date = ISO8601Utils.parse(string, new ParsePosition(0));
        }
    } catch (ParseException e) {
        throw Throwables.propagate(e);
    }
    return date;
}
 
Example 6
Source File: AsyncHistoryDateUtil.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
public static Date parseDate(String s) {
    if (s != null) {
        try {
            return ISO8601Utils.parse(s, new ParsePosition(0));
        } catch (ParseException e) {
            return null;
        }
    }
    return null;
}
 
Example 7
Source File: JdbcMetricsTest.java    From apiman with Apache License 2.0 5 votes vote down vote up
/**
 * @throws ParseException 
 */
private RequestMetric request(String requestStart, long requestDuration, String url, String resource,
        String method, String apiOrgId, String apiId, String apiVersion, String planId,
        String clientOrgId, String clientId, String clientVersion, String contractId, String user,
        int responseCode, String responseMessage, boolean failure, int failureCode, String failureReason,
        boolean error, String errorMessage, long bytesUploaded, long bytesDownloaded) throws ParseException {
    Date start = ISO8601Utils.parse(requestStart, new ParsePosition(0));
    RequestMetric rval = new RequestMetric();
    rval.setRequestStart(start);
    rval.setRequestEnd(new Date(start.getTime() + requestDuration));
    rval.setApiStart(start);
    rval.setApiEnd(rval.getRequestEnd());
    rval.setApiDuration(requestDuration);
    rval.setUrl(url);
    rval.setResource(resource);
    rval.setMethod(method);
    rval.setApiOrgId(apiOrgId);
    rval.setApiId(apiId);
    rval.setApiVersion(apiVersion);
    rval.setPlanId(planId);
    rval.setClientOrgId(clientOrgId);
    rval.setClientId(clientId);
    rval.setClientVersion(clientVersion);
    rval.setContractId(contractId);
    rval.setUser(user);
    rval.setResponseCode(responseCode);
    rval.setResponseMessage(responseMessage);
    rval.setFailure(failure);
    rval.setFailureCode(failureCode);
    rval.setFailureReason(failureReason);
    rval.setError(error);
    rval.setErrorMessage(errorMessage);
    rval.setBytesUploaded(bytesUploaded);
    rval.setBytesDownloaded(bytesDownloaded);
    return rval;
}