Skip to content

Commit

Permalink
remove deprecated timeutil methods
Browse files Browse the repository at this point in the history
  • Loading branch information
dev-mlb committed Sep 18, 2023
1 parent 0f11c9e commit 3248f88
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 139 deletions.
7 changes: 4 additions & 3 deletions src/main/java/emissary/output/DropOffUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -956,9 +958,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);
}
}
Expand Down
75 changes: 5 additions & 70 deletions src/main/java/emissary/util/TimeUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,18 @@
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;

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);
Expand Down Expand Up @@ -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)
*
Expand All @@ -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
*
Expand Down Expand Up @@ -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)
*
Expand All @@ -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')
*
Expand All @@ -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")
*
Expand Down
66 changes: 0 additions & 66 deletions src/test/java/emissary/util/TimeUtilTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 3248f88

Please sign in to comment.