diff --git a/src/main/java/emissary/output/DropOffUtil.java b/src/main/java/emissary/output/DropOffUtil.java index 5fe1222272..41d38d88b2 100755 --- a/src/main/java/emissary/output/DropOffUtil.java +++ b/src/main/java/emissary/output/DropOffUtil.java @@ -4,6 +4,7 @@ import emissary.config.Configurator; import emissary.core.Family; import emissary.core.IBaseDataObject; +import emissary.util.FlexibleDateTimeParser; import emissary.util.ShortNameComparator; import emissary.util.TimeUtil; import emissary.util.shell.Executrix; @@ -22,6 +23,7 @@ import java.security.SecureRandom; import java.text.SimpleDateFormat; import java.time.Instant; +import java.time.ZonedDateTime; import java.time.format.DateTimeParseException; import java.util.ArrayList; import java.util.Collection; @@ -42,6 +44,7 @@ import static emissary.core.constants.Parameters.FILEXT; import static emissary.core.constants.Parameters.FILE_ABSOLUTEPATH; import static emissary.core.constants.Parameters.ORIGINAL_FILENAME; +import static emissary.util.TimeUtil.DATE_ISO_8601; public class DropOffUtil { protected static final Logger logger = LoggerFactory.getLogger(DropOffUtil.class); @@ -886,8 +889,12 @@ public Date extractEventDateFrom(final IBaseDataObject d, final boolean lastReso final String value = d.getStringParameter(paramName); if (value != null) { try { - date = TimeUtil.getDateFromISO8601(value); - return date; + ZonedDateTime zdt = FlexibleDateTimeParser.parse(value, DATE_ISO_8601); + if (zdt == null) { + logger.debug("FlexibleDateTimeParser returned null trying to parse EventDate"); + } else { + return Date.from(zdt.toInstant()); + } } catch (DateTimeParseException ex) { logger.debug("Cannot parse EventDate", ex); } diff --git a/src/main/java/emissary/util/TimeUtil.java b/src/main/java/emissary/util/TimeUtil.java index 72aa2ff7a3..54e7281292 100755 --- a/src/main/java/emissary/util/TimeUtil.java +++ b/src/main/java/emissary/util/TimeUtil.java @@ -14,7 +14,6 @@ import java.time.temporal.ChronoUnit; import java.time.temporal.TemporalAccessor; import java.time.zone.ZoneRulesException; -import java.util.Date; import java.util.regex.Matcher; import java.util.regex.Pattern; import javax.annotation.Nullable; @@ -22,11 +21,11 @@ public class TimeUtil { private static final ZoneId GMT = ZoneId.of("GMT"); - private static final DateTimeFormatter DATE_WITH_SLASHES = DateTimeFormatter.ofPattern("yyyy-MM-dd/HH/mm").withZone(GMT); - private static final DateTimeFormatter DATE_ISO_8601 = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss").withZone(GMT); - private static final DateTimeFormatter DATE_FULL_ISO_8601 = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ssX").withZone(GMT); - private static final DateTimeFormatter DATE_ORDINAL = DateTimeFormatter.ofPattern("yyyyDDD").withZone(GMT); - private static final DateTimeFormatter DATE_ISO_8601_SSS = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS"); + public static final DateTimeFormatter DATE_WITH_SLASHES = DateTimeFormatter.ofPattern("yyyy-MM-dd/HH/mm").withZone(GMT); + public static final DateTimeFormatter DATE_ISO_8601 = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss").withZone(GMT); + public static final DateTimeFormatter DATE_FULL_ISO_8601 = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ssX").withZone(GMT); + public static final DateTimeFormatter DATE_ORDINAL = DateTimeFormatter.ofPattern("yyyyDDD").withZone(GMT); + public static final DateTimeFormatter DATE_ISO_8601_SSS = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS"); private static final String ISO_8601_TIME_DATE_STRING = "yyyy-MM-dd'T'HH:mm:ss'Z'"; private static final String HEX_REGEX = "^0x([0-9A-Fa-f]{8})([0-9A-Fa-f]{8})"; private static final Pattern HEX_DATE_PATTERN = Pattern.compile(HEX_REGEX); @@ -92,16 +91,6 @@ public static String getCurrentDate() { return getDateAsPath(ZonedDateTime.now(GMT)); } - /** - * Get specified date/time as a slash separated path component - * - * @deprecated replaced by {@link #getDateAsPath(TemporalAccessor)} - */ - @Deprecated - public static String getDateAsPath(final Date date) { - return getDateAsPath(date.toInstant()); - } - /** * Get specified date/time as a slash separated path component (yyyy-MM-dd/HH/mm) * @@ -127,16 +116,6 @@ public static String getCurrentDateOrdinal() { return getDateOrdinal(ZonedDateTime.now(GMT)); } - /** - * Get current date as yyyyjjj - * - * @deprecated replaced by {@link #getDateOrdinal(TemporalAccessor)} - */ - @Deprecated - public static String getDateOrdinal(@Nullable Date date) { - return date == null ? null : getDateOrdinal(date.toInstant()); - } - /** * Get current date as yyyyjjj * @@ -168,16 +147,6 @@ public static String getDateAsISO8601(final long time) { return getDateAsISO8601(ZonedDateTime.ofInstant(Instant.ofEpochMilli(time), GMT)); } - /** - * Get specified date object as ISO-8601 string - * - * @deprecated replaced by {@link #getDateAsISO8601(TemporalAccessor)} - */ - @Deprecated - public static String getDateAsISO8601(@Nullable final Date date) { - return date == null ? null : getDateAsISO8601(date.toInstant()); - } - /** * Get specified date object as ISO-8601 string (yyyy-MM-dd HH:mm:ss) * @@ -199,16 +168,6 @@ public static String getCurrentDateFullISO8601() { return getDateAsFullISO8601(ZonedDateTime.now(GMT)); } - /** - * Get specified date object as a full ISO-8601 string yyyy-MM-dd'T'HH:mm:ss'Z' - * - * @deprecated replaced by {@link #getDateAsFullISO8601(TemporalAccessor)} - */ - @Deprecated - public static String getDateAsFullISO8601(@Nullable final Date date) { - return date == null ? null : getDateAsFullISO8601(date.toInstant()); - } - /** * Get specified date object as a full ISO-8601 string (yyyy-MM-dd'T'HH:mm:ss'Z') * @@ -220,16 +179,6 @@ public static String getDateAsFullISO8601(@Nullable final TemporalAccessor date) return date == null ? null : DATE_FULL_ISO_8601.format(date); } - /** - * Get Date object from ISO-8601 formatted string - * - * @deprecated replaced by {@link FlexibleDateTimeParser#parse(String)} - */ - @Deprecated - public static Date getDateFromISO8601(@Nullable final String dateString) throws DateTimeParseException { - return dateString == null ? null : Date.from(getZonedDateFromISO8601(dateString).toInstant()); - } - /** * Get Date object from ISO-8601 formatted string ("yyyy-MM-dd HH:mm:ss") * diff --git a/src/test/java/emissary/util/TimeUtilTest.java b/src/test/java/emissary/util/TimeUtilTest.java index 4eb2017e07..3048ee8235 100644 --- a/src/test/java/emissary/util/TimeUtilTest.java +++ b/src/test/java/emissary/util/TimeUtilTest.java @@ -9,7 +9,6 @@ import java.time.ZoneId; import java.time.ZoneOffset; import java.time.ZonedDateTime; -import java.time.format.DateTimeParseException; import java.time.zone.ZoneRulesException; import java.util.Date; @@ -55,47 +54,11 @@ void testGetDateExceptionBadZone() { assertThrows(ZoneRulesException.class, () -> TimeUtil.getDate("yyyy", "BAD")); } - @Deprecated - @Test - void testGetDateAsPath() { - assertEquals("2016-12-25/15/30", TimeUtil.getDateAsPath(testUtilDate), "GetDateAsPath"); - } - - @Deprecated - @Test - void testGetDateOrdinal() { - assertEquals("2016360", TimeUtil.getDateOrdinal(testUtilDate), "GetDateOrdinal"); - } - - @Deprecated - @Test - void testGetDateAsISO8601() { - assertEquals("2016-12-25 15:30:25", TimeUtil.getDateAsISO8601(testUtilDate), "GetDateAsISO8601"); - } - @Test void testGetDateAsISO8601Long() { assertEquals("2016-12-25 15:30:25", TimeUtil.getDateAsISO8601(testUtilDate.getTime()), "GetDateAsISO8601Long"); } - @Deprecated - @Test - void testGetDateAsFullISO8601() { - assertEquals("2016-12-25T15:30:25Z", TimeUtil.getDateAsFullISO8601(testUtilDate), "GetDateAsFullISO8601"); - } - - @Deprecated - @Test - void testGetDateFromISO8601() { - assertEquals(testUtilDate.getTime(), TimeUtil.getDateFromISO8601("2016-12-25 15:30:25").getTime(), "GetDateFromISO8601"); - } - - @Deprecated - @Test - void testGetDateFromISO8601Exception() { - assertThrows(DateTimeParseException.class, () -> TimeUtil.getDateFromISO8601("Bad Date")); - } - @Deprecated @Test void testGetZonedDateFromISO8601() { @@ -110,26 +73,11 @@ void testGetZonedDateFromISO8601() { assertEquals("GMT", zdt.getZone().getId()); } - @Deprecated - @Test - void testDatePath() { - assertTrue(TimeUtil.getDateAsPath(new Date()).contains("/"), "Date with slashes must have slashes"); - } - @Test void testOrdinal() { assertEquals(7, TimeUtil.getCurrentDateOrdinal().length(), "Date with ordinal must be 7 long"); } - @Deprecated - @Test - void testISO8601RoundTrip() { - final String s = TimeUtil.getCurrentDateISO8601(); - final Date d = TimeUtil.getDateFromISO8601(s); - final String s2 = TimeUtil.getDateAsISO8601(d.getTime()); - assertEquals(s, s2, "ISO8601 utils should make round trip"); - } - @Test void testCurrentTimeAsPath() { final String path = TimeUtil.getCurrentDate();