From 709f0d1643162fc0177f44837a71cbfec3bc15a6 Mon Sep 17 00:00:00 2001 From: dev-mlb <19797865+dev-mlb@users.noreply.github.com> Date: Sat, 9 Sep 2023 11:05:16 -0400 Subject: [PATCH] remove deprecated timeutil methods --- .../java/emissary/output/DropOffUtil.java | 7 +- src/main/java/emissary/util/TimeUtil.java | 75 ++----------------- src/test/java/emissary/util/TimeUtilTest.java | 66 ---------------- 3 files changed, 9 insertions(+), 139 deletions(-) diff --git a/src/main/java/emissary/output/DropOffUtil.java b/src/main/java/emissary/output/DropOffUtil.java index 90f8132481..3b82531eef 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; @@ -39,6 +40,7 @@ import static emissary.core.Form.TEXT; import static emissary.core.Form.UNKNOWN; 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); @@ -882,9 +884,8 @@ 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; - } catch (DateTimeParseException ex) { + return Date.from(FlexibleDateTimeParser.parse(value, DATE_ISO_8601).toInstant()); + } catch (DateTimeParseException | NullPointerException 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..817ab9af73 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,30 +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") - * - * @param dateString the string representation of the date in the format yyyy-MM-dd HH:mm:ss - * @return ZonedDateTime parsed from the string - * @throws DateTimeParseException if string is not in the proper format - * - * @deprecated replaced by {@link FlexibleDateTimeParser#parse(String)} - */ - @Deprecated - public static ZonedDateTime getZonedDateFromISO8601(@Nullable final String dateString) throws DateTimeParseException { - return dateString == null ? null : ZonedDateTime.parse(dateString, DATE_ISO_8601); - } - /** * Parses hex date string into formatted string ("yyyy-MM-dd HH:mm:ss.SSS") * diff --git a/src/test/java/emissary/util/TimeUtilTest.java b/src/test/java/emissary/util/TimeUtilTest.java index 4eb2017e07..35bd143cc0 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,81 +54,16 @@ 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() { - ZonedDateTime zdt = TimeUtil.getZonedDateFromISO8601("2016-12-25 15:30:25"); - assertEquals(15, zdt.getHour()); - assertEquals(30, zdt.getMinute()); - assertEquals(25, zdt.getSecond()); - assertEquals(2016, zdt.getYear()); - assertEquals(12, zdt.getMonthValue()); - assertEquals(25, zdt.getDayOfMonth()); - assertEquals(360, zdt.getDayOfYear()); - 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();