/** * Returns the current value of {@link XMLStreamReader#getElementText()} as a temporal object, * or {@code null} if that value is null or empty. * * @return the current text element as a temporal object, or {@code null} if empty. * @throws XMLStreamException if a text element can not be returned. * @throws DateTimeParseException if the text can not be parsed as a date. */ protected final Temporal getElementAsTemporal() throws XMLStreamException { return StandardDateFormat.parseBest(getElementText()); }
/** * Tests parsing a temporal object. * * @since 0.8 */ @Test public void testParseBest() { final long day = 1466985600000L; assertEquals(Instant.ofEpochMilli(day + ((16*60 + 48)*60 )*1000), StandardDateFormat.parseBest("2016-06-27T16:48Z")); assertEquals(Instant.ofEpochMilli(day + ((16*60 + 48)*60 + 12)*1000), StandardDateFormat.parseBest("2016-06-27T16:48:12Z")); assertEquals(Instant.ofEpochMilli(day + (( 3*60 + 2)*60 + 1)*1000 + 90), StandardDateFormat.parseBest("2016-06-27T03:02:01.09Z")); assertEquals(LocalDateTime.of(2016, 6, 27, 16, 48, 12), StandardDateFormat.parseBest("2016-06-27T16:48:12")); assertEquals(LocalDateTime.of(2016, 6, 27, 16, 48), StandardDateFormat.parseBest("2016-06-27T16:48")); assertEquals(LocalDateTime.of(2016, 6, 27, 16, 48), StandardDateFormat.parseBest("2016-06-27 16:48")); assertEquals(LocalDate.of(2016, 6, 27), StandardDateFormat.parseBest("2016-06-27")); }