@Override public ZonedDateTime createdAt() { return ZonedDateTime.parse("2018-03-23T15:00:00Z"); }
@Override public ZonedDateTime createdAt() { return ZonedDateTime.parse("2017-01-10T15:01:00Z"); }
@Override public ZonedDateTime createdAt() { return ZonedDateTime.parse("2016-11-16T17:21:00Z"); }
@Override public ZonedDateTime createdAt() { return ZonedDateTime.parse("2016-11-16T17:22:00Z"); }
@Override public ZonedDateTime createdAt() { return ZonedDateTime.parse("2016-12-15T16:39:00Z"); }
@Override public ZonedDateTime createdAt() { return ZonedDateTime.parse("2016-11-30T14:15:00Z"); }
@Override public ZonedDateTime createdAt() { return ZonedDateTime.parse("2018-09-24T11:16:44Z"); }
@Override public ZonedDateTime createdAt() { return ZonedDateTime.parse("2018-02-12T16:50:00Z"); }
@Override public ZonedDateTime createdAt() { return ZonedDateTime.parse("2018-06-01T15:15:00Z"); }
@Override public ZonedDateTime createdAt() { return ZonedDateTime.parse("2016-11-22T17:45:00Z"); }
@Override public ZonedDateTime createdAt() { return ZonedDateTime.parse("2016-11-25T14:24:00Z"); }
@Override public ZonedDateTime createdAt() { return ZonedDateTime.parse("2016-11-24T10:47:00Z"); }
@Override protected ZonedDateTime parse(@Nullable final String input) throws Exception { return ZonedDateTime.parse(input); } }
@Override protected ZonedDateTime deserialize(String key, DeserializationContext ctxt) throws IOException { // not serializing timezone data yet try { return ZonedDateTime.parse(key, DateTimeFormatter.ISO_OFFSET_DATE_TIME); } catch (DateTimeException e) { return _handleDateTimeException(ctxt, ZonedDateTime.class, e, key); } } }
/** * Obtains an instance of {@link ZonedDateTime} from a string representation in ISO date format. * Note that the {@link ZonedDateTime} created from the given String is built in the {@link java.time.ZoneId} of the * actual {@link ZonedDateTime}. * @param dateTimeAsString the string to parse * @return the parsed {@link ZonedDateTime} */ @Override protected ZonedDateTime parse(String dateTimeAsString) { ZonedDateTime zonedDateTime = ZonedDateTime.parse(dateTimeAsString, DateTimeFormatter.ISO_DATE_TIME); return sameInstantInActualTimeZone(zonedDateTime); }
@Override public TemporalAccessor parse(String text, Locale locale) throws ParseException { DateTimeFormatter formatterToUse = DateTimeContextHolder.getFormatter(this.formatter, locale); if (LocalDate.class == this.temporalAccessorType) { return LocalDate.parse(text, formatterToUse); } else if (LocalTime.class == this.temporalAccessorType) { return LocalTime.parse(text, formatterToUse); } else if (LocalDateTime.class == this.temporalAccessorType) { return LocalDateTime.parse(text, formatterToUse); } else if (ZonedDateTime.class == this.temporalAccessorType) { return ZonedDateTime.parse(text, formatterToUse); } else if (OffsetDateTime.class == this.temporalAccessorType) { return OffsetDateTime.parse(text, formatterToUse); } else if (OffsetTime.class == this.temporalAccessorType) { return OffsetTime.parse(text, formatterToUse); } else { throw new IllegalStateException("Unsupported TemporalAccessor type: " + this.temporalAccessorType); } }
@Test public void parseDates() { ContentDisposition disposition = ContentDisposition .parse("attachment; creation-date=\"Mon, 12 Feb 2007 10:15:30 -0500\"; " + "modification-date=\"Tue, 13 Feb 2007 10:15:30 -0500\"; " + "read-date=\"Wed, 14 Feb 2007 10:15:30 -0500\""); DateTimeFormatter formatter = DateTimeFormatter.RFC_1123_DATE_TIME; assertEquals(ContentDisposition.builder("attachment") .creationDate(ZonedDateTime.parse("Mon, 12 Feb 2007 10:15:30 -0500", formatter)) .modificationDate(ZonedDateTime.parse("Tue, 13 Feb 2007 10:15:30 -0500", formatter)) .readDate(ZonedDateTime.parse("Wed, 14 Feb 2007 10:15:30 -0500", formatter)).build(), disposition); }
@Test public void checkModifiedTimestampWithLengthPart() { long epochTime = ZonedDateTime.parse(CURRENT_TIME, RFC_1123_DATE_TIME).toInstant().toEpochMilli(); servletRequest.setMethod("GET"); servletRequest.addHeader("If-Modified-Since", "Wed, 08 Apr 2014 09:57:42 GMT; length=13774"); assertFalse(request.checkNotModified(epochTime)); assertEquals(200, servletResponse.getStatus()); assertEquals(epochTime / 1000, servletResponse.getDateHeader("Last-Modified") / 1000); }
@Test public void checkNotModifiedTimestampWithLengthPart() { long epochTime = ZonedDateTime.parse(CURRENT_TIME, RFC_1123_DATE_TIME).toInstant().toEpochMilli(); servletRequest.setMethod("GET"); servletRequest.addHeader("If-Modified-Since", "Wed, 09 Apr 2014 09:57:42 GMT; length=13774"); assertTrue(request.checkNotModified(epochTime)); assertEquals(304, servletResponse.getStatus()); assertEquals(epochTime / 1000, servletResponse.getDateHeader("Last-Modified") / 1000); }
@Test public void parseInvalidDates() { ContentDisposition disposition = ContentDisposition .parse("attachment; creation-date=\"-1\"; modification-date=\"-1\"; " + "read-date=\"Wed, 14 Feb 2007 10:15:30 -0500\""); DateTimeFormatter formatter = DateTimeFormatter.RFC_1123_DATE_TIME; assertEquals(ContentDisposition.builder("attachment") .readDate(ZonedDateTime.parse("Wed, 14 Feb 2007 10:15:30 -0500", formatter)).build(), disposition); }