@Override public final Date convert(final String o) { return DateUtils.parseISO8601Date(o); } };
public static Date parseIso8601Date(String dateString) { return DateUtils.parseISO8601Date(dateString); }
/** * The date and time this object's Object Lock will expire. */ public Date getObjectLockRetainUntilDate() { String dateStr = (String) metadata.get(Headers.OBJECT_LOCK_RETAIN_UNTIL_DATE); if (dateStr != null) { return DateUtils.parseISO8601Date(dateStr); } return null; }
@Override public Object unmarshall(AttributeValue value) { Set<Calendar> result = new HashSet<Calendar>(); for (String s : value.getSS()) { Calendar cal = GregorianCalendar.getInstance(); cal.setTime(DateUtils.parseISO8601Date(s)); result.add(cal); } return result; } }
@Override public Object unmarshall(AttributeValue value) { Calendar cal = GregorianCalendar.getInstance(); cal.setTime(DateUtils.parseISO8601Date(value.getS())); return cal; } }
/** * Gets a ISO8601 date value from the JSON. * * @param fieldName Name of field to get. * @return Date object or null if not present. */ private Date getIso8601Date(String fieldName) { String dateString = getString(fieldName); return dateString != null ? DateUtils.parseISO8601Date(dateString) : null; }
public Date unmarshall(StaxUnmarshallerContext unmarshallerContext) throws Exception { String dateString = unmarshallerContext.readText(); if (dateString == null) return null; try { return DateUtils.parseISO8601Date(dateString); } catch (Exception e) { log.warn("Unable to parse date '" + dateString + "': " + e.getMessage(), e); return null; } }
@Override public Object unmarshall(AttributeValue value) { Set<Date> result = new HashSet<Date>(); for (String s : value.getSS()) { result.add(DateUtils.parseISO8601Date(s)); } return result; } }
@Override public Object unmarshall(AttributeValue value) { return DateUtils.parseISO8601Date(value.getS()); } }
private static boolean checkParseIso8601DateUsingAlternativeFormat() throws ParseException { Date date = new Date(); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"); sdf.setTimeZone(new SimpleTimeZone(0, "GMT")); String formatted = sdf.format(date); String alternative = DateUtils.alternateIso8601DateFormat.print(date .getTime()); if (formatted.equals(alternative)) { Date expectedDate = sdf.parse(formatted); Date actualDate = DateUtils.parseISO8601Date(formatted); return expectedDate.equals(actualDate); } return false; }
/** * Same as {@link #asDate(String, Node)} but allows an xpath to be passed * in explicitly for reuse. */ public static Date asDate(String expression, Node node, XPath xpath) throws XPathExpressionException { String dateString = evaluateAsString(expression, node, xpath); if (isEmptyString(dateString)) return null; try { return DateUtils.parseISO8601Date(dateString); } catch (Exception e) { log.warn("Unable to parse date '" + dateString + "': " + e.getMessage(), e); return null; } }
/** * Parse the process output to retrieve the expiration date and time. The result includes any configured expiration buffer. */ private DateTime credentialExpirationTime(JsonNode credentialsJson) { String expiration = getText(credentialsJson, "Expiration"); if (expiration != null) { DateTime credentialExpiration = new DateTime(DateUtils.parseISO8601Date(expiration)); credentialExpiration = credentialExpiration.minus(expirationBufferUnit.toMillis(expirationBufferValue)); return credentialExpiration; } else { return DateTime.now().plusYears(9999); } }
@Override public Date unmarshall(StaxUnmarshallerContext unmarshallerContext) throws Exception { String dateString = unmarshallerContext.readText(); if (dateString == null) return null; try { if (TimestampFormat.RFC_822.getFormat().equals(dateFormatType)) { return DateUtils.parseRFC822Date(dateString); } if (TimestampFormat.UNIX_TIMESTAMP.getFormat().equals(dateFormatType)) { return DateUtils.parseServiceSpecificDate(dateString); } return DateUtils.parseISO8601Date(dateString); } catch (Exception e) { log.warn("Unable to parse date '" + dateString + "': " + e.getMessage(), e); return null; } }
public Date unmarshall(JsonUnmarshallerContext unmarshallerContext) throws Exception { // If value is string, assume ISO8601. Otherwise parse as epoch seconds. if (unmarshallerContext.getCurrentToken() == JsonToken.VALUE_STRING) { return DateUtils.parseISO8601Date(unmarshallerContext.readText()); } else { return DateUtils.parseServiceSpecificDate(unmarshallerContext.readText()); } }
credentialsExpiration = DateUtils.parseISO8601Date(expiration); } catch(Exception ex) { handleError("Unable to parse credentials expiration date from Amazon EC2 instance", ex);
@Override protected void doEndElement(String uri, String name, String qName) { if (in("ListAllMyBucketsResult", "Owner")) { if (name.equals("ID")) { bucketsOwner.setId(getText()); } else if (name.equals("DisplayName")) { bucketsOwner.setDisplayName(getText()); } } else if (in("ListAllMyBucketsResult", "Buckets")) { if (name.equals("Bucket")) { buckets.add(currentBucket); currentBucket = null; } } else if (in("ListAllMyBucketsResult", "Buckets", "Bucket")) { if (name.equals("Name")) { currentBucket.setName(getText()); } else if (name.equals("CreationDate")) { Date creationDate = DateUtils.parseISO8601Date(getText()); currentBucket.setCreationDate(creationDate); } } } }
@Override public Date unmarshall(JsonUnmarshallerContext unmarshallerContext) throws Exception { String dateString = unmarshallerContext.readText(); if (dateString == null) { return null; } try { if (TimestampFormat.RFC_822.getFormat().equals(dateFormatType)) { return DateUtils.parseRFC822Date(dateString); } if (TimestampFormat.UNIX_TIMESTAMP.getFormat().equals(dateFormatType)) { return DateUtils.parseServiceSpecificDate(dateString); } if (TimestampFormat.UNIX_TIMESTAMP_IN_MILLIS.getFormat().equals(dateFormatType)) { return DateUtils.parseUnixTimestampInMillis(dateString); } return DateUtils.parseISO8601Date(dateString); } catch (Exception exception) { // fallback to the original behavior. return DateJsonUnmarshaller.getInstance().unmarshall(unmarshallerContext); } }
@Override public Object unmarshall(AttributeValue value) { final Set<Date> result = new HashSet<Date>(); for (final String s : value.getSS()) { result.add(DateUtils.parseISO8601Date(s)); } return result; } }
@Override public Date unmarshall(StaxUnmarshallerContext unmarshallerContext) throws Exception { String dateString = unmarshallerContext.readText(); if (dateString == null) return null; try { return DateUtils.parseISO8601Date(dateString); } catch (Exception e) { log.warn("Unable to parse date '" + dateString + "': " + e.getMessage(), e); return null; } }
@Test public void testAlternativeIso8601Date() throws ParseException { Date date = new Date(); String formatted = alternateIso8601DateFormat.print(date.getTime()); Date expectedDate = new Date(alternateIso8601DateFormat.parseMillis(formatted)); Date actualDate = DateUtils.parseISO8601Date(formatted); assertEquals(expectedDate, actualDate); }