Refine search
@Override public AttributeValue marshall(Object obj) { return new AttributeValue().withS( DateUtils.formatISO8601Date(((Calendar) obj).getTime())); } }
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; }
public static String fromDate(Date date, String timestampFormat) { if ("unixTimestamp".equalsIgnoreCase(timestampFormat)) { return DateUtils.formatServiceSpecificDate(date); } if ("iso8601".equalsIgnoreCase(timestampFormat)) { return DateUtils.formatISO8601Date(date); } if ("rfc822".equalsIgnoreCase(timestampFormat)) { return DateUtils.formatRFC822Date(date); } if ("unixTimestampInMillis".equalsIgnoreCase(timestampFormat)) { return DateUtils.formatUnixTimestampInMills(date); } throw new IllegalArgumentException("unsupported timestamp format"); }
@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()); } }
int parseClockSkewOffset(HttpResponse response, AmazonServiceException exception) { final Date deviceDate = new Date(); Date serverDate = null; String serverDateStr = null; final String responseDateHeader = response.getHeaders().get("Date"); try { if (responseDateHeader == null || responseDateHeader.isEmpty()) { // SQS doesn't return Date header serverDateStr = getServerDateFromException(exception.getMessage()); serverDate = DateUtils.parseCompressedISO8601Date(serverDateStr); } else { serverDateStr = responseDateHeader; serverDate = DateUtils.parseRFC822Date(serverDateStr); } } catch (final RuntimeException e) { log.warn("Unable to parse clock skew offset from response: " + serverDateStr, e); return 0; } final long diff = deviceDate.getTime() - serverDate.getTime(); return (int) (diff / TIME_MILLISEC); }
/** * Given the input epoch time returns a String of the proper format for the * short date in SigV4 parameters. * @param dateMilli desired date in milliseconds since epoch, UTC. * @return date formatted string in short date format. */ private String getDateStamp(long dateMilli) { return DateUtils.format(DATE_PATTERN, new Date(dateMilli)); }
@Test public void testIso8601Date() { Date date = new Date(); String expected = iso8601DateFormat.print(date.getTime()); String actual = DateUtils.formatISO8601Date(date); assertEquals(expected, actual); Date expectedDate = new Date(iso8601DateFormat.parseMillis(expected)); Date actualDate = DateUtils.parseISO8601Date(actual); assertEquals(expectedDate, actualDate); }
@Test public void testCompressedIso8601Date() throws ParseException { Date date = new Date(); String formatted = compressedIso8601DateFormat.print(date.getTime()); Date expected = new Date(compressedIso8601DateFormat.parseMillis(formatted)); Date actual = DateUtils.parseCompressedISO8601Date(formatted); assertEquals(expected, actual); }
@Ignore("Joda has issue handling format string 'z'") @Test public void testRfc822Date() { Date date = new Date(); String expected = rfc822DateFormat.print(date.getTime()); String actual = DateUtils.formatRFC822Date(date); assertEquals(expected, actual); Date expectedDate = new Date(rfc822DateFormat.parseMillis(expected)); Date actualDate = DateUtils.parseRFC822Date(actual); assertEquals(expectedDate, actualDate); }
@Test public void testDateStaxUnmarshaller() throws Exception { Date data = new Date(1000); SimpleTypeStaxUnmarshallers.DateStaxUnmarshaller unmarshaller = SimpleTypeStaxUnmarshallers.DateStaxUnmarshaller .getInstance(); Date unmarshalled = unmarshaller.unmarshall(getContext(DateUtils.formatISO8601Date(data))); assertEquals(unmarshalled.getTime(), data.getTime()); }
JsonNode token; try { lastInstanceProfileCheck = new Date(); credentialsExpiration = DateUtils.parseISO8601Date(expiration); } catch(Exception ex) { handleError("Unable to parse credentials expiration date from Amazon EC2 instance", ex);
@Test public void testIssue233JodaTimeLimit() throws ParseException { // https://github.com/aws/aws-sdk-java/issues/233 String s = DateUtils.formatISO8601Date(new Date(Long.MAX_VALUE)); System.out.println("s: " + s); Date date = DateUtils.parseISO8601Date(s); System.out.println("date: " + date); }
return 0; serverDate = DateUtils.parseCompressedISO8601Date(serverDateStr); } else { serverDateStr = responseDateHeader[0].getValue(); serverDate = DateUtils.parseRFC822Date(serverDateStr); long diff = currentTimeMilli - serverDate.getTime(); return (int) (diff / 1000);
@Test public void testIssueDaysDiff() throws ParseException { // https://github.com/aws/aws-sdk-java/issues/233 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"); sdf.setTimeZone(new SimpleTimeZone(0, "GMT")); String edgeCase = "292278994-08-17T07:12:55.807Z"; String testCase = "292278993-08-17T07:12:55.807Z"; Date od = DateUtils.parseISO8601Date(edgeCase); Date testd = DateUtils.parseISO8601Date(testCase); long diff = od.getTime() - testd.getTime(); assertTrue(diff == 365L * 24 * 60 * 60 * 1000); }
@Override public Object unmarshall(AttributeValue value) { final Calendar cal = Calendar.getInstance(); cal.setTime(DateUtils.parseISO8601Date(value.getS())); return cal; } }
@Override public Object unmarshall(AttributeValue value) { final Set<Calendar> result = new HashSet<Calendar>(); for (final String s : value.getSS()) { final Calendar cal = Calendar.getInstance(); cal.setTime(DateUtils.parseISO8601Date(s)); result.add(cal); } return result; } }
@Override public AttributeValue marshall(Object obj) { @SuppressWarnings("unchecked") Set<Calendar> dates = (Set<Calendar>) obj; List<String> timestamps = new ArrayList<String>(dates.size()); for (Calendar date : dates) { timestamps.add(DateUtils.formatISO8601Date(date.getTime())); } return new AttributeValue().withSS(timestamps); } }
@Override public Object unmarshall(AttributeValue value) { Calendar cal = GregorianCalendar.getInstance(); cal.setTime(DateUtils.parseISO8601Date(value.getS())); return cal; } }
@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; } }